OLD | NEW |
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 COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_REGISTRY_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_REGISTRY_H_ |
6 #define COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_REGISTRY_H_ | 6 #define COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "components/sync/base/model_type.h" | 16 #include "components/sync/base/model_type.h" |
17 #include "components/sync/core/model_type_connector.h" | 17 #include "components/sync/core/model_type_connector.h" |
18 #include "components/sync/core/non_blocking_sync_common.h" | 18 #include "components/sync/core/non_blocking_sync_common.h" |
19 #include "components/sync/core/sync_encryption_handler.h" | 19 #include "components/sync/core/sync_encryption_handler.h" |
20 #include "components/sync/engine/cycle/type_debug_info_observer.h" | 20 #include "components/sync/engine/cycle/type_debug_info_observer.h" |
21 #include "components/sync/engine/model_safe_worker.h" | 21 #include "components/sync/engine/model_safe_worker.h" |
22 #include "components/sync/engine_impl/nudge_handler.h" | 22 #include "components/sync/engine_impl/nudge_handler.h" |
23 | 23 |
24 namespace syncer_v2 { | 24 namespace syncer { |
25 struct DataTypeState; | 25 struct DataTypeState; |
26 class ModelTypeProcessor; | 26 class ModelTypeProcessor; |
27 class ModelTypeWorker; | 27 class ModelTypeWorker; |
28 } | 28 } |
29 | 29 |
30 namespace syncer { | 30 namespace syncer { |
31 | 31 |
32 namespace syncable { | 32 namespace syncable { |
33 class Directory; | 33 class Directory; |
34 } // namespace syncable | 34 } // namespace syncable |
35 | 35 |
36 class CommitContributor; | 36 class CommitContributor; |
37 class DirectoryCommitContributor; | 37 class DirectoryCommitContributor; |
38 class DirectoryUpdateHandler; | 38 class DirectoryUpdateHandler; |
39 class DirectoryTypeDebugInfoEmitter; | 39 class DirectoryTypeDebugInfoEmitter; |
40 class UpdateHandler; | 40 class UpdateHandler; |
41 | 41 |
42 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; | 42 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; |
43 typedef std::map<ModelType, CommitContributor*> CommitContributorMap; | 43 typedef std::map<ModelType, CommitContributor*> CommitContributorMap; |
44 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*> | 44 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*> |
45 DirectoryTypeDebugInfoEmitterMap; | 45 DirectoryTypeDebugInfoEmitterMap; |
46 | 46 |
47 // Keeps track of the sets of active update handlers and commit contributors. | 47 // Keeps track of the sets of active update handlers and commit contributors. |
48 class ModelTypeRegistry : public syncer_v2::ModelTypeConnector, | 48 class ModelTypeRegistry : public ModelTypeConnector, |
49 public SyncEncryptionHandler::Observer { | 49 public SyncEncryptionHandler::Observer { |
50 public: | 50 public: |
51 // Constructs a ModelTypeRegistry that supports directory types. | 51 // Constructs a ModelTypeRegistry that supports directory types. |
52 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker>>& workers, | 52 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker>>& workers, |
53 syncable::Directory* directory, | 53 syncable::Directory* directory, |
54 NudgeHandler* nudge_handler); | 54 NudgeHandler* nudge_handler); |
55 ~ModelTypeRegistry() override; | 55 ~ModelTypeRegistry() override; |
56 | 56 |
57 // Sets the set of enabled types. | 57 // Sets the set of enabled types. |
58 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info); | 58 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info); |
59 | 59 |
60 // Enables an off-thread type for syncing. Connects the given proxy | 60 // Enables an off-thread type for syncing. Connects the given proxy |
61 // and its task_runner to the newly created worker. | 61 // and its task_runner to the newly created worker. |
62 // | 62 // |
63 // Expects that the proxy's ModelType is not currently enabled. | 63 // Expects that the proxy's ModelType is not currently enabled. |
64 void ConnectType(syncer::ModelType type, | 64 void ConnectType( |
65 std::unique_ptr<syncer_v2::ActivationContext> | 65 ModelType type, |
66 activation_context) override; | 66 std::unique_ptr<ActivationContext> activation_context) override; |
67 | 67 |
68 // Disables the syncing of an off-thread type. | 68 // Disables the syncing of an off-thread type. |
69 // | 69 // |
70 // Expects that the type is currently enabled. | 70 // Expects that the type is currently enabled. |
71 // Deletes the worker associated with the type. | 71 // Deletes the worker associated with the type. |
72 void DisconnectType(syncer::ModelType type) override; | 72 void DisconnectType(ModelType type) override; |
73 | 73 |
74 // Implementation of SyncEncryptionHandler::Observer. | 74 // Implementation of SyncEncryptionHandler::Observer. |
75 void OnPassphraseRequired( | 75 void OnPassphraseRequired( |
76 PassphraseRequiredReason reason, | 76 PassphraseRequiredReason reason, |
77 const sync_pb::EncryptedData& pending_keys) override; | 77 const sync_pb::EncryptedData& pending_keys) override; |
78 void OnPassphraseAccepted() override; | 78 void OnPassphraseAccepted() override; |
79 void OnBootstrapTokenUpdated(const std::string& bootstrap_token, | 79 void OnBootstrapTokenUpdated(const std::string& bootstrap_token, |
80 BootstrapTokenType type) override; | 80 BootstrapTokenType type) override; |
81 void OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | 81 void OnEncryptedTypesChanged(ModelTypeSet encrypted_types, |
82 bool encrypt_everything) override; | 82 bool encrypt_everything) override; |
83 void OnEncryptionComplete() override; | 83 void OnEncryptionComplete() override; |
84 void OnCryptographerStateChanged(Cryptographer* cryptographer) override; | 84 void OnCryptographerStateChanged(Cryptographer* cryptographer) override; |
85 void OnPassphraseTypeChanged(PassphraseType type, | 85 void OnPassphraseTypeChanged(PassphraseType type, |
86 base::Time passphrase_time) override; | 86 base::Time passphrase_time) override; |
87 void OnLocalSetPassphraseEncryption( | 87 void OnLocalSetPassphraseEncryption( |
88 const SyncEncryptionHandler::NigoriState& nigori_state) override; | 88 const SyncEncryptionHandler::NigoriState& nigori_state) override; |
89 | 89 |
90 // Gets the set of enabled types. | 90 // Gets the set of enabled types. |
91 ModelTypeSet GetEnabledTypes() const; | 91 ModelTypeSet GetEnabledTypes() const; |
92 | 92 |
93 // Returns set of types for which initial set of updates was downloaded and | 93 // Returns set of types for which initial set of updates was downloaded and |
94 // applied. | 94 // applied. |
95 ModelTypeSet GetInitialSyncEndedTypes() const; | 95 ModelTypeSet GetInitialSyncEndedTypes() const; |
96 | 96 |
97 // Simple getters. | 97 // Simple getters. |
98 UpdateHandlerMap* update_handler_map(); | 98 UpdateHandlerMap* update_handler_map(); |
99 CommitContributorMap* commit_contributor_map(); | 99 CommitContributorMap* commit_contributor_map(); |
100 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map(); | 100 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map(); |
101 | 101 |
102 void RegisterDirectoryTypeDebugInfoObserver( | 102 void RegisterDirectoryTypeDebugInfoObserver(TypeDebugInfoObserver* observer); |
103 syncer::TypeDebugInfoObserver* observer); | |
104 void UnregisterDirectoryTypeDebugInfoObserver( | 103 void UnregisterDirectoryTypeDebugInfoObserver( |
105 syncer::TypeDebugInfoObserver* observer); | 104 TypeDebugInfoObserver* observer); |
106 bool HasDirectoryTypeDebugInfoObserver( | 105 bool HasDirectoryTypeDebugInfoObserver( |
107 const syncer::TypeDebugInfoObserver* observer) const; | 106 const TypeDebugInfoObserver* observer) const; |
108 void RequestEmitDebugInfo(); | 107 void RequestEmitDebugInfo(); |
109 | 108 |
110 base::WeakPtr<ModelTypeConnector> AsWeakPtr(); | 109 base::WeakPtr<ModelTypeConnector> AsWeakPtr(); |
111 | 110 |
112 private: | 111 private: |
113 void OnEncryptionStateChanged(); | 112 void OnEncryptionStateChanged(); |
114 | 113 |
115 ModelTypeSet GetEnabledNonBlockingTypes() const; | 114 ModelTypeSet GetEnabledNonBlockingTypes() const; |
116 ModelTypeSet GetEnabledDirectoryTypes() const; | 115 ModelTypeSet GetEnabledDirectoryTypes() const; |
117 | 116 |
118 // Sets of handlers and contributors. | 117 // Sets of handlers and contributors. |
119 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_; | 118 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_; |
120 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_; | 119 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_; |
121 ScopedVector<DirectoryTypeDebugInfoEmitter> | 120 ScopedVector<DirectoryTypeDebugInfoEmitter> |
122 directory_type_debug_info_emitters_; | 121 directory_type_debug_info_emitters_; |
123 | 122 |
124 ScopedVector<syncer_v2::ModelTypeWorker> model_type_workers_; | 123 ScopedVector<ModelTypeWorker> model_type_workers_; |
125 | 124 |
126 // Maps of UpdateHandlers and CommitContributors. | 125 // Maps of UpdateHandlers and CommitContributors. |
127 // They do not own any of the objects they point to. | 126 // They do not own any of the objects they point to. |
128 UpdateHandlerMap update_handler_map_; | 127 UpdateHandlerMap update_handler_map_; |
129 CommitContributorMap commit_contributor_map_; | 128 CommitContributorMap commit_contributor_map_; |
130 | 129 |
131 // Map of DebugInfoEmitters for directory types. | 130 // Map of DebugInfoEmitters for directory types. |
132 // Non-blocking types handle debug info differently. | 131 // Non-blocking types handle debug info differently. |
133 // Does not own its contents. | 132 // Does not own its contents. |
134 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_; | 133 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_; |
(...skipping 25 matching lines...) Expand all Loading... |
160 base::ObserverList<TypeDebugInfoObserver> type_debug_info_observers_; | 159 base::ObserverList<TypeDebugInfoObserver> type_debug_info_observers_; |
161 | 160 |
162 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_; | 161 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_; |
163 | 162 |
164 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry); | 163 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry); |
165 }; | 164 }; |
166 | 165 |
167 } // namespace syncer | 166 } // namespace syncer |
168 | 167 |
169 #endif // COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_REGISTRY_H_ | 168 #endif // COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_REGISTRY_H_ |
OLD | NEW |