Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/sync/syncable/syncable.cc

Issue 6104003: sync: use progress markers instead of timestamps during GetUpdates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #if defined(OS_POSIX) 10 #if defined(OS_POSIX)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 static const DirectoryChangeEvent kShutdownChangesEvent = 169 static const DirectoryChangeEvent kShutdownChangesEvent =
170 { DirectoryChangeEvent::SHUTDOWN, 0, 0 }; 170 { DirectoryChangeEvent::SHUTDOWN, 0, 0 };
171 171
172 void Directory::init_kernel(const std::string& name) { 172 void Directory::init_kernel(const std::string& name) {
173 DCHECK(kernel_ == NULL); 173 DCHECK(kernel_ == NULL);
174 kernel_ = new Kernel(FilePath(), name, KernelLoadInfo()); 174 kernel_ = new Kernel(FilePath(), name, KernelLoadInfo());
175 } 175 }
176 176
177 Directory::PersistedKernelInfo::PersistedKernelInfo() 177 Directory::PersistedKernelInfo::PersistedKernelInfo()
178 : next_id(0) { 178 : next_id(0) {
179 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { 179 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
180 last_download_timestamp[i] = 0; 180 reset_download_progress(ModelTypeFromInt(i));
181 } 181 }
182 autofill_migration_state = NOT_DETERMINED; 182 autofill_migration_state = NOT_DETERMINED;
183 } 183 }
184 184
185 Directory::PersistedKernelInfo::~PersistedKernelInfo() {} 185 Directory::PersistedKernelInfo::~PersistedKernelInfo() {}
186 186
187 void Directory::PersistedKernelInfo::reset_download_progress(
188 ModelType model_type) {
189 download_progress[model_type].set_data_type_id(
190 GetExtensionFieldNumberFromModelType(model_type));
191 // An empty-string token indicates no prior knowledge.
192 download_progress[model_type].set_token(std::string());
193 }
194
187 Directory::SaveChangesSnapshot::SaveChangesSnapshot() 195 Directory::SaveChangesSnapshot::SaveChangesSnapshot()
188 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { 196 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) {
189 } 197 }
190 198
191 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {} 199 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {}
192 200
193 Directory::Kernel::Kernel(const FilePath& db_path, 201 Directory::Kernel::Kernel(const FilePath& db_path,
194 const string& name, 202 const string& name,
195 const KernelLoadInfo& info) 203 const KernelLoadInfo& info)
196 : db_path(db_path), 204 : db_path(db_path),
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 delete entry; 677 delete entry;
670 } else { 678 } else {
671 ++it; 679 ++it;
672 } 680 }
673 } 681 }
674 682
675 // Ensure meta tracking for these data types reflects the deleted state. 683 // Ensure meta tracking for these data types reflects the deleted state.
676 for (std::set<ModelType>::const_iterator it = types.begin(); 684 for (std::set<ModelType>::const_iterator it = types.begin();
677 it != types.end(); ++it) { 685 it != types.end(); ++it) {
678 set_initial_sync_ended_for_type_unsafe(*it, false); 686 set_initial_sync_ended_for_type_unsafe(*it, false);
679 set_last_download_timestamp_unsafe(*it, 0); 687 kernel_->persisted_info.reset_download_progress(*it);
680 } 688 }
681 } 689 }
682 } 690 }
683 } 691 }
684 692
685 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { 693 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) {
686 ScopedKernelLock lock(this); 694 ScopedKernelLock lock(this);
687 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; 695 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
688 696
689 // Because we optimistically cleared the dirty bit on the real entries when 697 // Because we optimistically cleared the dirty bit on the real entries when
690 // taking the snapshot, we must restore it on failure. Not doing this could 698 // taking the snapshot, we must restore it on failure. Not doing this could
691 // cause lost data, if no other changes are made to the in-memory entries 699 // cause lost data, if no other changes are made to the in-memory entries
692 // that would cause the dirty bit to get set again. Setting the bit ensures 700 // that would cause the dirty bit to get set again. Setting the bit ensures
693 // that SaveChanges will at least try again later. 701 // that SaveChanges will at least try again later.
694 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin(); 702 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin();
695 i != snapshot.dirty_metas.end(); ++i) { 703 i != snapshot.dirty_metas.end(); ++i) {
696 kernel_->needle.put(META_HANDLE, i->ref(META_HANDLE)); 704 kernel_->needle.put(META_HANDLE, i->ref(META_HANDLE));
697 MetahandlesIndex::iterator found = 705 MetahandlesIndex::iterator found =
698 kernel_->metahandles_index->find(&kernel_->needle); 706 kernel_->metahandles_index->find(&kernel_->needle);
699 if (found != kernel_->metahandles_index->end()) { 707 if (found != kernel_->metahandles_index->end()) {
700 (*found)->mark_dirty(kernel_->dirty_metahandles); 708 (*found)->mark_dirty(kernel_->dirty_metahandles);
701 } 709 }
702 } 710 }
703 711
704 kernel_->metahandles_to_purge->insert(snapshot.metahandles_to_purge.begin(), 712 kernel_->metahandles_to_purge->insert(snapshot.metahandles_to_purge.begin(),
705 snapshot.metahandles_to_purge.end()); 713 snapshot.metahandles_to_purge.end());
706 } 714 }
707 715
708 int64 Directory::last_download_timestamp(ModelType model_type) const { 716 void Directory::GetDownloadProgress(
717 ModelType model_type,
718 sync_pb::DataTypeProgressMarker* value_out) const {
709 ScopedKernelLock lock(this); 719 ScopedKernelLock lock(this);
710 return kernel_->persisted_info.last_download_timestamp[model_type]; 720 return value_out->CopyFrom(
721 kernel_->persisted_info.download_progress[model_type]);
711 } 722 }
712 723
713 void Directory::set_last_download_timestamp(ModelType model_type, 724 void Directory::GetDownloadProgressAsString(
714 int64 timestamp) { 725 ModelType model_type,
726 std::string* value_out) const {
715 ScopedKernelLock lock(this); 727 ScopedKernelLock lock(this);
716 set_last_download_timestamp_unsafe(model_type, timestamp); 728 kernel_->persisted_info.download_progress[model_type].SerializeToString(
729 value_out);
730 }
731
732 void Directory::SetDownloadProgress(
733 ModelType model_type,
734 const sync_pb::DataTypeProgressMarker& new_progress) {
735 ScopedKernelLock lock(this);
736 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress);
717 } 737 }
718 738
719 bool Directory::initial_sync_ended_for_type(ModelType type) const { 739 bool Directory::initial_sync_ended_for_type(ModelType type) const {
720 ScopedKernelLock lock(this); 740 ScopedKernelLock lock(this);
721 return kernel_->persisted_info.initial_sync_ended[type]; 741 return kernel_->persisted_info.initial_sync_ended[type];
722 } 742 }
723 743
724 AutofillMigrationState Directory::get_autofill_migration_state() const { 744 AutofillMigrationState Directory::get_autofill_migration_state() const {
725 ScopedKernelLock lock(this); 745 ScopedKernelLock lock(this);
726 return kernel_->persisted_info.autofill_migration_state; 746 return kernel_->persisted_info.autofill_migration_state;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 824 }
805 825
806 void Directory::set_initial_sync_ended_for_type_unsafe(ModelType type, 826 void Directory::set_initial_sync_ended_for_type_unsafe(ModelType type,
807 bool x) { 827 bool x) {
808 if (kernel_->persisted_info.initial_sync_ended[type] == x) 828 if (kernel_->persisted_info.initial_sync_ended[type] == x)
809 return; 829 return;
810 kernel_->persisted_info.initial_sync_ended.set(type, x); 830 kernel_->persisted_info.initial_sync_ended.set(type, x);
811 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; 831 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
812 } 832 }
813 833
814 void Directory::set_last_download_timestamp_unsafe(ModelType model_type,
815 int64 timestamp) {
816 if (kernel_->persisted_info.last_download_timestamp[model_type] == timestamp)
817 return;
818 kernel_->persisted_info.last_download_timestamp[model_type] = timestamp;
819 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
820 }
821
822 void Directory::SetNotificationStateUnsafe( 834 void Directory::SetNotificationStateUnsafe(
823 const std::string& notification_state) { 835 const std::string& notification_state) {
824 if (notification_state == kernel_->persisted_info.notification_state) 836 if (notification_state == kernel_->persisted_info.notification_state)
825 return; 837 return;
826 kernel_->persisted_info.notification_state = notification_state; 838 kernel_->persisted_info.notification_state = notification_state;
827 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; 839 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
828 } 840 }
829 841
830 string Directory::store_birthday() const { 842 string Directory::store_birthday() const {
831 ScopedKernelLock lock(this); 843 ScopedKernelLock lock(this);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 } 1054 }
1043 } 1055 }
1044 } 1056 }
1045 1057
1046 browser_sync::ChannelHookup<DirectoryChangeEvent>* Directory::AddChangeObserver( 1058 browser_sync::ChannelHookup<DirectoryChangeEvent>* Directory::AddChangeObserver(
1047 browser_sync::ChannelEventHandler<DirectoryChangeEvent>* observer) { 1059 browser_sync::ChannelEventHandler<DirectoryChangeEvent>* observer) {
1048 return kernel_->changes_channel.AddObserver(observer); 1060 return kernel_->changes_channel.AddObserver(observer);
1049 } 1061 }
1050 1062
1051 /////////////////////////////////////////////////////////////////////////////// 1063 ///////////////////////////////////////////////////////////////////////////////
1052 // ScopedKernelLocks 1064 // ScopedKernelLock
1053 1065
1054 ScopedKernelLock::ScopedKernelLock(const Directory* dir) 1066 ScopedKernelLock::ScopedKernelLock(const Directory* dir)
1055 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { 1067 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) {
1056 } 1068 }
1057 1069
1058 /////////////////////////////////////////////////////////////////////////// 1070 ///////////////////////////////////////////////////////////////////////////
1059 // Transactions 1071 // Transactions
1060 1072
1061 void BaseTransaction::Lock() { 1073 void BaseTransaction::Lock() {
1062 base::TimeTicks start_time = base::TimeTicks::Now(); 1074 base::TimeTicks start_time = base::TimeTicks::Now();
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 1742
1731 FastDump& operator<<(FastDump& dump, const Blob& blob) { 1743 FastDump& operator<<(FastDump& dump, const Blob& blob) {
1732 if (blob.empty()) 1744 if (blob.empty())
1733 return dump; 1745 return dump;
1734 string buffer(base::HexEncode(&blob[0], blob.size())); 1746 string buffer(base::HexEncode(&blob[0], blob.size()));
1735 dump.out_->sputn(buffer.c_str(), buffer.size()); 1747 dump.out_->sputn(buffer.c_str(), buffer.size());
1736 return dump; 1748 return dump;
1737 } 1749 }
1738 1750
1739 } // namespace syncable 1751 } // namespace syncable
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698