V4L2SVDA: Drop any pending slices/state in H264Accelerator on reset.
[chromium-blink-merge.git] / sync / sessions / model_type_registry.h
blob6cae55e13febcec5cff4080ece22c75a94134f2a
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;
87 // Gets the set of enabled types.
88 ModelTypeSet GetEnabledTypes() const;
90 // Simple getters.
91 UpdateHandlerMap* update_handler_map();
92 CommitContributorMap* commit_contributor_map();
93 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map();
95 void RegisterDirectoryTypeDebugInfoObserver(
96 syncer::TypeDebugInfoObserver* observer);
97 void UnregisterDirectoryTypeDebugInfoObserver(
98 syncer::TypeDebugInfoObserver* observer);
99 bool HasDirectoryTypeDebugInfoObserver(
100 const syncer::TypeDebugInfoObserver* observer) const;
101 void RequestEmitDebugInfo();
103 base::WeakPtr<SyncContext> AsWeakPtr();
105 private:
106 void OnEncryptionStateChanged();
108 ModelTypeSet GetEnabledNonBlockingTypes() const;
109 ModelTypeSet GetEnabledDirectoryTypes() const;
111 // Sets of handlers and contributors.
112 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_;
113 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_;
114 ScopedVector<DirectoryTypeDebugInfoEmitter>
115 directory_type_debug_info_emitters_;
117 ScopedVector<ModelTypeSyncWorkerImpl> model_type_sync_workers_;
119 // Maps of UpdateHandlers and CommitContributors.
120 // They do not own any of the objects they point to.
121 UpdateHandlerMap update_handler_map_;
122 CommitContributorMap commit_contributor_map_;
124 // Map of DebugInfoEmitters for directory types.
125 // Non-blocking types handle debug info differently.
126 // Does not own its contents.
127 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_;
129 // The known ModelSafeWorkers.
130 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_;
132 // The directory. Not owned.
133 syncable::Directory* directory_;
135 // A copy of the directory's most recent cryptographer.
136 scoped_ptr<Cryptographer> cryptographer_;
138 // The set of encrypted types.
139 ModelTypeSet encrypted_types_;
141 // The NudgeHandler. Not owned.
142 NudgeHandler* nudge_handler_;
144 // The set of enabled directory types.
145 ModelTypeSet enabled_directory_types_;
147 // The set of observers of per-type debug info.
149 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's
150 // a lot of them, and their lifetimes are unpredictable, so it makes the
151 // book-keeping easier if we just store the list here. That way it's
152 // guaranteed to live as long as this sync backend.
153 ObserverList<TypeDebugInfoObserver> type_debug_info_observers_;
155 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_;
157 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry);
160 } // namespace syncer
162 #endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_