diff options
author | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 20:07:44 +0000 |
---|---|---|
committer | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 20:07:44 +0000 |
commit | ca66296a1952514eb42a8b4446fe4b5e7c819599 (patch) | |
tree | b5945a658c460eaf91a103233672d805af1e40e7 | |
parent | 51a22fda1748aa3c9b7c7acec655580a100b314a (diff) | |
download | chromium_src-ca66296a1952514eb42a8b4446fe4b5e7c819599.zip chromium_src-ca66296a1952514eb42a8b4446fe4b5e7c819599.tar.gz chromium_src-ca66296a1952514eb42a8b4446fe4b5e7c819599.tar.bz2 |
[SyncFS] Populate FileTracker::synced_details on its creation
Changing MetadataDatabase to populate synced_details.
Most of case, the FileDetails is available for a tracker on its creation,
and safely populated.
BUG=240165
Review URL: https://codereview.chromium.org/100713004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239022 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 38 insertions, 8 deletions
diff --git a/chrome/browser/sync_file_system/drive_backend/metadata_database.cc b/chrome/browser/sync_file_system/drive_backend/metadata_database.cc index 11d63e9..bf51bca 100644 --- a/chrome/browser/sync_file_system/drive_backend/metadata_database.cc +++ b/chrome/browser/sync_file_system/drive_backend/metadata_database.cc @@ -890,7 +890,7 @@ void MetadataDatabase::ReplaceActiveTrackerWithNewResource( FileTracker* new_tracker = *new_trackers.begin(); DCHECK(!new_tracker->active()); - DCHECK(!new_tracker->has_synced_details()); + DCHECK(new_tracker->has_synced_details()); DCHECK_EQ(parent_tracker_id, new_tracker->parent_tracker_id()); std::string title = new_file_details.title(); @@ -899,10 +899,6 @@ void MetadataDatabase::ReplaceActiveTrackerWithNewResource( trackers.has_active()) MakeTrackerInactive(trackers.active_tracker()->tracker_id(), batch.get()); - // TODO(tzik): Simplify this part. - *new_tracker->mutable_synced_details() = new_file_details; - trackers_by_parent_and_title_[parent_tracker_id][title].Insert(new_tracker); - MakeTrackerActive(new_tracker->tracker_id(), batch.get()); new_tracker->set_dirty(false); @@ -1391,6 +1387,24 @@ void MetadataDatabase::CreateTrackerForParentAndFileID( const FileTracker& parent_tracker, const std::string& file_id, leveldb::WriteBatch* batch) { + CreateTrackerInternal(parent_tracker, file_id, NULL, batch); +} + +void MetadataDatabase::CreateTrackerForParentAndFileMetadata( + const FileTracker& parent_tracker, + const FileMetadata& file_metadata, + leveldb::WriteBatch* batch) { + DCHECK(file_metadata.has_details()); + CreateTrackerInternal(parent_tracker, + file_metadata.file_id(), + &file_metadata.details(), + batch); +} + +void MetadataDatabase::CreateTrackerInternal(const FileTracker& parent_tracker, + const std::string& file_id, + const FileDetails* details, + leveldb::WriteBatch* batch) { int64 tracker_id = GetNextTrackerID(batch); scoped_ptr<FileTracker> tracker(new FileTracker); tracker->set_tracker_id(tracker_id); @@ -1401,6 +1415,11 @@ void MetadataDatabase::CreateTrackerForParentAndFileID( tracker->set_dirty(true); tracker->set_active(false); tracker->set_needs_folder_listing(false); + if (details) { + *tracker->mutable_synced_details() = *details; + tracker->mutable_synced_details()->set_missing(true); + tracker->mutable_synced_details()->clear_md5(); + } PutTrackerToBatch(*tracker, batch); trackers_by_file_id_[file_id].Insert(tracker.get()); @@ -1408,7 +1427,10 @@ void MetadataDatabase::CreateTrackerForParentAndFileID( // FileMetadata::details but from FileTracker::synced_details, which is filled // on tracker updated phase. Use empty string as the title since // FileTracker::synced_details is empty here. - trackers_by_parent_and_title_[parent_tracker.tracker_id()][std::string()] + std::string title; + if (details) + title = details->title(); + trackers_by_parent_and_title_[parent_tracker.tracker_id()][title] .Insert(tracker.get()); dirty_trackers_.insert(tracker.get()); DCHECK(!ContainsKey(tracker_by_id_, tracker_id)); @@ -1492,7 +1514,7 @@ void MetadataDatabase::MaybeAddTrackersForNewFile( if (ContainsKey(parents_to_exclude, parent_tracker_id)) continue; - CreateTrackerForParentAndFileID(*parent_tracker, file.file_id(), batch); + CreateTrackerForParentAndFileMetadata(*parent_tracker, file, batch); } } } diff --git a/chrome/browser/sync_file_system/drive_backend/metadata_database.h b/chrome/browser/sync_file_system/drive_backend/metadata_database.h index a0601d7..c535903 100644 --- a/chrome/browser/sync_file_system/drive_backend/metadata_database.h +++ b/chrome/browser/sync_file_system/drive_backend/metadata_database.h @@ -358,6 +358,13 @@ class MetadataDatabase { void CreateTrackerForParentAndFileID(const FileTracker& parent_tracker, const std::string& file_id, leveldb::WriteBatch* batch); + void CreateTrackerForParentAndFileMetadata(const FileTracker& parent_tracker, + const FileMetadata& file_metadata, + leveldb::WriteBatch* batch); + void CreateTrackerInternal(const FileTracker& parent_tracker, + const std::string& file_id, + const FileDetails* details, + leveldb::WriteBatch* batch); void RemoveTracker(int64 tracker_id, leveldb::WriteBatch* batch); void RemoveTrackerIgnoringSameTitle(int64 tracker_id, diff --git a/chrome/browser/sync_file_system/drive_backend/metadata_database_unittest.cc b/chrome/browser/sync_file_system/drive_backend/metadata_database_unittest.cc index ad2071e..2076489 100644 --- a/chrome/browser/sync_file_system/drive_backend/metadata_database_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend/metadata_database_unittest.cc @@ -884,7 +884,8 @@ TEST_F(MetadataDatabaseTest, UpdateByChangeListTest) { reorganized_file.tracker.set_dirty(true); updated_file.tracker.set_dirty(true); noop_file.tracker.set_dirty(true); - new_file.tracker.clear_synced_details(); + new_file.tracker.mutable_synced_details()->set_missing(true); + new_file.tracker.mutable_synced_details()->clear_md5(); new_file.tracker.set_active(false); new_file.tracker.set_dirty(true); ResetTrackerID(&new_file.tracker); |