Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / sync / sessions / model_type_registry.h
blob9e097cfb988a6e5c7424772d078d93d474318813
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
3 // found in the LICENSE file.
5 #ifndef SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
6 #define SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
14 #include "sync/base/sync_export.h"
15 #include "sync/engine/nudge_handler.h"
16 #include "sync/internal_api/public/base/model_type.h"
17 #include "sync/internal_api/public/engine/model_safe_worker.h"
18 #include "sync/internal_api/public/non_blocking_sync_common.h"
19 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
20 #include "sync/internal_api/public/sync_context.h"
21 #include "sync/internal_api/public/sync_encryption_handler.h"
23 namespace syncer_v2 {
24 struct DataTypeState;
25 class ModelTypeProcessor;
26 class ModelTypeWorker;
29 namespace syncer {
31 namespace syncable {
32 class Directory;
33 } // namespace syncable
35 class CommitContributor;
36 class DirectoryCommitContributor;
37 class DirectoryUpdateHandler;
38 class DirectoryTypeDebugInfoEmitter;
39 class UpdateHandler;
41 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
42 typedef std::map<ModelType, CommitContributor*> CommitContributorMap;
43 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*>
44 DirectoryTypeDebugInfoEmitterMap;
46 // Keeps track of the sets of active update handlers and commit contributors.
47 class SYNC_EXPORT_PRIVATE ModelTypeRegistry
48 : public syncer_v2::SyncContext,
49 public SyncEncryptionHandler::Observer {
50 public:
51 // Constructs a ModelTypeRegistry that supports directory types.
52 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
53 syncable::Directory* directory,
54 NudgeHandler* nudge_handler);
55 ~ModelTypeRegistry() override;
57 // Sets the set of enabled types.
58 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info);
60 // Enables an off-thread type for syncing. Connects the given proxy
61 // and its task_runner to the newly created worker.
63 // Expects that the proxy's ModelType is not currently enabled.
64 void ConnectSyncTypeToWorker(
65 syncer::ModelType type,
66 const syncer_v2::DataTypeState& data_type_state,
67 const syncer_v2::UpdateResponseDataList& saved_pending_updates,
68 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
69 const base::WeakPtr<syncer_v2::ModelTypeProcessor>& type_processor)
70 override;
72 // Disables the syncing of an off-thread type.
74 // Expects that the type is currently enabled.
75 // Deletes the worker associated with the type.
76 void DisconnectSyncWorker(syncer::ModelType type) override;
78 // Implementation of SyncEncryptionHandler::Observer.
79 void OnPassphraseRequired(
80 PassphraseRequiredReason reason,
81 const sync_pb::EncryptedData& pending_keys) override;
82 void OnPassphraseAccepted() override;
83 void OnBootstrapTokenUpdated(const std::string& bootstrap_token,
84 BootstrapTokenType type) override;
85 void OnEncryptedTypesChanged(ModelTypeSet encrypted_types,
86 bool encrypt_everything) override;
87 void OnEncryptionComplete() override;
88 void OnCryptographerStateChanged(Cryptographer* cryptographer) override;
89 void OnPassphraseTypeChanged(PassphraseType type,
90 base::Time passphrase_time) override;
91 void OnLocalSetPassphraseEncryption(
92 const SyncEncryptionHandler::NigoriState& nigori_state) override;
94 // Gets the set of enabled types.
95 ModelTypeSet GetEnabledTypes() const;
97 // Simple getters.
98 UpdateHandlerMap* update_handler_map();
99 CommitContributorMap* commit_contributor_map();
100 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map();
102 void RegisterDirectoryTypeDebugInfoObserver(
103 syncer::TypeDebugInfoObserver* observer);
104 void UnregisterDirectoryTypeDebugInfoObserver(
105 syncer::TypeDebugInfoObserver* observer);
106 bool HasDirectoryTypeDebugInfoObserver(
107 const syncer::TypeDebugInfoObserver* observer) const;
108 void RequestEmitDebugInfo();
110 base::WeakPtr<SyncContext> AsWeakPtr();
112 private:
113 void OnEncryptionStateChanged();
115 ModelTypeSet GetEnabledNonBlockingTypes() const;
116 ModelTypeSet GetEnabledDirectoryTypes() const;
118 // Sets of handlers and contributors.
119 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_;
120 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_;
121 ScopedVector<DirectoryTypeDebugInfoEmitter>
122 directory_type_debug_info_emitters_;
124 ScopedVector<syncer_v2::ModelTypeWorker> model_type_workers_;
126 // Maps of UpdateHandlers and CommitContributors.
127 // They do not own any of the objects they point to.
128 UpdateHandlerMap update_handler_map_;
129 CommitContributorMap commit_contributor_map_;
131 // Map of DebugInfoEmitters for directory types.
132 // Non-blocking types handle debug info differently.
133 // Does not own its contents.
134 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_;
136 // The known ModelSafeWorkers.
137 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_;
139 // The directory. Not owned.
140 syncable::Directory* directory_;
142 // A copy of the directory's most recent cryptographer.
143 scoped_ptr<Cryptographer> cryptographer_;
145 // The set of encrypted types.
146 ModelTypeSet encrypted_types_;
148 // The NudgeHandler. Not owned.
149 NudgeHandler* nudge_handler_;
151 // The set of enabled directory types.
152 ModelTypeSet enabled_directory_types_;
154 // The set of observers of per-type debug info.
156 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's
157 // a lot of them, and their lifetimes are unpredictable, so it makes the
158 // book-keeping easier if we just store the list here. That way it's
159 // guaranteed to live as long as this sync backend.
160 base::ObserverList<TypeDebugInfoObserver> type_debug_info_observers_;
162 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_;
164 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry);
167 } // namespace syncer
169 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_