diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-05 01:06:47 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-05 01:06:47 +0000 |
commit | c44d7f02e2dec6695bddff85f615e65695784b47 (patch) | |
tree | 7b11a5075ed0fea6c5754b933ccc1ba64c75e90e /sync/sessions | |
parent | 87a0a99943298d33d8eca3ab0d52abbe751d795a (diff) | |
download | chromium_src-c44d7f02e2dec6695bddff85f615e65695784b47.zip chromium_src-c44d7f02e2dec6695bddff85f615e65695784b47.tar.gz chromium_src-c44d7f02e2dec6695bddff85f615e65695784b47.tar.bz2 |
sync: Add non-blocking type encryption support
Introduces the framework for dealing with sync encryption in
non-blocking types. Unlike directory sync types, non-blocking type
encryption only encrypts data before it is sent to the server.
Encrypting the data on-disk is a separate problem.
Adds code to the ModelTypeSyncWorker so it can access the directory's
cryptographer (through a CryptographerProvider interface) and use it to
encrypt entities before it sends them to the server. If the
cryptographer is unable to encrypt with the desired key, the worker will
not commit until the cryptographer returns to a good state.
Adds the concept of a "desired encryption key" to the data type state.
When the cryptographer key to be used to encrypt a type changes, this
will be reflected in the data type state. The ModelTypeSyncProxy is
responsible for ensuring that all items which have not yet been
encrypted with this desired key are enqueued for commit.
Makes the ModelTypeSyncWorker, EntityTracker, and ModelTypeSyncProxy
collaborate on the management of undecryptable (inapplicable) updates.
The EntityTracker keeps track of their version numbers and content, and
prevents the committing of new items to the server until the
inapplicable update has been dealt with. The ModelTypeSyncProxy is
responsible for saving inapplicable updates across restarts.
This CL alone is not enough to enable encryption support for
non-blocking types. It requires additional code to hook up the
ModelTypeSyncWorkers to receive cryptographer events. This will be
added in a future commit. In the meantime, this CL includes plenty
of unit tests to verify the functionality that's being added.
BUG=351005
Review URL: https://codereview.chromium.org/423193002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/sessions')
-rw-r--r-- | sync/sessions/model_type_registry.cc | 21 | ||||
-rw-r--r-- | sync/sessions/model_type_registry.h | 7 | ||||
-rw-r--r-- | sync/sessions/model_type_registry_unittest.cc | 6 |
3 files changed, 28 insertions, 6 deletions
diff --git a/sync/sessions/model_type_registry.cc b/sync/sessions/model_type_registry.cc index 5222202..c2ba5f4 100644 --- a/sync/sessions/model_type_registry.cc +++ b/sync/sessions/model_type_registry.cc @@ -15,6 +15,7 @@ #include "sync/engine/model_type_sync_worker_impl.h" #include "sync/internal_api/public/non_blocking_sync_common.h" #include "sync/sessions/directory_type_debug_info_emitter.h" +#include "sync/util/cryptographer.h" namespace syncer { @@ -32,7 +33,8 @@ class ModelTypeSyncProxyWrapper : public ModelTypeSyncProxy { const CommitResponseDataList& response_list) OVERRIDE; virtual void OnUpdateReceived( const DataTypeState& type_state, - const UpdateResponseDataList& response_list) OVERRIDE; + const UpdateResponseDataList& response_list, + const UpdateResponseDataList& pending_updates) OVERRIDE; private: base::WeakPtr<ModelTypeSyncProxyImpl> processor_; @@ -61,13 +63,15 @@ void ModelTypeSyncProxyWrapper::OnCommitCompleted( void ModelTypeSyncProxyWrapper::OnUpdateReceived( const DataTypeState& type_state, - const UpdateResponseDataList& response_list) { + const UpdateResponseDataList& response_list, + const UpdateResponseDataList& pending_updates) { processor_task_runner_->PostTask( FROM_HERE, base::Bind(&ModelTypeSyncProxyImpl::OnUpdateReceived, processor_, type_state, - response_list)); + response_list, + pending_updates)); } class ModelTypeSyncWorkerWrapper : public ModelTypeSyncWorker { @@ -107,6 +111,7 @@ ModelTypeRegistry::ModelTypeRegistry( syncable::Directory* directory, NudgeHandler* nudge_handler) : directory_(directory), + cryptographer_provider_(directory_), nudge_handler_(nudge_handler), weak_ptr_factory_(this) { for (size_t i = 0u; i < workers.size(); ++i) { @@ -185,6 +190,7 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes( void ModelTypeRegistry::ConnectSyncTypeToWorker( ModelType type, const DataTypeState& data_type_state, + const UpdateResponseDataList& saved_pending_updates, const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy_impl) { DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); @@ -192,8 +198,13 @@ void ModelTypeRegistry::ConnectSyncTypeToWorker( // Initialize Worker -> Proxy communication channel. scoped_ptr<ModelTypeSyncProxy> proxy( new ModelTypeSyncProxyWrapper(proxy_impl, type_task_runner)); - scoped_ptr<ModelTypeSyncWorkerImpl> worker(new ModelTypeSyncWorkerImpl( - type, data_type_state, nudge_handler_, proxy.Pass())); + scoped_ptr<ModelTypeSyncWorkerImpl> worker( + new ModelTypeSyncWorkerImpl(type, + data_type_state, + saved_pending_updates, + &cryptographer_provider_, + nudge_handler_, + proxy.Pass())); // Initialize Proxy -> Worker communication channel. scoped_ptr<ModelTypeSyncWorker> wrapped_worker( diff --git a/sync/sessions/model_type_registry.h b/sync/sessions/model_type_registry.h index e18ac9c..2399f22 100644 --- a/sync/sessions/model_type_registry.h +++ b/sync/sessions/model_type_registry.h @@ -12,9 +12,11 @@ #include "base/memory/scoped_vector.h" #include "base/memory/weak_ptr.h" #include "sync/base/sync_export.h" +#include "sync/engine/directory_cryptographer_provider.h" #include "sync/engine/nudge_handler.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/non_blocking_sync_common.h" #include "sync/internal_api/public/sessions/type_debug_info_observer.h" #include "sync/internal_api/public/sync_context.h" @@ -31,7 +33,6 @@ class DirectoryTypeDebugInfoEmitter; class ModelTypeSyncWorkerImpl; class ModelTypeSyncProxyImpl; class UpdateHandler; -struct DataTypeState; typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; typedef std::map<ModelType, CommitContributor*> CommitContributorMap; @@ -57,6 +58,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { virtual void ConnectSyncTypeToWorker( syncer::ModelType type, const DataTypeState& data_type_state, + const syncer::UpdateResponseDataList& saved_pending_updates, const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE; @@ -112,6 +114,9 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { // The directory. Not owned. syncable::Directory* directory_; + // Provides access to the Directory's cryptographer. + DirectoryCryptographerProvider cryptographer_provider_; + // The NudgeHandler. Not owned. NudgeHandler* nudge_handler_; diff --git a/sync/sessions/model_type_registry_unittest.cc b/sync/sessions/model_type_registry_unittest.cc index b1f1a49..96d6294 100644 --- a/sync/sessions/model_type_registry_unittest.cc +++ b/sync/sessions/model_type_registry_unittest.cc @@ -154,6 +154,7 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { registry()->ConnectSyncTypeToWorker(syncer::THEMES, MakeInitialDataTypeState(THEMES), + UpdateResponseDataList(), task_runner, themes_sync_proxy.AsWeakPtrForUI()); EXPECT_TRUE(registry()->GetEnabledTypes().Equals( @@ -161,6 +162,7 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { registry()->ConnectSyncTypeToWorker(syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS), + UpdateResponseDataList(), task_runner, sessions_sync_proxy.AsWeakPtrForUI()); EXPECT_TRUE(registry()->GetEnabledTypes().Equals( @@ -192,6 +194,7 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { // Add the themes non-blocking type. registry()->ConnectSyncTypeToWorker(syncer::THEMES, MakeInitialDataTypeState(THEMES), + UpdateResponseDataList(), task_runner, themes_sync_proxy.AsWeakPtrForUI()); current_types.Put(syncer::THEMES); @@ -205,6 +208,7 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { // Add sessions non-blocking type. registry()->ConnectSyncTypeToWorker(syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS), + UpdateResponseDataList(), task_runner, sessions_sync_proxy.AsWeakPtrForUI()); current_types.Put(syncer::SESSIONS); @@ -235,10 +239,12 @@ TEST_F(ModelTypeRegistryTest, DeletionOrdering) { registry()->ConnectSyncTypeToWorker(syncer::THEMES, MakeInitialDataTypeState(THEMES), + UpdateResponseDataList(), task_runner, themes_sync_proxy->AsWeakPtrForUI()); registry()->ConnectSyncTypeToWorker(syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS), + UpdateResponseDataList(), task_runner, sessions_sync_proxy->AsWeakPtrForUI()); EXPECT_TRUE(registry()->GetEnabledTypes().Equals( |