diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-16 00:34:12 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-16 00:36:03 +0000 |
commit | 6777597b7d471a544472810b7594f9cf473415ea (patch) | |
tree | 6cf90ba020f9324f80983fcef38fefb9650bf44e /sync/sessions | |
parent | 947f48cf8ef031a2f126f7af5d1b4f4ba49b7973 (diff) | |
download | chromium_src-6777597b7d471a544472810b7594f9cf473415ea.zip chromium_src-6777597b7d471a544472810b7594f9cf473415ea.tar.gz chromium_src-6777597b7d471a544472810b7594f9cf473415ea.tar.bz2 |
sync: Finish non-blocking type encryption support
Undoes some previous work towards encryption support. That approach
suffered from some subtle deadlock issues that could not be easily
worked around. The new approach involves less sharing and less locks.
Gives the ModelTypeSyncWorker its own copy of the Cryptographer. By
passing around copies, it no longer needs to worry about acquiring locks
in order to access the Directory's cryptographer. This required
a rewrite of some changes to the way the ModelTypeSyncWorker detects the
current encryption state. Most notably, its Cryptographer is NULL if
encryption is not enabled for its model type.
Makes the ModelTypeSyncRegistry responsible for observing changes
emitted by the SyncEncryptionHandler and forwarding them to the
ModelTypeSyncWorkers. It should receive callbacks from the
SyncEncryptionHandler during startup, so it does not need to cache or
query any new data.
Removes the CryptographerProviders. Since the ModelTypeSyncWorker no
longer need to access the directory's cryptographer, it's no longer
necessary.
BUG=351005
Review URL: https://codereview.chromium.org/452283003
Cr-Commit-Position: refs/heads/master@{#290067}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290067 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/sessions')
-rw-r--r-- | sync/sessions/model_type_registry.cc | 54 | ||||
-rw-r--r-- | sync/sessions/model_type_registry.h | 33 |
2 files changed, 80 insertions, 7 deletions
diff --git a/sync/sessions/model_type_registry.cc b/sync/sessions/model_type_registry.cc index c2ba5f4..a3448464f 100644 --- a/sync/sessions/model_type_registry.cc +++ b/sync/sessions/model_type_registry.cc @@ -111,7 +111,6 @@ 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) { @@ -120,7 +119,8 @@ ModelTypeRegistry::ModelTypeRegistry( } } -ModelTypeRegistry::~ModelTypeRegistry() {} +ModelTypeRegistry::~ModelTypeRegistry() { +} void ModelTypeRegistry::SetEnabledDirectoryTypes( const ModelSafeRoutingInfo& routing_info) { @@ -198,11 +198,15 @@ void ModelTypeRegistry::ConnectSyncTypeToWorker( // Initialize Worker -> Proxy communication channel. scoped_ptr<ModelTypeSyncProxy> proxy( new ModelTypeSyncProxyWrapper(proxy_impl, type_task_runner)); + scoped_ptr<Cryptographer> cryptographer_copy; + if (encrypted_types_.Has(type)) + cryptographer_copy.reset(new Cryptographer(*cryptographer_)); + scoped_ptr<ModelTypeSyncWorkerImpl> worker( new ModelTypeSyncWorkerImpl(type, data_type_state, saved_pending_updates, - &cryptographer_provider_, + cryptographer_copy.Pass(), nudge_handler_, proxy.Pass())); @@ -299,10 +303,54 @@ base::WeakPtr<SyncContext> ModelTypeRegistry::AsWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } +void ModelTypeRegistry::OnPassphraseRequired( + PassphraseRequiredReason reason, + const sync_pb::EncryptedData& pending_keys) { +} + +void ModelTypeRegistry::OnPassphraseAccepted() { +} + +void ModelTypeRegistry::OnBootstrapTokenUpdated( + const std::string& bootstrap_token, + BootstrapTokenType type) { +} + +void ModelTypeRegistry::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, + bool encrypt_everything) { + encrypted_types_ = encrypted_types; + OnEncryptionStateChanged(); +} + +void ModelTypeRegistry::OnEncryptionComplete() { +} + +void ModelTypeRegistry::OnCryptographerStateChanged( + Cryptographer* cryptographer) { + cryptographer_.reset(new Cryptographer(*cryptographer)); + OnEncryptionStateChanged(); +} + +void ModelTypeRegistry::OnPassphraseTypeChanged(PassphraseType type, + base::Time passphrase_time) { +} + ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { return enabled_directory_types_; } +void ModelTypeRegistry::OnEncryptionStateChanged() { + for (ScopedVector<ModelTypeSyncWorkerImpl>::iterator it = + model_type_sync_workers_.begin(); + it != model_type_sync_workers_.end(); + ++it) { + if (encrypted_types_.Has((*it)->GetModelType())) { + (*it)->UpdateCryptographer( + make_scoped_ptr(new Cryptographer(*cryptographer_))); + } + } +} + ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { ModelTypeSet enabled_off_thread_types; for (ScopedVector<ModelTypeSyncWorkerImpl>::const_iterator it = diff --git a/sync/sessions/model_type_registry.h b/sync/sessions/model_type_registry.h index 2399f22..0b4a5b4 100644 --- a/sync/sessions/model_type_registry.h +++ b/sync/sessions/model_type_registry.h @@ -12,13 +12,13 @@ #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" +#include "sync/internal_api/public/sync_encryption_handler.h" namespace syncer { @@ -40,7 +40,9 @@ typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*> DirectoryTypeDebugInfoEmitterMap; // Keeps track of the sets of active update handlers and commit contributors. -class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { +class SYNC_EXPORT_PRIVATE ModelTypeRegistry + : public SyncContext, + public SyncEncryptionHandler::Observer { public: // Constructs a ModelTypeRegistry that supports directory types. ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers, @@ -68,6 +70,21 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { // Deletes the worker associated with the type. virtual void DisconnectSyncWorker(syncer::ModelType type) OVERRIDE; + // Implementation of SyncEncryptionHandler::Observer. + virtual void OnPassphraseRequired( + PassphraseRequiredReason reason, + const sync_pb::EncryptedData& pending_keys) OVERRIDE; + virtual void OnPassphraseAccepted() OVERRIDE; + virtual void OnBootstrapTokenUpdated(const std::string& bootstrap_token, + BootstrapTokenType type) OVERRIDE; + virtual void OnEncryptedTypesChanged(ModelTypeSet encrypted_types, + bool encrypt_everything) OVERRIDE; + virtual void OnEncryptionComplete() OVERRIDE; + virtual void OnCryptographerStateChanged( + Cryptographer* cryptographer) OVERRIDE; + virtual void OnPassphraseTypeChanged(PassphraseType type, + base::Time passphrase_time) OVERRIDE; + // Gets the set of enabled types. ModelTypeSet GetEnabledTypes() const; @@ -87,6 +104,8 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { base::WeakPtr<SyncContext> AsWeakPtr(); private: + void OnEncryptionStateChanged(); + ModelTypeSet GetEnabledNonBlockingTypes() const; ModelTypeSet GetEnabledDirectoryTypes() const; @@ -114,8 +133,14 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { // The directory. Not owned. syncable::Directory* directory_; - // Provides access to the Directory's cryptographer. - DirectoryCryptographerProvider cryptographer_provider_; + // A copy of the directory's most recent cryptographer. + scoped_ptr<Cryptographer> cryptographer_; + + // The set of encrypted types. + ModelTypeSet encrypted_types_; + + // A helper that manages cryptography state and preferences. + SyncEncryptionHandler* encryption_handler_; // The NudgeHandler. Not owned. NudgeHandler* nudge_handler_; |