| OLD | NEW |
| 1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
| 2 // | 2 // |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are met: | 4 // modification, are permitted provided that the following conditions are met: |
| 5 // | 5 // |
| 6 // 1. Redistributions of source code must retain the above copyright notice, | 6 // 1. Redistributions of source code must retain the above copyright notice, |
| 7 // this list of conditions and the following disclaimer. | 7 // this list of conditions and the following disclaimer. |
| 8 // 2. Redistributions in binary form must reproduce the above copyright notice, | 8 // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 9 // this list of conditions and the following disclaimer in the documentation | 9 // this list of conditions and the following disclaimer in the documentation |
| 10 // and/or other materials provided with the distribution. | 10 // and/or other materials provided with the distribution. |
| 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be | 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be |
| 12 // used to endorse or promote products derived from this software without | 12 // used to endorse or promote products derived from this software without |
| 13 // specific prior written permission. | 13 // specific prior written permission. |
| 14 // | 14 // |
| 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | 25 |
| 26 #include "gears/base/common/permissions_db.h" | 26 #include "gears/base/common/permissions_db.h" |
| 27 #include "gears/base/common/sqlite_wrapper.h" | 27 #include "gears/base/common/sqlite_wrapper.h" |
| 28 #include "gears/base/common/thread_locals.h" | 28 #include "gears/base/common/thread_locals.h" |
| 29 #include "gears/localserver/common/localserver_db.h" | 29 #include "gears/localserver/common/localserver_db.h" |
| 30 | 30 |
| 31 static const char16 *kDatabaseName = STRING16(L"permissions.db"); | 31 static const char16 *kDatabaseName = STRING16(L"permissions.db"); |
| 32 static const char16 *kVersionTableName = STRING16(L"VersionInfo"); | 32 static const char16 *kVersionTableName = STRING16(L"VersionInfo"); |
| 33 static const char16 *kVersionKeyName = STRING16(L"Version"); | 33 static const char16 *kVersionKeyName = STRING16(L"Version"); |
| 34 static const char16 *kAccessTableName = STRING16(L"Access"); | 34 static const char16 *kAccessTableName = STRING16(L"Access"); |
| 35 static const int kCurrentVersion = 7; | 35 static const int kCurrentVersion = 8; |
| 36 static const int kOldestUpgradeableVersion = 1; | 36 static const int kOldestUpgradeableVersion = 1; |
| 37 | 37 |
| 38 | 38 |
| 39 const std::string PermissionsDB::kThreadLocalKey("base:permissions"); | 39 const std::string PermissionsDB::kThreadLocalKey("base:permissions"); |
| 40 | 40 |
| 41 | 41 |
| 42 PermissionsDB *PermissionsDB::GetDB() { | 42 PermissionsDB *PermissionsDB::GetDB() { |
| 43 if (ThreadLocals::HasValue(kThreadLocalKey)) { | 43 if (ThreadLocals::HasValue(kThreadLocalKey)) { |
| 44 return reinterpret_cast<PermissionsDB*>( | 44 return reinterpret_cast<PermissionsDB*>( |
| 45 ThreadLocals::GetValue(kThreadLocalKey)); | 45 ThreadLocals::GetValue(kThreadLocalKey)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 PermissionsDB *db = new PermissionsDB(); | 48 PermissionsDB *db = new PermissionsDB(); |
| 49 | 49 |
| 50 // If we can't initialize, we store NULL in the map so that we don't keep | 50 // If we can't initialize, we store NULL in the map so that we don't keep |
| 51 // trying to Init() over and over. | 51 // trying to Init() over and over. |
| 52 if (!db->Init()) { | 52 if (!db->Init()) { |
| 53 delete db; | 53 delete db; |
| 54 db = NULL; | 54 db = NULL; |
| 55 } | 55 } |
| 56 | 56 |
| 57 ThreadLocals::SetValue(kThreadLocalKey, db, &DestroyDB); | 57 ThreadLocals::SetValue(kThreadLocalKey, db, &DestroyDB); |
| 58 return db; | 58 return db; |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 void PermissionsDB::DestroyDB(void *context) { | 62 void PermissionsDB::DestroyDB(void *context) { |
| 63 PermissionsDB *db = reinterpret_cast<PermissionsDB*>(context); | 63 PermissionsDB *db = reinterpret_cast<PermissionsDB*>(context); |
| 64 if (db) { | 64 if (db) { |
| 65 delete db; | 65 delete db; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 PermissionsDB::PermissionsDB() | 70 PermissionsDB::PermissionsDB() |
| 71 : version_table_(&db_, kVersionTableName), | 71 : version_table_(&db_, kVersionTableName), |
| 72 access_table_(&db_, kAccessTableName), | 72 access_table_(&db_, kAccessTableName), |
| 73 shortcut_table_(&db_), | 73 shortcut_table_(&db_), |
| 74 database_name_table_(&db_) { | 74 database_name_table_(&db_), |
| 75 database2_metadata_table_(&db_) { |
| 75 } | 76 } |
| 76 | 77 |
| 77 | 78 |
| 78 bool PermissionsDB::Init() { | 79 bool PermissionsDB::Init() { |
| 79 // Initialize the database and tables | 80 // Initialize the database and tables |
| 80 if (!db_.Open(kDatabaseName)) { | 81 if (!db_.Open(kDatabaseName)) { |
| 81 return false; | 82 return false; |
| 82 } | 83 } |
| 83 | 84 |
| 84 // Examine the contents of the database and determine if we have to | 85 // Examine the contents of the database and determine if we have to |
| 85 // instantiate or updgrade the schema. | 86 // instantiate or updgrade the schema. |
| 86 int version = 0; | 87 int version = 0; |
| 87 version_table_.GetInt(kVersionKeyName, &version); | 88 version_table_.GetInt(kVersionKeyName, &version); |
| 88 | 89 |
| 89 // if its the version we're expecting, great | 90 // if its the version we're expecting, great |
| 90 if (version == kCurrentVersion) { | 91 if (version == kCurrentVersion) { |
| 91 return true; | 92 return true; |
| 92 } | 93 } |
| 93 | 94 |
| 94 // Doing this in a transaction effectively locks the database file and | 95 // Doing this in a transaction effectively locks the database file and |
| 95 // ensures that this is synchronized across all threads and processes | 96 // ensures that this is synchronized across all threads and processes |
| 96 SQLTransaction transaction(&db_, "PermissionsDB::Init"); | 97 SQLTransaction transaction(&db_, "PermissionsDB::Init"); |
| 97 if (!transaction.Begin()) { | 98 if (!transaction.Begin()) { |
| 98 return false; | 99 return false; |
| 99 } | 100 } |
| 100 | 101 |
| 101 // Fetch the version again in case someone else beat us to the | 102 // Fetch the version again in case someone else beat us to the |
| 102 // upgrade. | 103 // upgrade. |
| 103 version_table_.GetInt(kVersionKeyName, &version); | 104 version_table_.GetInt(kVersionKeyName, &version); |
| 104 if (version == kCurrentVersion) { | 105 if (version == kCurrentVersion) { |
| 105 return true; | 106 return true; |
| 106 } | 107 } |
| 107 | 108 |
| 108 if (0 == version) { | 109 if (0 == version) { |
| 109 // No database in place, create it. | 110 // No database in place, create it. |
| 110 // | 111 // |
| 111 // TODO(shess) Verify that this is true. Is it _no_ database, or | 112 // TODO(shess) Verify that this is true. Is it _no_ database, or |
| 112 // is there a database which didn't have a version? The latter | 113 // is there a database which didn't have a version? The latter |
| 113 // case would be masked by the CREATE IF NOT EXISTS statements | 114 // case would be masked by the CREATE IF NOT EXISTS statements |
| 114 // we're using. | 115 // we're using. |
| 115 if (!CreateDatabase()) { | 116 if (!CreateDatabase()) { |
| 116 return false; | 117 return false; |
| 117 } | 118 } |
| 118 } else { | 119 } else { |
| 119 if (!UpgradeToVersion7()) { | 120 if (!UpgradeToVersion8()) { |
| 120 return false; | 121 return false; |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 // Double-check that we ended up with the right version. | 125 // Double-check that we ended up with the right version. |
| 125 version_table_.GetInt(kVersionKeyName, &version); | 126 version_table_.GetInt(kVersionKeyName, &version); |
| 126 if (version != kCurrentVersion) { | 127 if (version != kCurrentVersion) { |
| 127 return false; | 128 return false; |
| 128 } | 129 } |
| 129 | 130 |
| 130 return transaction.Commit(); | 131 return transaction.Commit(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 | 134 |
| 134 PermissionsDB::PermissionValue PermissionsDB::GetCanAccessGears( | 135 PermissionsDB::PermissionValue PermissionsDB::GetCanAccessGears( |
| 135 const SecurityOrigin &origin) { | 136 const SecurityOrigin &origin) { |
| 136 int retval_int = PERMISSION_NOT_SET; | 137 int retval_int = PERMISSION_NOT_SET; |
| 137 access_table_.GetInt(origin.url().c_str(), &retval_int); | 138 access_table_.GetInt(origin.url().c_str(), &retval_int); |
| 138 return static_cast<PermissionsDB::PermissionValue>(retval_int); | 139 return static_cast<PermissionsDB::PermissionValue>(retval_int); |
| 139 } | 140 } |
| 140 | 141 |
| 141 | 142 |
| 142 void PermissionsDB::SetCanAccessGears(const SecurityOrigin &origin, | 143 void PermissionsDB::SetCanAccessGears(const SecurityOrigin &origin, |
| 143 PermissionsDB::PermissionValue value) { | 144 PermissionsDB::PermissionValue value) { |
| 144 if (origin.url().empty()) { | 145 if (origin.url().empty()) { |
| 145 assert(false); | 146 assert(false); |
| 146 return; | 147 return; |
| 147 } | 148 } |
| 148 | 149 |
| 149 if (value == PERMISSION_NOT_SET) { | 150 if (value == PERMISSION_NOT_SET) { |
| 150 shortcut_table_.DeleteShortcuts(origin.url().c_str()); | 151 shortcut_table_.DeleteShortcuts(origin.url().c_str()); |
| 151 access_table_.Clear(origin.url().c_str()); | 152 access_table_.Clear(origin.url().c_str()); |
| 152 } else if (value == PERMISSION_ALLOWED || value == PERMISSION_DENIED) { | 153 } else if (value == PERMISSION_ALLOWED || value == PERMISSION_DENIED) { |
| 153 access_table_.SetInt(origin.url().c_str(), value); | 154 access_table_.SetInt(origin.url().c_str(), value); |
| 154 } else { | 155 } else { |
| 155 LOG(("PermissionsDB::SetCanAccessGears invalid value: %d", value)); | 156 LOG(("PermissionsDB::SetCanAccessGears invalid value: %d", value)); |
| 156 assert(false); | 157 assert(false); |
| 157 } | 158 } |
| 158 | 159 |
| 159 if (value == PERMISSION_DENIED || value == PERMISSION_NOT_SET) { | 160 if (value == PERMISSION_DENIED || value == PERMISSION_NOT_SET) { |
| 160 WebCacheDB *webcacheDB = WebCacheDB::GetDB(); | 161 WebCacheDB *webcacheDB = WebCacheDB::GetDB(); |
| 161 if (webcacheDB) { | 162 if (webcacheDB) { |
| 162 webcacheDB->DeleteServersForOrigin(origin); | 163 webcacheDB->DeleteServersForOrigin(origin); |
| 163 } | 164 } |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 | 167 |
| 167 | 168 |
| 168 bool PermissionsDB::GetOriginsByValue(PermissionsDB::PermissionValue value, | 169 bool PermissionsDB::GetOriginsByValue(PermissionsDB::PermissionValue value, |
| 169 std::vector<SecurityOrigin> *result) { | 170 std::vector<SecurityOrigin> *result) { |
| (...skipping 91 matching lines...) Show 10 above Show 10 below |
| 261 continue; | 262 continue; |
| 262 } | 263 } |
| 263 result->push_back(origin); | 264 result->push_back(origin); |
| 264 } | 265 } |
| 265 return true; | 266 return true; |
| 266 } | 267 } |
| 267 | 268 |
| 268 bool PermissionsDB::GetOriginShortcuts(const SecurityOrigin &origin, | 269 bool PermissionsDB::GetOriginShortcuts(const SecurityOrigin &origin, |
| 269 std::vector<std::string16> *names) { | 270 std::vector<std::string16> *names) { |
| 270 return shortcut_table_.GetOriginShortcuts(origin.url().c_str(), names); | 271 return shortcut_table_.GetOriginShortcuts(origin.url().c_str(), names); |
| 271 } | 272 } |
| 272 | 273 |
| 273 bool PermissionsDB::GetShortcut(const SecurityOrigin &origin, | 274 bool PermissionsDB::GetShortcut(const SecurityOrigin &origin, |
| 274 const char16 *name, std::string16 *app_url, | 275 const char16 *name, std::string16 *app_url, |
| 275 std::string16 *icon16x16_url, | 276 std::string16 *icon16x16_url, |
| 276 std::string16 *icon32x32_url, | 277 std::string16 *icon32x32_url, |
| 277 std::string16 *icon48x48_url, | 278 std::string16 *icon48x48_url, |
| 278 std::string16 *icon128x128_url, | 279 std::string16 *icon128x128_url, |
| 279 std::string16 *msg, | 280 std::string16 *msg, |
| 280 bool *allow) { | 281 bool *allow) { |
| 281 return shortcut_table_.GetShortcut(origin.url().c_str(), name, app_url, | 282 return shortcut_table_.GetShortcut(origin.url().c_str(), name, app_url, |
| 282 icon16x16_url, icon32x32_url, | 283 icon16x16_url, icon32x32_url, |
| 283 icon48x48_url, icon128x128_url, msg, | 284 icon48x48_url, icon128x128_url, msg, |
| 284 allow); | 285 allow); |
| 285 } | 286 } |
| 286 | 287 |
| 287 bool PermissionsDB::DeleteShortcut(const SecurityOrigin &origin, | 288 bool PermissionsDB::DeleteShortcut(const SecurityOrigin &origin, |
| 288 const char16 *name) { | 289 const char16 *name) { |
| 289 return shortcut_table_.DeleteShortcut(origin.url().c_str(), name); | 290 return shortcut_table_.DeleteShortcut(origin.url().c_str(), name); |
| 290 } | 291 } |
| 291 | 292 |
| 292 bool PermissionsDB::DeleteShortcuts(const SecurityOrigin &origin) { | 293 bool PermissionsDB::DeleteShortcuts(const SecurityOrigin &origin) { |
| 293 return shortcut_table_.DeleteShortcuts(origin.url().c_str()); | 294 return shortcut_table_.DeleteShortcuts(origin.url().c_str()); |
| 294 } | 295 } |
| 295 | 296 |
| 296 // TODO(shess): Should these just be inline in the .h? | 297 // TODO(shess): Should these just be inline in the .h? |
| 297 bool PermissionsDB::GetDatabaseBasename(const SecurityOrigin &origin, | 298 bool PermissionsDB::GetDatabaseBasename(const SecurityOrigin &origin, |
| 298 const char16 *database_name, | 299 const char16 *database_name, |
| 299 std::string16 *basename) { | 300 std::string16 *basename) { |
| 300 return database_name_table_.GetDatabaseBasename(origin.url().c_str(), | 301 return database_name_table_.GetDatabaseBasename(origin.url().c_str(), |
| 301 database_name, | 302 database_name, |
| 302 basename); | 303 basename); |
| 303 } | 304 } |
| 304 | 305 |
| 305 bool PermissionsDB::MarkDatabaseCorrupt(const SecurityOrigin &origin, | 306 bool PermissionsDB::MarkDatabaseCorrupt(const SecurityOrigin &origin, |
| 306 const char16 *database_name, | 307 const char16 *database_name, |
| 307 const char16 *basename) { | 308 const char16 *basename) { |
| 308 return database_name_table_.MarkDatabaseCorrupt(origin.url().c_str(), | 309 return database_name_table_.MarkDatabaseCorrupt(origin.url().c_str(), |
| 309 database_name, | 310 database_name, |
| 310 basename); | 311 basename); |
| 312 } |
| 313 |
| 314 Database2Metadata &PermissionsDB::GetDatabase2Metadata() { |
| 315 return database2_metadata_table_; |
| 311 } | 316 } |
| 312 | 317 |
| 313 bool PermissionsDB::CreateDatabase() { | 318 bool PermissionsDB::CreateDatabase() { |
| 314 ASSERT_SINGLE_THREAD(); | 319 ASSERT_SINGLE_THREAD(); |
| 315 | 320 |
| 316 SQLTransaction transaction(&db_, "PermissionsDB::CreateDatabase"); | 321 SQLTransaction transaction(&db_, "PermissionsDB::CreateDatabase"); |
| 317 if (!transaction.Begin()) { | 322 if (!transaction.Begin()) { |
| 318 return false; | 323 return false; |
| 319 } | 324 } |
| 320 | 325 |
| 321 if (!db_.DropAllObjects()) { | 326 if (!db_.DropAllObjects()) { |
| 322 return false; | 327 return false; |
| 323 } | 328 } |
| 324 | 329 |
| 325 if (!version_table_.MaybeCreateTable() || | 330 if (!version_table_.MaybeCreateTable() || |
| 326 !access_table_.MaybeCreateTable() || | 331 !access_table_.MaybeCreateTable() || |
| 327 !shortcut_table_.MaybeCreateTableLatestVersion() || | 332 !shortcut_table_.MaybeCreateTableLatestVersion() || |
| 328 !database_name_table_.MaybeCreateTableLatestVersion()) { | 333 !database_name_table_.MaybeCreateTableLatestVersion()) { |
| 329 return false; | 334 return false; |
| 330 } | 335 } |
| 331 | 336 |
| 332 // set the current version | 337 // set the current version |
| 333 if (!version_table_.SetInt(kVersionKeyName, kCurrentVersion)) { | 338 if (!version_table_.SetInt(kVersionKeyName, kCurrentVersion)) { |
| 334 return false; | 339 return false; |
| 335 } | 340 } |
| 336 | 341 |
| 337 return transaction.Commit(); | 342 return transaction.Commit(); |
| 338 } | 343 } |
| 339 | 344 |
| 340 bool PermissionsDB::UpgradeToVersion2() { | 345 bool PermissionsDB::UpgradeToVersion2() { |
| 341 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion2"); | 346 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion2"); |
| 342 if (!transaction.Begin()) { | 347 if (!transaction.Begin()) { |
| 343 return false; | 348 return false; |
| 344 } | 349 } |
| 345 | 350 |
| 346 int version = 0; | 351 int version = 0; |
| 347 version_table_.GetInt(kVersionKeyName, &version); | 352 version_table_.GetInt(kVersionKeyName, &version); |
| 348 | 353 |
| 349 if (version != 1) { | 354 if (version != 1) { |
| 350 LOG(("PermissionsDB::UpgradeToVersion2 unexpected version: %d", version)); | 355 LOG(("PermissionsDB::UpgradeToVersion2 unexpected version: %d", version)); |
| 351 return false; | 356 return false; |
| 352 } | 357 } |
| 353 | 358 |
| 354 // There was a bug in v1 of this db where we inserted some corrupt UTF-8 | 359 // There was a bug in v1 of this db where we inserted some corrupt UTF-8 |
| 355 // characters into the db. This was pre-release, so it's not worth trying | 360 // characters into the db. This was pre-release, so it's not worth trying |
| 356 // to clean it up. Instead just remove old permissions. | 361 // to clean it up. Instead just remove old permissions. |
| 357 // | 362 // |
| 358 // TODO(shess) I'm inclined to say "DROP TABLE IF EXISTS | 363 // TODO(shess) I'm inclined to say "DROP TABLE IF EXISTS |
| 359 // ScourAccess". Or, since this was from a pre-release schema, | 364 // ScourAccess". Or, since this was from a pre-release schema, |
| 360 // "upgrade" version 1 by calling CreateDatabase(), which will drop | 365 // "upgrade" version 1 by calling CreateDatabase(), which will drop |
| (...skipping 123 matching lines...) Show 10 above Show 10 below |
| 484 | 489 |
| 485 if (version != 5) { | 490 if (version != 5) { |
| 486 LOG(("PermissionsDB::UpgradeToVersion6 unexpected version: %d", version)); | 491 LOG(("PermissionsDB::UpgradeToVersion6 unexpected version: %d", version)); |
| 487 return false; | 492 return false; |
| 488 } | 493 } |
| 489 | 494 |
| 490 if (!shortcut_table_.UpgradeFromVersion5ToVersion6()) { | 495 if (!shortcut_table_.UpgradeFromVersion5ToVersion6()) { |
| 491 return false; | 496 return false; |
| 492 } | 497 } |
| 493 | 498 |
| 494 if (!version_table_.SetInt(kVersionKeyName, 6)) { | 499 if (!version_table_.SetInt(kVersionKeyName, 6)) { |
| 495 return false; | 500 return false; |
| 496 } | 501 } |
| 497 | 502 |
| 498 return transaction.Commit(); | 503 return transaction.Commit(); |
| 499 } | 504 } |
| 500 | 505 |
| 501 bool PermissionsDB::UpgradeToVersion7() { | 506 bool PermissionsDB::UpgradeToVersion7() { |
| 502 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion7"); | 507 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion7"); |
| 503 if (!transaction.Begin()) { | 508 if (!transaction.Begin()) { |
| 504 return false; | 509 return false; |
| 505 } | 510 } |
| 506 | 511 |
| 507 int version = 0; | 512 int version = 0; |
| 508 version_table_.GetInt(kVersionKeyName, &version); | 513 version_table_.GetInt(kVersionKeyName, &version); |
| 509 | 514 |
| 510 if (version < 6) { | 515 if (version < 6) { |
| 511 if (!UpgradeToVersion6()) { | 516 if (!UpgradeToVersion6()) { |
| 512 return false; | 517 return false; |
| 513 } | 518 } |
| 514 version_table_.GetInt(kVersionKeyName, &version); | 519 version_table_.GetInt(kVersionKeyName, &version); |
| 515 } | 520 } |
| 516 | 521 |
| 517 if (version != 6) { | 522 if (version != 6) { |
| 518 LOG(("PermissionsDB::UpgradeToVersion7 unexpected version: %d", version)); | 523 LOG(("PermissionsDB::UpgradeToVersion7 unexpected version: %d", version)); |
| 519 return false; | 524 return false; |
| 520 } | 525 } |
| 521 | 526 |
| 522 // No changes to shortcut_table_. | 527 // No changes to shortcut_table_. |
| 523 | 528 |
| 524 if (!database_name_table_.UpgradeToVersion7()) { | 529 if (!database_name_table_.UpgradeToVersion7()) { |
| 525 return false; | 530 return false; |
| 526 } | 531 } |
| 527 | 532 |
| 528 if (!version_table_.SetInt(kVersionKeyName, 7)) { | 533 if (!version_table_.SetInt(kVersionKeyName, 7)) { |
| 529 return false; | 534 return false; |
| 530 } | 535 } |
| 531 | 536 |
| 532 return transaction.Commit(); | 537 return transaction.Commit(); |
| 533 } | 538 } |
| 539 |
| 540 bool PermissionsDB::UpgradeToVersion8() { |
| 541 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion8"); |
| 542 if (!transaction.Begin()) { |
| 543 return false; |
| 544 } |
| 545 |
| 546 int version = 0; |
| 547 version_table_.GetInt(kVersionKeyName, &version); |
| 548 |
| 549 if (version < 7) { |
| 550 if (!UpgradeToVersion7()) { |
| 551 return false; |
| 552 } |
| 553 version_table_.GetInt(kVersionKeyName, &version); |
| 554 } |
| 555 |
| 556 if (version != 7) { |
| 557 LOG(("PermissionsDB::UpgradeToVersion8 unexpected version: %d", version)); |
| 558 return false; |
| 559 } |
| 560 |
| 561 // Adding new database2_metadata_table_ |
| 562 if (!database2_metadata_table_.CreateTableVersion8()) { |
| 563 return false; |
| 564 } |
| 565 |
| 566 if (!version_table_.SetInt(kVersionKeyName, 8)) { |
| 567 return false; |
| 568 } |
| 569 |
| 570 return transaction.Commit(); |
| 571 } |
| OLD | NEW |