Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 SyncStatusCode PopulateFolder(const std::string& folder_id, | 585 SyncStatusCode PopulateFolder(const std::string& folder_id, |
| 586 const FileIDList& listed_children) { | 586 const FileIDList& listed_children) { |
| 587 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 587 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 588 metadata_database_->PopulateFolder( | 588 metadata_database_->PopulateFolder( |
| 589 folder_id, listed_children, | 589 folder_id, listed_children, |
| 590 base::Bind(&SyncStatusResultCallback, &status)); | 590 base::Bind(&SyncStatusResultCallback, &status)); |
| 591 message_loop_.RunUntilIdle(); | 591 message_loop_.RunUntilIdle(); |
| 592 return status; | 592 return status; |
| 593 } | 593 } |
| 594 | 594 |
| 595 SyncStatusCode UpdateTracker(const FileTracker& tracker) { | |
| 596 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | |
| 597 metadata_database_->UpdateTracker( | |
| 598 tracker.tracker_id(), tracker.synced_details(), | |
| 599 base::Bind(&SyncStatusResultCallback, &status)); | |
| 600 message_loop_.RunUntilIdle(); | |
| 601 return status; | |
| 602 } | |
| 603 | |
| 595 private: | 604 private: |
| 596 base::ScopedTempDir database_dir_; | 605 base::ScopedTempDir database_dir_; |
| 597 base::MessageLoop message_loop_; | 606 base::MessageLoop message_loop_; |
| 598 | 607 |
| 599 scoped_ptr<MetadataDatabase> metadata_database_; | 608 scoped_ptr<MetadataDatabase> metadata_database_; |
| 600 | 609 |
| 601 int64 next_change_id_; | 610 int64 next_change_id_; |
| 602 int64 next_tracker_id_; | 611 int64 next_tracker_id_; |
| 603 int64 next_file_id_number_; | 612 int64 next_file_id_number_; |
| 604 int64 next_md5_sequence_number_; | 613 int64 next_md5_sequence_number_; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 file.tracker.set_active(false); | 910 file.tracker.set_active(false); |
| 902 file.should_be_absent = false; | 911 file.should_be_absent = false; |
| 903 file.tracker_only = true; | 912 file.tracker_only = true; |
| 904 | 913 |
| 905 disabled_app_root.tracker.set_dirty(false); | 914 disabled_app_root.tracker.set_dirty(false); |
| 906 disabled_app_root.tracker.set_needs_folder_listing(false); | 915 disabled_app_root.tracker.set_needs_folder_listing(false); |
| 907 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); | 916 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); |
| 908 VerifyReloadConsistency(); | 917 VerifyReloadConsistency(); |
| 909 } | 918 } |
| 910 | 919 |
| 920 TEST_F(MetadataDatabaseTest, UpdateTrackerTest) { | |
| 921 TrackedFile sync_root(CreateTrackedSyncRoot()); | |
| 922 TrackedFile app_root(CreateTrackedAppRoot(sync_root, "app_root")); | |
| 923 TrackedFile file(CreateTrackedFile(app_root, "file")); | |
| 924 file.tracker.set_dirty(true); | |
| 925 file.metadata.mutable_details()->set_title("renamed file");; | |
|
kinuko
2013/08/27 13:20:19
nit: I'm still often confused by this 'metadata' w
tzik
2013/08/30 05:51:57
Done.
I added some comment to the struct declarati
| |
| 926 | |
| 927 TrackedFile inactive_file(CreateTrackedFile(app_root, "inactive_file")); | |
| 928 inactive_file.tracker.set_active(false); | |
| 929 inactive_file.tracker.set_dirty(true); | |
| 930 inactive_file.metadata.mutable_details()->set_title("renamed inactive file"); | |
| 931 inactive_file.metadata.mutable_details()->set_md5("modified_md5"); | |
| 932 | |
| 933 TrackedFile new_conflict(CreateTrackedFile(app_root, "new conflict file")); | |
| 934 new_conflict.tracker.set_dirty(true); | |
| 935 new_conflict.metadata.mutable_details()->set_title("renamed file"); | |
| 936 | |
| 937 const TrackedFile* tracked_files[] = { | |
| 938 &sync_root, &app_root, &file, &inactive_file, &new_conflict | |
| 939 }; | |
| 940 | |
| 941 SetUpDatabaseByTrackedFiles(tracked_files, arraysize(tracked_files)); | |
| 942 EXPECT_EQ(SYNC_STATUS_OK, InitializeMetadataDatabase()); | |
| 943 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); | |
| 944 VerifyReloadConsistency(); | |
| 945 | |
| 946 *file.tracker.mutable_synced_details() = file.metadata.details(); | |
| 947 file.tracker.set_dirty(false); | |
| 948 EXPECT_EQ(SYNC_STATUS_OK, UpdateTracker(file.tracker)); | |
| 949 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); | |
| 950 VerifyReloadConsistency(); | |
| 951 | |
| 952 *inactive_file.tracker.mutable_synced_details() = | |
| 953 inactive_file.metadata.details(); | |
| 954 inactive_file.tracker.set_dirty(false); | |
| 955 inactive_file.tracker.set_active(true); | |
| 956 EXPECT_EQ(SYNC_STATUS_OK, UpdateTracker(inactive_file.tracker)); | |
| 957 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); | |
| 958 VerifyReloadConsistency(); | |
| 959 | |
| 960 *new_conflict.tracker.mutable_synced_details() = | |
| 961 new_conflict.metadata.details(); | |
| 962 new_conflict.tracker.set_dirty(false); | |
| 963 new_conflict.tracker.set_active(true); | |
| 964 file.tracker.set_dirty(true); | |
| 965 file.tracker.set_active(false); | |
| 966 EXPECT_EQ(SYNC_STATUS_OK, UpdateTracker(new_conflict.tracker)); | |
| 967 VerifyTrackedFiles(tracked_files, arraysize(tracked_files)); | |
| 968 VerifyReloadConsistency(); | |
| 969 } | |
| 970 | |
| 911 } // namespace drive_backend | 971 } // namespace drive_backend |
| 912 } // namespace sync_file_system | 972 } // namespace sync_file_system |
| OLD | NEW |