diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-11 22:09:54 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-11 22:09:54 +0000 |
commit | 82f4abc7c4c2a91ce62a56a0c0ae06af0fa51305 (patch) | |
tree | 02955f0781609f84e955b2d80486a3bafd9c58ba | |
parent | 7b83f7eadd08a3e5fdebb4aa6a2c6fabecc9cdc4 (diff) | |
download | chromium_src-82f4abc7c4c2a91ce62a56a0c0ae06af0fa51305.zip chromium_src-82f4abc7c4c2a91ce62a56a0c0ae06af0fa51305.tar.gz chromium_src-82f4abc7c4c2a91ce62a56a0c0ae06af0fa51305.tar.bz2 |
[Sync] Notify the datatype of the current context on startup
In order to support context triggered refreshes, the datatype must know
what the current context is at startup to decide whether a refresh must
be performed or not. We will now invoke UpdateDataTypeContext before
MergeDataAndStartSyncing if a valid context exists.
BUG=357368
R=rlarocque@chromium.org
Review URL: https://codereview.chromium.org/233833003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263376 0039d316-1c4b-4281-b951-d872f2087c98
11 files changed, 75 insertions, 2 deletions
diff --git a/chrome/browser/sync/glue/fake_generic_change_processor.cc b/chrome/browser/sync/glue/fake_generic_change_processor.cc index f068dc6..0e1eeb9 100644 --- a/chrome/browser/sync/glue/fake_generic_change_processor.cc +++ b/chrome/browser/sync/glue/fake_generic_change_processor.cc @@ -55,6 +55,12 @@ syncer::SyncError FakeGenericChangeProcessor::GetAllSyncDataReturnError( return get_sync_data_for_type_error_; } +bool FakeGenericChangeProcessor::GetDataTypeContext( + syncer::ModelType type, + std::string* context) const { + return false; +} + int FakeGenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { return 0; } diff --git a/chrome/browser/sync/glue/fake_generic_change_processor.h b/chrome/browser/sync/glue/fake_generic_change_processor.h index bf493dc..489af73 100644 --- a/chrome/browser/sync/glue/fake_generic_change_processor.h +++ b/chrome/browser/sync/glue/fake_generic_change_processor.h @@ -31,6 +31,8 @@ class FakeGenericChangeProcessor : public GenericChangeProcessor { virtual syncer::SyncError GetAllSyncDataReturnError( syncer::ModelType type, syncer::SyncDataList* data) const OVERRIDE; + virtual bool GetDataTypeContext(syncer::ModelType type, + std::string* context) const OVERRIDE; virtual int GetSyncCountForType(syncer::ModelType type) OVERRIDE; virtual bool SyncModelHasUserCreatedNodes(syncer::ModelType type, bool* has_nodes) OVERRIDE; diff --git a/chrome/browser/sync/glue/generic_change_processor.cc b/chrome/browser/sync/glue/generic_change_processor.cc index 0505f4f..18382aa 100644 --- a/chrome/browser/sync/glue/generic_change_processor.cc +++ b/chrome/browser/sync/glue/generic_change_processor.cc @@ -233,6 +233,21 @@ syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( return syncer::SyncError(); } +bool GenericChangeProcessor::GetDataTypeContext(syncer::ModelType type, + std::string* context) const { + syncer::ReadTransaction trans(FROM_HERE, share_handle()); + sync_pb::DataTypeContext context_proto; + trans.GetDataTypeContext(type, &context_proto); + if (!context_proto.has_context()) + return false; + + DCHECK_EQ(type, + syncer::GetModelTypeFromSpecificsFieldNumber( + context_proto.data_type_id())); + *context = context_proto.context(); + return true; +} + int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { syncer::ReadTransaction trans(FROM_HERE, share_handle()); syncer::ReadNode root(&trans); diff --git a/chrome/browser/sync/glue/generic_change_processor.h b/chrome/browser/sync/glue/generic_change_processor.h index cbed785..2af4e4e 100644 --- a/chrome/browser/sync/glue/generic_change_processor.h +++ b/chrome/browser/sync/glue/generic_change_processor.h @@ -79,6 +79,12 @@ class GenericChangeProcessor : public ChangeProcessor, syncer::ModelType type, syncer::SyncDataList* data) const; + // If a datatype context associated with |type| exists, fills |context| and + // returns true. Otheriwse, if there has not been a context set, returns + // false. + virtual bool GetDataTypeContext(syncer::ModelType type, + std::string* context) const; + // Returns the number of items for this type. virtual int GetSyncCountForType(syncer::ModelType type); diff --git a/chrome/browser/sync/glue/non_ui_data_type_controller.cc b/chrome/browser/sync/glue/non_ui_data_type_controller.cc index 83c7dd7..ba47bcf 100644 --- a/chrome/browser/sync/glue/non_ui_data_type_controller.cc +++ b/chrome/browser/sync/glue/non_ui_data_type_controller.cc @@ -379,6 +379,12 @@ void NonUIDataTypeController:: return; } + std::string datatype_context; + if (shared_change_processor_->GetDataTypeContext(&datatype_context)) { + local_service_->UpdateDataTypeContext( + type(), syncer::SyncChangeProcessor::NO_REFRESH, datatype_context); + } + syncer_merge_result.set_num_items_before_association( initial_sync_data.size()); // Passes a reference to |shared_change_processor|. diff --git a/chrome/browser/sync/glue/shared_change_processor.cc b/chrome/browser/sync/glue/shared_change_processor.cc index f3f6fd6..f4393e2 100644 --- a/chrome/browser/sync/glue/shared_change_processor.cc +++ b/chrome/browser/sync/glue/shared_change_processor.cc @@ -183,6 +183,17 @@ bool SharedChangeProcessor::CryptoReadyIfNecessary() { return generic_change_processor_->CryptoReadyIfNecessary(type_); } +bool SharedChangeProcessor::GetDataTypeContext(std::string* context) const { + DCHECK(backend_loop_.get()); + DCHECK(backend_loop_->BelongsToCurrentThread()); + AutoLock lock(monitor_lock_); + if (disconnected_) { + LOG(ERROR) << "Change processor disconnected."; + return false; + } + return generic_change_processor_->GetDataTypeContext(type_, context); +} + void SharedChangeProcessor::ActivateDataType( syncer::ModelSafeGroup model_safe_group) { DCHECK(backend_loop_.get()); diff --git a/chrome/browser/sync/glue/shared_change_processor.h b/chrome/browser/sync/glue/shared_change_processor.h index eff7dc2..1012676 100644 --- a/chrome/browser/sync/glue/shared_change_processor.h +++ b/chrome/browser/sync/glue/shared_change_processor.h @@ -94,6 +94,11 @@ class SharedChangeProcessor virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); virtual bool CryptoReadyIfNecessary(); + // If a datatype context associated with the current type exists, fills + // |context| and returns true. Otheriwse, if there has not been a context + // set, returns false. + virtual bool GetDataTypeContext(std::string* context) const; + // Register |generic_change_processor_| as the change processor for the // current type on |model_safe_group|. // Does nothing if |disconnected_| is true. diff --git a/chrome/browser/sync/glue/shared_change_processor_mock.h b/chrome/browser/sync/glue/shared_change_processor_mock.h index 0335125..21a3f5a 100644 --- a/chrome/browser/sync/glue/shared_change_processor_mock.h +++ b/chrome/browser/sync/glue/shared_change_processor_mock.h @@ -34,6 +34,7 @@ class SharedChangeProcessorMock : public SharedChangeProcessor { MOCK_METHOD1(SyncModelHasUserCreatedNodes, bool(bool*)); MOCK_METHOD0(CryptoReadyIfNecessary, bool()); + MOCK_CONST_METHOD1(GetDataTypeContext, bool(std::string*)); MOCK_METHOD1(ActivateDataType, void(syncer::ModelSafeGroup)); diff --git a/chrome/browser/sync/glue/ui_data_type_controller.cc b/chrome/browser/sync/glue/ui_data_type_controller.cc index 884c73b..bbd840a 100644 --- a/chrome/browser/sync/glue/ui_data_type_controller.cc +++ b/chrome/browser/sync/glue/ui_data_type_controller.cc @@ -182,6 +182,12 @@ void UIDataTypeController::Associate() { return; } + std::string datatype_context; + if (shared_change_processor_->GetDataTypeContext(&datatype_context)) { + local_service_->UpdateDataTypeContext( + type(), syncer::SyncChangeProcessor::NO_REFRESH, datatype_context); + } + syncer_merge_result.set_num_items_before_association( initial_sync_data.size()); // Passes a reference to |shared_change_processor_|. diff --git a/sync/internal_api/public/read_transaction.h b/sync/internal_api/public/read_transaction.h index 02e2633..3a3dc8d 100644 --- a/sync/internal_api/public/read_transaction.h +++ b/sync/internal_api/public/read_transaction.h @@ -13,6 +13,10 @@ namespace tracked_objects { class Location; } // namespace tracked_objects +namespace sync_pb { +class DataTypeContext; +} + namespace syncer { struct UserShare; @@ -35,7 +39,11 @@ class SYNC_EXPORT ReadTransaction : public BaseTransaction { // Return |transaction_version| of |type| stored in sync directory's // persisted info. - int64 GetModelVersion(ModelType type); + int64 GetModelVersion(ModelType type) const; + + // Fills |context| with the datatype context associated with |type|. + void GetDataTypeContext(ModelType type, + sync_pb::DataTypeContext* context) const; private: void* operator new(size_t size); // Transaction is meant for stack use only. diff --git a/sync/internal_api/read_transaction.cc b/sync/internal_api/read_transaction.cc index 81e5340..ebc56ec 100644 --- a/sync/internal_api/read_transaction.cc +++ b/sync/internal_api/read_transaction.cc @@ -36,8 +36,15 @@ syncable::BaseTransaction* ReadTransaction::GetWrappedTrans() const { return transaction_; } -int64 ReadTransaction::GetModelVersion(ModelType type) { +int64 ReadTransaction::GetModelVersion(ModelType type) const { return transaction_->directory()->GetTransactionVersion(type); } +void ReadTransaction::GetDataTypeContext( + ModelType type, + sync_pb::DataTypeContext* context) const { + return transaction_->directory()->GetDataTypeContext( + transaction_, type, context); +} + } // namespace syncer |