| LEFT | RIGHT |
|---|---|
| 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_versions_table_(&db_) { | 75 database2_metadata_table_(&db_) { |
| 76 } | 76 } |
| 77 | 77 |
| 78 | 78 |
| 79 bool PermissionsDB::Init() { | 79 bool PermissionsDB::Init() { |
| 80 // Initialize the database and tables | 80 // Initialize the database and tables |
| 81 if (!db_.Open(kDatabaseName)) { | 81 if (!db_.Open(kDatabaseName)) { |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // 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 |
| 86 // instantiate or updgrade the schema. | 86 // instantiate or updgrade the schema. |
| 87 int version = 0; | 87 int version = 0; |
| 88 version_table_.GetInt(kVersionKeyName, &version); | 88 version_table_.GetInt(kVersionKeyName, &version); |
| 89 | 89 |
| 90 // if its the version we're expecting, great | 90 // if its the version we're expecting, great |
| 91 if (version == kCurrentVersion) { | 91 if (version == kCurrentVersion) { |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Doing this in a transaction effectively locks the database file and | 95 // Doing this in a transaction effectively locks the database file and |
| 96 // ensures that this is synchronized across all threads and processes | 96 // ensures that this is synchronized across all threads and processes |
| 97 SQLTransaction transaction(&db_, "PermissionsDB::Init"); | 97 SQLTransaction transaction(&db_, "PermissionsDB::Init"); |
| 98 if (!transaction.Begin()) { | 98 if (!transaction.Begin()) { |
| 99 return false; | 99 return false; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // 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 |
| 103 // upgrade. | 103 // upgrade. |
| 104 version_table_.GetInt(kVersionKeyName, &version); | 104 version_table_.GetInt(kVersionKeyName, &version); |
| 105 if (version == kCurrentVersion) { | 105 if (version == kCurrentVersion) { |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (0 == version) { | 109 if (0 == version) { |
| 110 // No database in place, create it. | 110 // No database in place, create it. |
| 111 // | 111 // |
| 112 // 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 |
| 113 // 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 |
| 114 // case would be masked by the CREATE IF NOT EXISTS statements | 114 // case would be masked by the CREATE IF NOT EXISTS statements |
| 115 // we're using. | 115 // we're using. |
| 116 if (!CreateDatabase()) { | 116 if (!CreateDatabase()) { |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 } else { | 119 } else { |
| 120 if (!UpgradeToVersion7()) { | 120 if (!UpgradeToVersion8()) { |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Double-check that we ended up with the right version. | 125 // Double-check that we ended up with the right version. |
| 126 version_table_.GetInt(kVersionKeyName, &version); | 126 version_table_.GetInt(kVersionKeyName, &version); |
| 127 if (version != kCurrentVersion) { | 127 if (version != kCurrentVersion) { |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 | 130 |
| 131 return transaction.Commit(); | 131 return transaction.Commit(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 PermissionsDB::PermissionValue PermissionsDB::GetCanAccessGears( | 135 PermissionsDB::PermissionValue PermissionsDB::GetCanAccessGears( |
| 136 const SecurityOrigin &origin) { | 136 const SecurityOrigin &origin) { |
| 137 int retval_int = PERMISSION_NOT_SET; | 137 int retval_int = PERMISSION_NOT_SET; |
| 138 access_table_.GetInt(origin.url().c_str(), &retval_int); | 138 access_table_.GetInt(origin.url().c_str(), &retval_int); |
| 139 return static_cast<PermissionsDB::PermissionValue>(retval_int); | 139 return static_cast<PermissionsDB::PermissionValue>(retval_int); |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 void PermissionsDB::SetCanAccessGears(const SecurityOrigin &origin, | 143 void PermissionsDB::SetCanAccessGears(const SecurityOrigin &origin, |
| 144 PermissionsDB::PermissionValue value) { | 144 PermissionsDB::PermissionValue value) { |
| 145 if (origin.url().empty()) { | 145 if (origin.url().empty()) { |
| 146 assert(false); | 146 assert(false); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 | 149 |
| 150 if (value == PERMISSION_NOT_SET) { | 150 if (value == PERMISSION_NOT_SET) { |
| 151 shortcut_table_.DeleteShortcuts(origin.url().c_str()); | 151 shortcut_table_.DeleteShortcuts(origin.url().c_str()); |
| 152 access_table_.Clear(origin.url().c_str()); | 152 access_table_.Clear(origin.url().c_str()); |
| 153 } else if (value == PERMISSION_ALLOWED || value == PERMISSION_DENIED) { | 153 } else if (value == PERMISSION_ALLOWED || value == PERMISSION_DENIED) { |
| 154 access_table_.SetInt(origin.url().c_str(), value); | 154 access_table_.SetInt(origin.url().c_str(), value); |
| 155 } else { | 155 } else { |
| 156 LOG(("PermissionsDB::SetCanAccessGears invalid value: %d", value)); | 156 LOG(("PermissionsDB::SetCanAccessGears invalid value: %d", value)); |
| 157 assert(false); | 157 assert(false); |
| 158 } | 158 } |
| 159 | 159 |
| 160 if (value == PERMISSION_DENIED || value == PERMISSION_NOT_SET) { | 160 if (value == PERMISSION_DENIED || value == PERMISSION_NOT_SET) { |
| 161 WebCacheDB *webcacheDB = WebCacheDB::GetDB(); | 161 WebCacheDB *webcacheDB = WebCacheDB::GetDB(); |
| 162 if (webcacheDB) { | 162 if (webcacheDB) { |
| 163 webcacheDB->DeleteServersForOrigin(origin); | 163 webcacheDB->DeleteServersForOrigin(origin); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 bool PermissionsDB::GetOriginsByValue(PermissionsDB::PermissionValue value, | 169 bool PermissionsDB::GetOriginsByValue(PermissionsDB::PermissionValue value, |
| 170 std::vector<SecurityOrigin> *result) { | 170 std::vector<SecurityOrigin> *result) { |
| (...skipping 93 matching lines...) Show 10 above Show 10 below | |
| 264 result->push_back(origin); | 264 result->push_back(origin); |
| 265 } | 265 } |
| 266 return true; | 266 return true; |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool PermissionsDB::GetOriginShortcuts(const SecurityOrigin &origin, | 269 bool PermissionsDB::GetOriginShortcuts(const SecurityOrigin &origin, |
| 270 std::vector<std::string16> *names) { | 270 std::vector<std::string16> *names) { |
| 271 return shortcut_table_.GetOriginShortcuts(origin.url().c_str(), names); | 271 return shortcut_table_.GetOriginShortcuts(origin.url().c_str(), names); |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool PermissionsDB::GetShortcut(const SecurityOrigin &origin, | 274 bool PermissionsDB::GetShortcut(const SecurityOrigin &origin, |
| 275 const char16 *name, std::string16 *app_url, | 275 const char16 *name, std::string16 *app_url, |
| 276 std::string16 *icon16x16_url, | 276 std::string16 *icon16x16_url, |
| 277 std::string16 *icon32x32_url, | 277 std::string16 *icon32x32_url, |
| 278 std::string16 *icon48x48_url, | 278 std::string16 *icon48x48_url, |
| 279 std::string16 *icon128x128_url, | 279 std::string16 *icon128x128_url, |
| 280 std::string16 *msg, | 280 std::string16 *msg, |
| 281 bool *allow) { | 281 bool *allow) { |
| 282 return shortcut_table_.GetShortcut(origin.url().c_str(), name, app_url, | 282 return shortcut_table_.GetShortcut(origin.url().c_str(), name, app_url, |
| 283 icon16x16_url, icon32x32_url, | 283 icon16x16_url, icon32x32_url, |
| 284 icon48x48_url, icon128x128_url, msg, | 284 icon48x48_url, icon128x128_url, msg, |
| 285 allow); | 285 allow); |
| 286 } | 286 } |
| 287 | 287 |
| 288 bool PermissionsDB::DeleteShortcut(const SecurityOrigin &origin, | 288 bool PermissionsDB::DeleteShortcut(const SecurityOrigin &origin, |
| 289 const char16 *name) { | 289 const char16 *name) { |
| 290 return shortcut_table_.DeleteShortcut(origin.url().c_str(), name); | 290 return shortcut_table_.DeleteShortcut(origin.url().c_str(), name); |
| 291 } | 291 } |
| 292 | 292 |
| 293 bool PermissionsDB::DeleteShortcuts(const SecurityOrigin &origin) { | 293 bool PermissionsDB::DeleteShortcuts(const SecurityOrigin &origin) { |
| 294 return shortcut_table_.DeleteShortcuts(origin.url().c_str()); | 294 return shortcut_table_.DeleteShortcuts(origin.url().c_str()); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // TODO(shess): Should these just be inline in the .h? | 297 // TODO(shess): Should these just be inline in the .h? |
| 298 bool PermissionsDB::GetDatabaseBasename(const SecurityOrigin &origin, | 298 bool PermissionsDB::GetDatabaseBasename(const SecurityOrigin &origin, |
| 299 const char16 *database_name, | 299 const char16 *database_name, |
| 300 std::string16 *basename) { | 300 std::string16 *basename) { |
| 301 return database_name_table_.GetDatabaseBasename(origin.url().c_str(), | 301 return database_name_table_.GetDatabaseBasename(origin.url().c_str(), |
| 302 database_name, | 302 database_name, |
| 303 basename); | 303 basename); |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool PermissionsDB::MarkDatabaseCorrupt(const SecurityOrigin &origin, | 306 bool PermissionsDB::MarkDatabaseCorrupt(const SecurityOrigin &origin, |
| 307 const char16 *database_name, | 307 const char16 *database_name, |
| 308 const char16 *basename) { | 308 const char16 *basename) { |
| 309 return database_name_table_.MarkDatabaseCorrupt(origin.url().c_str(), | 309 return database_name_table_.MarkDatabaseCorrupt(origin.url().c_str(), |
| 310 database_name, | 310 database_name, |
| 311 basename); | 311 basename); |
| 312 } | 312 } |
| 313 | 313 |
| 314 bool PermissionsDB::GetDatabase2Version(const SecurityOrigin &origin, | 314 Database2Metadata &PermissionsDB::GetDatabase2Metadata() { |
|
Aaron
2008/05/19 15:33:50
I think we can eliminate this extra indirection by
Dimitri
2008/05/20 03:07:08
On 2008/05/19 15:33:50, Aaron wrote:
> I think we
| |
| 315 const std::string16 &name, | 315 return database2_metadata_table_; |
| 316 std::string16 *version, | |
| 317 bool *found) { | |
| 318 return database2_versions_table_.GetVersion(origin.url().c_str(), name, | |
| 319 version, found); | |
| 320 } | |
| 321 | |
| 322 bool PermissionsDB::SetDatabase2Version(const SecurityOrigin &origin, | |
| 323 const std::string16 &name, | |
| 324 const std::string16 &version) { | |
| 325 return database2_versions_table_.SetVersion(origin.url().c_str(), name, | |
| 326 version); | |
| 327 } | 316 } |
| 328 | 317 |
| 329 bool PermissionsDB::CreateDatabase() { | 318 bool PermissionsDB::CreateDatabase() { |
| 330 ASSERT_SINGLE_THREAD(); | 319 ASSERT_SINGLE_THREAD(); |
| 331 | 320 |
| 332 SQLTransaction transaction(&db_, "PermissionsDB::CreateDatabase"); | 321 SQLTransaction transaction(&db_, "PermissionsDB::CreateDatabase"); |
| 333 if (!transaction.Begin()) { | 322 if (!transaction.Begin()) { |
| 334 return false; | 323 return false; |
| 335 } | 324 } |
| 336 | 325 |
| 337 if (!db_.DropAllObjects()) { | 326 if (!db_.DropAllObjects()) { |
| 338 return false; | 327 return false; |
| 339 } | 328 } |
| 340 | 329 |
| 341 if (!version_table_.MaybeCreateTable() || | 330 if (!version_table_.MaybeCreateTable() || |
| 342 !access_table_.MaybeCreateTable() || | 331 !access_table_.MaybeCreateTable() || |
| 343 !shortcut_table_.MaybeCreateTableLatestVersion() || | 332 !shortcut_table_.MaybeCreateTableLatestVersion() || |
| 344 !database_name_table_.MaybeCreateTableLatestVersion() || | 333 !database_name_table_.MaybeCreateTableLatestVersion()) { |
| 345 !database2_versions_table_.MaybeCreateTableLatestVersion()) { | |
| 346 return false; | 334 return false; |
| 347 } | 335 } |
| 348 | 336 |
| 349 // set the current version | 337 // set the current version |
| 350 if (!version_table_.SetInt(kVersionKeyName, kCurrentVersion)) { | 338 if (!version_table_.SetInt(kVersionKeyName, kCurrentVersion)) { |
| 351 return false; | 339 return false; |
| 352 } | 340 } |
| 353 | 341 |
| 354 return transaction.Commit(); | 342 return transaction.Commit(); |
| 355 } | 343 } |
| 356 | 344 |
| 357 bool PermissionsDB::UpgradeToVersion2() { | 345 bool PermissionsDB::UpgradeToVersion2() { |
| 358 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion2"); | 346 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion2"); |
| 359 if (!transaction.Begin()) { | 347 if (!transaction.Begin()) { |
| 360 return false; | 348 return false; |
| 361 } | 349 } |
| 362 | 350 |
| 363 int version = 0; | 351 int version = 0; |
| 364 version_table_.GetInt(kVersionKeyName, &version); | 352 version_table_.GetInt(kVersionKeyName, &version); |
| 365 | 353 |
| 366 if (version != 1) { | 354 if (version != 1) { |
| 367 LOG(("PermissionsDB::UpgradeToVersion2 unexpected version: %d", version)); | 355 LOG(("PermissionsDB::UpgradeToVersion2 unexpected version: %d", version)); |
| 368 return false; | 356 return false; |
| 369 } | 357 } |
| 370 | 358 |
| 371 // 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 |
| 372 // 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 |
| 373 // to clean it up. Instead just remove old permissions. | 361 // to clean it up. Instead just remove old permissions. |
| 374 // | 362 // |
| 375 // TODO(shess) I'm inclined to say "DROP TABLE IF EXISTS | 363 // TODO(shess) I'm inclined to say "DROP TABLE IF EXISTS |
| 376 // ScourAccess". Or, since this was from a pre-release schema, | 364 // ScourAccess". Or, since this was from a pre-release schema, |
| 377 // "upgrade" version 1 by calling CreateDatabase(), which will drop | 365 // "upgrade" version 1 by calling CreateDatabase(), which will drop |
| 378 // all existing tables. | 366 // all existing tables. |
| 379 if (SQLITE_OK != db_.Execute("DELETE FROM ScourAccess")) { | 367 if (SQLITE_OK != db_.Execute("DELETE FROM ScourAccess")) { |
| 380 return false; | 368 return false; |
| 381 } | 369 } |
| 382 | 370 |
| 383 if (!version_table_.SetInt(kVersionKeyName, 2)) { | 371 if (!version_table_.SetInt(kVersionKeyName, 2)) { |
| 384 return false; | 372 return false; |
| 385 } | 373 } |
| 386 | 374 |
| 387 return transaction.Commit(); | 375 return transaction.Commit(); |
| 388 } | 376 } |
| 389 | 377 |
| 390 bool PermissionsDB::UpgradeToVersion3() { | 378 bool PermissionsDB::UpgradeToVersion3() { |
| 391 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion3"); | 379 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion3"); |
| 392 if (!transaction.Begin()) { | 380 if (!transaction.Begin()) { |
| 393 return false; | 381 return false; |
| 394 } | 382 } |
| 395 | 383 |
| (...skipping 105 matching lines...) Show 10 above Show 10 below | |
| 501 | 489 |
| 502 if (version != 5) { | 490 if (version != 5) { |
| 503 LOG(("PermissionsDB::UpgradeToVersion6 unexpected version: %d", version)); | 491 LOG(("PermissionsDB::UpgradeToVersion6 unexpected version: %d", version)); |
| 504 return false; | 492 return false; |
| 505 } | 493 } |
| 506 | 494 |
| 507 if (!shortcut_table_.UpgradeFromVersion5ToVersion6()) { | 495 if (!shortcut_table_.UpgradeFromVersion5ToVersion6()) { |
| 508 return false; | 496 return false; |
| 509 } | 497 } |
| 510 | 498 |
| 511 if (!version_table_.SetInt(kVersionKeyName, 6)) { | 499 if (!version_table_.SetInt(kVersionKeyName, 6)) { |
| 512 return false; | 500 return false; |
| 513 } | 501 } |
| 514 | 502 |
| 515 return transaction.Commit(); | 503 return transaction.Commit(); |
| 516 } | 504 } |
| 517 | 505 |
| 518 bool PermissionsDB::UpgradeToVersion7() { | 506 bool PermissionsDB::UpgradeToVersion7() { |
| 519 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion7"); | 507 SQLTransaction transaction(&db_, "PermissionsDB::UpgradeToVersion7"); |
| 520 if (!transaction.Begin()) { | 508 if (!transaction.Begin()) { |
| 521 return false; | 509 return false; |
| 522 } | 510 } |
| 523 | 511 |
| 524 int version = 0; | 512 int version = 0; |
| 525 version_table_.GetInt(kVersionKeyName, &version); | 513 version_table_.GetInt(kVersionKeyName, &version); |
| 526 | 514 |
| 527 if (version < 6) { | 515 if (version < 6) { |
| 528 if (!UpgradeToVersion6()) { | 516 if (!UpgradeToVersion6()) { |
| 529 return false; | 517 return false; |
| 530 } | 518 } |
| 531 version_table_.GetInt(kVersionKeyName, &version); | 519 version_table_.GetInt(kVersionKeyName, &version); |
| 532 } | 520 } |
| 533 | 521 |
| 534 if (version != 6) { | 522 if (version != 6) { |
| 535 LOG(("PermissionsDB::UpgradeToVersion7 unexpected version: %d", version)); | 523 LOG(("PermissionsDB::UpgradeToVersion7 unexpected version: %d", version)); |
| 536 return false; | 524 return false; |
| 537 } | 525 } |
| 538 | 526 |
| 539 // No changes to shortcut_table_. | 527 // No changes to shortcut_table_. |
| 540 | 528 |
| 541 if (!database_name_table_.UpgradeToVersion7()) { | 529 if (!database_name_table_.UpgradeToVersion7()) { |
| 542 return false; | 530 return false; |
| 543 } | 531 } |
| 544 | 532 |
| 545 if (!version_table_.SetInt(kVersionKeyName, 7)) { | 533 if (!version_table_.SetInt(kVersionKeyName, 7)) { |
| 546 return false; | 534 return false; |
| 547 } | 535 } |
| 548 | 536 |
| 549 return transaction.Commit(); | 537 return transaction.Commit(); |
| 550 } | 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 } | |
| LEFT | RIGHT |