Remove errant '>' in gyp file.
[chromium-blink-merge.git] / sync / sessions / model_type_registry.h
blob53c0d99bbe4252f91e3061cefd8ecd1d533c324d
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 {
25 namespace syncable {
26 class Directory;
27 } // namespace syncable
29 class CommitContributor;
30 class DirectoryCommitContributor;
31 class DirectoryUpdateHandler;
32 class DirectoryTypeDebugInfoEmitter;
33 class ModelTypeSyncWorkerImpl;
34 class ModelTypeSyncProxyImpl;
35 class UpdateHandler;
37 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
38 typedef std::map<ModelType, CommitContributor*> CommitContributorMap;
39 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*>
40 DirectoryTypeDebugInfoEmitterMap;
42 // Keeps track of the sets of active update handlers and commit contributors.
43 class SYNC_EXPORT_PRIVATE ModelTypeRegistry
44 : public SyncContext,
45 public SyncEncryptionHandler::Observer {
46 public:
47 // Constructs a ModelTypeRegistry that supports directory types.
48 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
49 syncable::Directory* directory,
50 NudgeHandler* nudge_handler);
51 ~ModelTypeRegistry() override;
53 // Sets the set of enabled types.
54 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info);
56 // Enables an off-thread type for syncing. Connects the given proxy
57 // and its task_runner to the newly created worker.
59 // Expects that the proxy's ModelType is not currently enabled.
60 void ConnectSyncTypeToWorker(
61 syncer::ModelType type,
62 const DataTypeState& data_type_state,
63 const syncer::UpdateResponseDataList& saved_pending_updates,
64 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
65 const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) override;
67 // Disables the syncing of an off-thread type.
69 // Expects that the type is currently enabled.
70 // Deletes the worker associated with the type.
71 void DisconnectSyncWorker(syncer::ModelType type) override;
73 // Implementation of SyncEncryptionHandler::Observer.
74 void OnPassphraseRequired(
75 PassphraseRequiredReason reason,
76 const sync_pb::EncryptedData& pending_keys) override;
77 void OnPassphraseAccepted() override;
78 void OnBootstrapTokenUpdated(const std::string& bootstrap_token,
79 BootstrapTokenType type) override;
80 void OnEncryptedTypesChanged(ModelTypeSet encrypted_types,
81 bool encrypt_everything) override;
82 void OnEncryptionComplete() override;
83 void OnCryptographerStateChanged(Cryptographer* cryptographer) override;
84 void OnPassphraseTypeChanged(PassphraseType type,
85 base::Time passphrase_time) override;
86 void OnLocalSetPassphraseEncryption(
87 const SyncEncryptionHandler::NigoriState& nigori_state) override;
89 // Gets the set of enabled types.
90 ModelTypeSet GetEnabledTypes() const;
92 // Simple getters.
93 UpdateHandlerMap* update_handler_map();
94 CommitContributorMap* commit_contributor_map();
95 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map();
97 void RegisterDirectoryTypeDebugInfoObserver(
98 syncer::TypeDebugInfoObserver* observer);
99 void UnregisterDirectoryTypeDebugInfoObserver(
100 syncer::TypeDebugInfoObserver* observer);
101 bool HasDirectoryTypeDebugInfoObserver(
102 const syncer::TypeDebugInfoObserver* observer) const;
103 void RequestEmitDebugInfo();
105 base::WeakPtr<SyncContext> AsWeakPtr();
107 private:
108 void OnEncryptionStateChanged();
110 ModelTypeSet GetEnabledNonBlockingTypes() const;
111 ModelTypeSet GetEnabledDirectoryTypes() const;
113 // Sets of handlers and contributors.
114 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_;
115 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_;
116 ScopedVector<DirectoryTypeDebugInfoEmitter>
117 directory_type_debug_info_emitters_;
119 ScopedVector<ModelTypeSyncWorkerImpl> model_type_sync_workers_;
121 // Maps of UpdateHandlers and CommitContributors.
122 // They do not own any of the objects they point to.
123 UpdateHandlerMap update_handler_map_;
124 CommitContributorMap commit_contributor_map_;
126 // Map of DebugInfoEmitters for directory types.
127 // Non-blocking types handle debug info differently.
128 // Does not own its contents.
129 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_;
131 // The known ModelSafeWorkers.
132 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_;
134 // The directory. Not owned.
135 syncable::Directory* directory_;
137 // A copy of the directory's most recent cryptographer.
138 scoped_ptr<Cryptographer> cryptographer_;
140 // The set of encrypted types.
141 ModelTypeSet encrypted_types_;
143 // The NudgeHandler. Not owned.
144 NudgeHandler* nudge_handler_;
146 // The set of enabled directory types.
147 ModelTypeSet enabled_directory_types_;
149 // The set of observers of per-type debug info.
151 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's
152 // a lot of them, and their lifetimes are unpredictable, so it makes the
153 // book-keeping easier if we just store the list here. That way it's
154 // guaranteed to live as long as this sync backend.
155 base::ObserverList<TypeDebugInfoObserver> type_debug_info_observers_;
157 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_;
159 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry);
162 } // namespace syncer
164 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_