OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <stack> | 8 #include <stack> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY) | 512 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY) |
513 MarkTrackersDirtyByPath(parent_tracker_id, title, index); | 513 MarkTrackersDirtyByPath(parent_tracker_id, title, index); |
514 | 514 |
515 if (index->GetFileTrackerIDsByFileID(file_id).empty()) { | 515 if (index->GetFileTrackerIDsByFileID(file_id).empty()) { |
516 index->RemoveFileMetadata(file_id); | 516 index->RemoveFileMetadata(file_id); |
517 } | 517 } |
518 } | 518 } |
519 | 519 |
520 } // namespace | 520 } // namespace |
521 | 521 |
522 struct MetadataDatabase::CreateParam { | |
523 base::FilePath database_path; | |
524 leveldb::Env* env_override; | |
525 | |
526 CreateParam(const base::FilePath& database_path, | |
527 leveldb::Env* env_override) | |
528 : database_path(database_path), | |
529 env_override(env_override) {} | |
530 }; | |
531 | |
532 // static | 522 // static |
533 void MetadataDatabase::Create( | 523 void MetadataDatabase::Create( |
534 const base::FilePath& database_path, | 524 const base::FilePath& database_path, |
535 leveldb::Env* env_override, | 525 leveldb::Env* env_override, |
536 const CreateCallback& callback) { | 526 const CreateCallback& callback) { |
537 CreateOnWorkerTaskRunner( | 527 bool enable_on_disk_index = !CommandLine::ForCurrentProcess()->HasSwitch( |
538 make_scoped_ptr(new CreateParam(database_path, env_override)), | 528 kDisableMetadataDatabaseOnDisk); |
539 callback); | 529 scoped_ptr<MetadataDatabase> metadata_database( |
| 530 new MetadataDatabase(database_path, |
| 531 enable_on_disk_index, |
| 532 env_override)); |
| 533 |
| 534 SyncStatusCode status = metadata_database->Initialize(); |
| 535 if (status == SYNC_DATABASE_ERROR_FAILED) { |
| 536 // Delete the previous instance to avoid creating a LevelDB instance for |
| 537 // the same path. |
| 538 metadata_database.reset(); |
| 539 |
| 540 metadata_database.reset( |
| 541 new MetadataDatabase(database_path, |
| 542 enable_on_disk_index, |
| 543 env_override)); |
| 544 status = metadata_database->Initialize(); |
| 545 } |
| 546 |
| 547 if (status != SYNC_STATUS_OK) |
| 548 metadata_database.reset(); |
| 549 |
| 550 callback.Run(status, metadata_database.Pass()); |
540 } | 551 } |
541 | 552 |
542 // static | 553 // static |
543 SyncStatusCode MetadataDatabase::CreateForTesting( | 554 SyncStatusCode MetadataDatabase::CreateForTesting( |
544 scoped_ptr<LevelDBWrapper> db, | 555 scoped_ptr<LevelDBWrapper> db, |
545 bool enable_on_disk_index, | 556 bool enable_on_disk_index, |
546 scoped_ptr<MetadataDatabase>* metadata_database_out) { | 557 scoped_ptr<MetadataDatabase>* metadata_database_out) { |
547 scoped_ptr<MetadataDatabase> metadata_database( | 558 scoped_ptr<MetadataDatabase> metadata_database( |
548 new MetadataDatabase(base::FilePath(), | 559 new MetadataDatabase(base::FilePath(), |
549 enable_on_disk_index, | 560 enable_on_disk_index, |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 const base::FilePath& database_path, | 1320 const base::FilePath& database_path, |
1310 bool enable_on_disk_index, | 1321 bool enable_on_disk_index, |
1311 leveldb::Env* env_override) | 1322 leveldb::Env* env_override) |
1312 : database_path_(database_path), | 1323 : database_path_(database_path), |
1313 env_override_(env_override), | 1324 env_override_(env_override), |
1314 enable_on_disk_index_(enable_on_disk_index), | 1325 enable_on_disk_index_(enable_on_disk_index), |
1315 largest_known_change_id_(0), | 1326 largest_known_change_id_(0), |
1316 weak_ptr_factory_(this) { | 1327 weak_ptr_factory_(this) { |
1317 } | 1328 } |
1318 | 1329 |
1319 // static | |
1320 void MetadataDatabase::CreateOnWorkerTaskRunner( | |
1321 scoped_ptr<CreateParam> create_param, | |
1322 const CreateCallback& callback) { | |
1323 bool enable_on_disk_index = !CommandLine::ForCurrentProcess()->HasSwitch( | |
1324 kDisableMetadataDatabaseOnDisk); | |
1325 scoped_ptr<MetadataDatabase> metadata_database( | |
1326 new MetadataDatabase(create_param->database_path, | |
1327 enable_on_disk_index, | |
1328 create_param->env_override)); | |
1329 | |
1330 SyncStatusCode status = metadata_database->Initialize(); | |
1331 if (status == SYNC_DATABASE_ERROR_FAILED) { | |
1332 // Delete the previous instance to avoid creating a LevelDB instance for | |
1333 // the same path. | |
1334 metadata_database.reset(); | |
1335 | |
1336 metadata_database.reset( | |
1337 new MetadataDatabase(create_param->database_path, | |
1338 enable_on_disk_index, | |
1339 create_param->env_override)); | |
1340 status = metadata_database->Initialize(); | |
1341 } | |
1342 | |
1343 if (status != SYNC_STATUS_OK) | |
1344 metadata_database.reset(); | |
1345 | |
1346 callback.Run(status, metadata_database.Pass()); | |
1347 } | |
1348 | |
1349 SyncStatusCode MetadataDatabase::Initialize() { | 1330 SyncStatusCode MetadataDatabase::Initialize() { |
1350 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 1331 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
1351 bool created = false; | 1332 bool created = false; |
1352 // Open database unless |db_| is overridden for testing. | 1333 // Open database unless |db_| is overridden for testing. |
1353 if (!db_) { | 1334 if (!db_) { |
1354 status = OpenDatabase(database_path_, env_override_, &db_, &created); | 1335 status = OpenDatabase(database_path_, env_override_, &db_, &created); |
1355 if (status != SYNC_STATUS_OK) | 1336 if (status != SYNC_STATUS_OK) |
1356 return status; | 1337 return status; |
1357 } | 1338 } |
1358 | 1339 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 return false; | 1814 return false; |
1834 | 1815 |
1835 if (!parents.empty()) | 1816 if (!parents.empty()) |
1836 return false; | 1817 return false; |
1837 | 1818 |
1838 return true; | 1819 return true; |
1839 } | 1820 } |
1840 | 1821 |
1841 } // namespace drive_backend | 1822 } // namespace drive_backend |
1842 } // namespace sync_file_system | 1823 } // namespace sync_file_system |
OLD | NEW |