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

Side by Side Diff: sync/sessions/model_type_registry.h

Issue 452283003: sync: Finish non-blocking type encryption support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ 5 #ifndef SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
6 #define SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ 6 #define SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "sync/base/sync_export.h" 14 #include "sync/base/sync_export.h"
15 #include "sync/engine/directory_cryptographer_provider.h"
16 #include "sync/engine/nudge_handler.h" 15 #include "sync/engine/nudge_handler.h"
17 #include "sync/internal_api/public/base/model_type.h" 16 #include "sync/internal_api/public/base/model_type.h"
18 #include "sync/internal_api/public/engine/model_safe_worker.h" 17 #include "sync/internal_api/public/engine/model_safe_worker.h"
19 #include "sync/internal_api/public/non_blocking_sync_common.h" 18 #include "sync/internal_api/public/non_blocking_sync_common.h"
20 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" 19 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
21 #include "sync/internal_api/public/sync_context.h" 20 #include "sync/internal_api/public/sync_context.h"
21 #include "sync/internal_api/public/sync_encryption_handler.h"
22 22
23 namespace syncer { 23 namespace syncer {
24 24
25 namespace syncable { 25 namespace syncable {
26 class Directory; 26 class Directory;
27 } // namespace syncable 27 } // namespace syncable
28 28
29 class CommitContributor; 29 class CommitContributor;
30 class DirectoryCommitContributor; 30 class DirectoryCommitContributor;
31 class DirectoryUpdateHandler; 31 class DirectoryUpdateHandler;
32 class DirectoryTypeDebugInfoEmitter; 32 class DirectoryTypeDebugInfoEmitter;
33 class ModelTypeSyncWorkerImpl; 33 class ModelTypeSyncWorkerImpl;
34 class ModelTypeSyncProxyImpl; 34 class ModelTypeSyncProxyImpl;
35 class UpdateHandler; 35 class UpdateHandler;
36 36
37 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; 37 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
38 typedef std::map<ModelType, CommitContributor*> CommitContributorMap; 38 typedef std::map<ModelType, CommitContributor*> CommitContributorMap;
39 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*> 39 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*>
40 DirectoryTypeDebugInfoEmitterMap; 40 DirectoryTypeDebugInfoEmitterMap;
41 41
42 // Keeps track of the sets of active update handlers and commit contributors. 42 // Keeps track of the sets of active update handlers and commit contributors.
43 class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { 43 class SYNC_EXPORT_PRIVATE ModelTypeRegistry
44 : public SyncContext,
45 public SyncEncryptionHandler::Observer {
44 public: 46 public:
45 // Constructs a ModelTypeRegistry that supports directory types. 47 // Constructs a ModelTypeRegistry that supports directory types.
46 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers, 48 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
47 syncable::Directory* directory, 49 syncable::Directory* directory,
48 NudgeHandler* nudge_handler); 50 NudgeHandler* nudge_handler);
49 virtual ~ModelTypeRegistry(); 51 virtual ~ModelTypeRegistry();
50 52
51 // Sets the set of enabled types. 53 // Sets the set of enabled types.
52 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info); 54 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info);
53 55
54 // Enables an off-thread type for syncing. Connects the given proxy 56 // Enables an off-thread type for syncing. Connects the given proxy
55 // and its task_runner to the newly created worker. 57 // and its task_runner to the newly created worker.
56 // 58 //
57 // Expects that the proxy's ModelType is not currently enabled. 59 // Expects that the proxy's ModelType is not currently enabled.
58 virtual void ConnectSyncTypeToWorker( 60 virtual void ConnectSyncTypeToWorker(
59 syncer::ModelType type, 61 syncer::ModelType type,
60 const DataTypeState& data_type_state, 62 const DataTypeState& data_type_state,
61 const syncer::UpdateResponseDataList& saved_pending_updates, 63 const syncer::UpdateResponseDataList& saved_pending_updates,
62 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, 64 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
63 const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE; 65 const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE;
64 66
65 // Disables the syncing of an off-thread type. 67 // Disables the syncing of an off-thread type.
66 // 68 //
67 // Expects that the type is currently enabled. 69 // Expects that the type is currently enabled.
68 // Deletes the worker associated with the type. 70 // Deletes the worker associated with the type.
69 virtual void DisconnectSyncWorker(syncer::ModelType type) OVERRIDE; 71 virtual void DisconnectSyncWorker(syncer::ModelType type) OVERRIDE;
70 72
73 // Implementation of NonBlockingEncryptionCacheObserver
74 virtual void OnPassphraseRequired(
75 PassphraseRequiredReason reason,
76 const sync_pb::EncryptedData& pending_keys) OVERRIDE;
77 virtual void OnPassphraseAccepted() OVERRIDE;
78 virtual void OnBootstrapTokenUpdated(const std::string& bootstrap_token,
79 BootstrapTokenType type) OVERRIDE;
80 virtual void OnEncryptedTypesChanged(ModelTypeSet encrypted_types,
81 bool encrypt_everything) OVERRIDE;
82 virtual void OnEncryptionComplete() OVERRIDE;
83 virtual void OnCryptographerStateChanged(
84 Cryptographer* cryptographer) OVERRIDE;
85 virtual void OnPassphraseTypeChanged(PassphraseType type,
86 base::Time passphrase_time) OVERRIDE;
87
71 // Gets the set of enabled types. 88 // Gets the set of enabled types.
72 ModelTypeSet GetEnabledTypes() const; 89 ModelTypeSet GetEnabledTypes() const;
73 90
74 // Simple getters. 91 // Simple getters.
75 UpdateHandlerMap* update_handler_map(); 92 UpdateHandlerMap* update_handler_map();
76 CommitContributorMap* commit_contributor_map(); 93 CommitContributorMap* commit_contributor_map();
77 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map(); 94 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map();
78 95
79 void RegisterDirectoryTypeDebugInfoObserver( 96 void RegisterDirectoryTypeDebugInfoObserver(
80 syncer::TypeDebugInfoObserver* observer); 97 syncer::TypeDebugInfoObserver* observer);
81 void UnregisterDirectoryTypeDebugInfoObserver( 98 void UnregisterDirectoryTypeDebugInfoObserver(
82 syncer::TypeDebugInfoObserver* observer); 99 syncer::TypeDebugInfoObserver* observer);
83 bool HasDirectoryTypeDebugInfoObserver( 100 bool HasDirectoryTypeDebugInfoObserver(
84 syncer::TypeDebugInfoObserver* observer); 101 syncer::TypeDebugInfoObserver* observer);
85 void RequestEmitDebugInfo(); 102 void RequestEmitDebugInfo();
86 103
87 base::WeakPtr<SyncContext> AsWeakPtr(); 104 base::WeakPtr<SyncContext> AsWeakPtr();
88 105
89 private: 106 private:
107 void OnEncryptionStateChanged();
108
90 ModelTypeSet GetEnabledNonBlockingTypes() const; 109 ModelTypeSet GetEnabledNonBlockingTypes() const;
91 ModelTypeSet GetEnabledDirectoryTypes() const; 110 ModelTypeSet GetEnabledDirectoryTypes() const;
92 111
93 // Sets of handlers and contributors. 112 // Sets of handlers and contributors.
94 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_; 113 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_;
95 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_; 114 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_;
96 ScopedVector<DirectoryTypeDebugInfoEmitter> 115 ScopedVector<DirectoryTypeDebugInfoEmitter>
97 directory_type_debug_info_emitters_; 116 directory_type_debug_info_emitters_;
98 117
99 ScopedVector<ModelTypeSyncWorkerImpl> model_type_sync_workers_; 118 ScopedVector<ModelTypeSyncWorkerImpl> model_type_sync_workers_;
100 119
101 // Maps of UpdateHandlers and CommitContributors. 120 // Maps of UpdateHandlers and CommitContributors.
102 // They do not own any of the objects they point to. 121 // They do not own any of the objects they point to.
103 UpdateHandlerMap update_handler_map_; 122 UpdateHandlerMap update_handler_map_;
104 CommitContributorMap commit_contributor_map_; 123 CommitContributorMap commit_contributor_map_;
105 124
106 // Map of DebugInfoEmitters for directory types. 125 // Map of DebugInfoEmitters for directory types.
107 // Non-blocking types handle debug info differently. 126 // Non-blocking types handle debug info differently.
108 // Does not own its contents. 127 // Does not own its contents.
109 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_; 128 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_;
110 129
111 // The known ModelSafeWorkers. 130 // The known ModelSafeWorkers.
112 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_; 131 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_;
113 132
114 // The directory. Not owned. 133 // The directory. Not owned.
115 syncable::Directory* directory_; 134 syncable::Directory* directory_;
116 135
117 // Provides access to the Directory's cryptographer. 136 // A copy of the directory's most recent cryptographer.
118 DirectoryCryptographerProvider cryptographer_provider_; 137 scoped_ptr<Cryptographer> cryptographer_;
138
139 // The set of encrypted types.
140 ModelTypeSet encrypted_types_;
141
142 // A helper that manages cryptography state and preferences.
143 SyncEncryptionHandler* encryption_handler_;
119 144
120 // The NudgeHandler. Not owned. 145 // The NudgeHandler. Not owned.
121 NudgeHandler* nudge_handler_; 146 NudgeHandler* nudge_handler_;
122 147
123 // The set of enabled directory types. 148 // The set of enabled directory types.
124 ModelTypeSet enabled_directory_types_; 149 ModelTypeSet enabled_directory_types_;
125 150
126 // The set of observers of per-type debug info. 151 // The set of observers of per-type debug info.
127 // 152 //
128 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's 153 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's
129 // a lot of them, and their lifetimes are unpredictable, so it makes the 154 // a lot of them, and their lifetimes are unpredictable, so it makes the
130 // book-keeping easier if we just store the list here. That way it's 155 // book-keeping easier if we just store the list here. That way it's
131 // guaranteed to live as long as this sync backend. 156 // guaranteed to live as long as this sync backend.
132 ObserverList<TypeDebugInfoObserver> type_debug_info_observers_; 157 ObserverList<TypeDebugInfoObserver> type_debug_info_observers_;
133 158
134 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_; 159 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_;
135 160
136 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry); 161 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry);
137 }; 162 };
138 163
139 } // namespace syncer 164 } // namespace syncer
140 165
141 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_ 166 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698