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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return SYNC_DATABASE_ERROR_FAILED; | 277 return SYNC_DATABASE_ERROR_FAILED; |
278 // fall-through | 278 // fall-through |
279 case 3: | 279 case 3: |
280 DCHECK_EQ(3, kCurrentDatabaseVersion); | 280 DCHECK_EQ(3, kCurrentDatabaseVersion); |
281 return SYNC_STATUS_OK; | 281 return SYNC_STATUS_OK; |
282 default: | 282 default: |
283 return SYNC_DATABASE_ERROR_FAILED; | 283 return SYNC_DATABASE_ERROR_FAILED; |
284 } | 284 } |
285 } | 285 } |
286 | 286 |
287 SyncStatusCode WriteVersionInfo(leveldb::DB* db) { | |
288 base::ThreadRestrictions::AssertIOAllowed(); | |
289 DCHECK(db); | |
290 return LevelDBStatusToSyncStatusCode( | |
291 db->Put(leveldb::WriteOptions(), | |
292 kDatabaseVersionKey, | |
293 base::Int64ToString(kCurrentDatabaseVersion))); | |
294 } | |
295 | |
296 bool HasInvalidTitle(const std::string& title) { | 287 bool HasInvalidTitle(const std::string& title) { |
297 return title.empty() || | 288 return title.empty() || |
298 title.find('/') != std::string::npos || | 289 title.find('/') != std::string::npos || |
299 title.find('\\') != std::string::npos; | 290 title.find('\\') != std::string::npos; |
300 } | 291 } |
301 | 292 |
302 void MarkTrackerSetDirty(const TrackerIDSet& trackers, | 293 void MarkTrackerSetDirty(const TrackerIDSet& trackers, |
303 MetadataDatabaseIndexInterface* index, | 294 MetadataDatabaseIndexInterface* index, |
304 leveldb::WriteBatch* batch) { | 295 leveldb::WriteBatch* batch) { |
305 for (TrackerIDSet::const_iterator itr = trackers.begin(); | 296 for (TrackerIDSet::const_iterator itr = trackers.begin(); |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 | 1463 |
1473 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 1464 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
1474 bool created = false; | 1465 bool created = false; |
1475 // Open database unless |db_| is overridden for testing. | 1466 // Open database unless |db_| is overridden for testing. |
1476 if (!db_) { | 1467 if (!db_) { |
1477 status = OpenDatabase(database_path_, env_override_, &db_, &created); | 1468 status = OpenDatabase(database_path_, env_override_, &db_, &created); |
1478 if (status != SYNC_STATUS_OK) | 1469 if (status != SYNC_STATUS_OK) |
1479 return status; | 1470 return status; |
1480 } | 1471 } |
1481 | 1472 |
1482 if (created) { | 1473 if (!created) { |
1483 status = WriteVersionInfo(db_.get()); | |
1484 if (status != SYNC_STATUS_OK) | |
1485 return status; | |
1486 } else { | |
1487 status = MigrateDatabaseIfNeeded(db_.get()); | 1474 status = MigrateDatabaseIfNeeded(db_.get()); |
1488 if (status != SYNC_STATUS_OK) | 1475 if (status != SYNC_STATUS_OK) |
1489 return status; | 1476 return status; |
1490 } | 1477 } |
1491 | 1478 |
1492 leveldb::WriteBatch batch; | 1479 leveldb::WriteBatch batch; |
1493 index_ = MetadataDatabaseIndex::Create(db_.get(), &batch); | 1480 index_ = MetadataDatabaseIndex::Create(db_.get(), &batch); |
1494 | 1481 |
1495 status = LevelDBStatusToSyncStatusCode( | 1482 status = LevelDBStatusToSyncStatusCode( |
1496 db_->Write(leveldb::WriteOptions(), &batch)); | 1483 db_->Write(leveldb::WriteOptions(), &batch)); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 index_->StoreFileMetadata(app_root_metadata.Pass(), batch); | 1966 index_->StoreFileMetadata(app_root_metadata.Pass(), batch); |
1980 index_->StoreFileTracker(app_root_tracker.Pass(), batch); | 1967 index_->StoreFileTracker(app_root_tracker.Pass(), batch); |
1981 } | 1968 } |
1982 | 1969 |
1983 void MetadataDatabase::DetachFromSequence() { | 1970 void MetadataDatabase::DetachFromSequence() { |
1984 worker_sequence_checker_.DetachFromSequence(); | 1971 worker_sequence_checker_.DetachFromSequence(); |
1985 } | 1972 } |
1986 | 1973 |
1987 } // namespace drive_backend | 1974 } // namespace drive_backend |
1988 } // namespace sync_file_system | 1975 } // namespace sync_file_system |
OLD | NEW |