diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-09 00:17:36 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-09 00:17:36 +0000 |
commit | 694ffab8fbe7a05c10d694a109fc430cfc3ba472 (patch) | |
tree | 53d66bef2148a64e0a968638f07a6047f927c0ac /sync/internal_api | |
parent | 6a9fa70e1b13a3bc5a125062cb03cf1f6ccb9239 (diff) | |
download | chromium_src-694ffab8fbe7a05c10d694a109fc430cfc3ba472.zip chromium_src-694ffab8fbe7a05c10d694a109fc430cfc3ba472.tar.gz chromium_src-694ffab8fbe7a05c10d694a109fc430cfc3ba472.tar.bz2 |
[Sync] Add support for context changes that trigger refreshes
The ContextRefreshStatus controls whether a context change should force a
refresh or not. A refresh just discards the progress marker token and marks
all synced entities for the type has having version 1. This means all entities
the server knows about are overwritten, while any locally created entities
will remain in the same state (and be pushed to the server on the next commit).
BUG=357368
Review URL: https://codereview.chromium.org/226473005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262567 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api')
-rw-r--r-- | sync/internal_api/public/write_transaction.h | 10 | ||||
-rw-r--r-- | sync/internal_api/write_transaction.cc | 36 |
2 files changed, 36 insertions, 10 deletions
diff --git a/sync/internal_api/public/write_transaction.h b/sync/internal_api/public/write_transaction.h index 8e797be..b0865ec 100644 --- a/sync/internal_api/public/write_transaction.h +++ b/sync/internal_api/public/write_transaction.h @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "sync/api/sync_change_processor.h" #include "sync/base/sync_export.h" #include "sync/internal_api/public/base_transaction.h" @@ -43,8 +44,13 @@ class SYNC_EXPORT WriteTransaction : public BaseTransaction { virtual syncable::BaseTransaction* GetWrappedTrans() const OVERRIDE; syncable::WriteTransaction* GetWrappedWriteTrans() { return transaction_; } - // Set's a |type|'s local context. Does not affect any individual entities. - void SetDataTypeContext(ModelType type, const std::string& context); + // Set's a |type|'s local context. |refresh_status| controls whether + // a datatype refresh is performed (clearing the progress marker token and + // setting the version of all synced entities to 1). + void SetDataTypeContext( + ModelType type, + syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status, + const std::string& context); protected: WriteTransaction() {} diff --git a/sync/internal_api/write_transaction.cc b/sync/internal_api/write_transaction.cc index b0ed6a2..b2dfe87 100644 --- a/sync/internal_api/write_transaction.cc +++ b/sync/internal_api/write_transaction.cc @@ -37,8 +37,12 @@ syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const { return transaction_; } -void WriteTransaction::SetDataTypeContext(ModelType type, - const std::string& context) { +void WriteTransaction::SetDataTypeContext( + ModelType type, + syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status, + const std::string& context) { + DCHECK(ProtocolTypes().Has(type)); + int field_number = GetSpecificsFieldNumberFromModelType(type); sync_pb::DataTypeContext local_context; GetDirectory()->GetDataTypeContext(transaction_, type, @@ -46,18 +50,34 @@ void WriteTransaction::SetDataTypeContext(ModelType type, if (local_context.context() == context) return; - if (!local_context.has_data_type_id()) { - local_context.set_data_type_id( - syncer::GetSpecificsFieldNumberFromModelType(type)); - } - DCHECK_EQ(syncer::GetSpecificsFieldNumberFromModelType(type), - local_context.data_type_id()); + if (!local_context.has_data_type_id()) + local_context.set_data_type_id(field_number); + + DCHECK_EQ(field_number, local_context.data_type_id()); DCHECK_GE(local_context.version(), 0); local_context.set_version(local_context.version() + 1); local_context.set_context(context); GetDirectory()->SetDataTypeContext(transaction_, type, local_context); + if (refresh_status == syncer::SyncChangeProcessor::REFRESH_NEEDED) { + DVLOG(1) << "Forcing refresh of type " << ModelTypeToString(type); + // Clear the progress token from the progress markers. Preserve all other + // state, in case a GC directive was present. + sync_pb::DataTypeProgressMarker progress_marker; + GetDirectory()->GetDownloadProgress(type, &progress_marker); + progress_marker.clear_token(); + GetDirectory()->SetDownloadProgress(type, progress_marker); + + // Go through and reset the versions for all the synced entities of this + // data type. + GetDirectory()->ResetVersionsForType(transaction_, type); + } + + // Note that it's possible for a GetUpdatesResponse that arrives immediately + // after the context update to override the cleared progress markers. + // TODO(zea): add a flag in the directory to prevent this from happening. + // See crbug.com/360280 } } // namespace syncer |