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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 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
OLDNEW
(Empty)
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.
4
5 #ifndef SYNC_SESSIONS_MODEL_TYPE_REGISTRY_H_
6 #define SYNC_SESSIONS_MODEL_TYPE_REGISTRY_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h"
16 #include "sync/base/sync_export.h"
17 #include "sync/engine/nudge_handler.h"
18 #include "sync/internal_api/public/base/model_type.h"
19 #include "sync/internal_api/public/engine/model_safe_worker.h"
20 #include "sync/internal_api/public/model_type_connector.h"
21 #include "sync/internal_api/public/non_blocking_sync_common.h"
22 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
23 #include "sync/internal_api/public/sync_encryption_handler.h"
24
25 namespace syncer_v2 {
26 struct DataTypeState;
27 class ModelTypeProcessor;
28 class ModelTypeWorker;
29 }
30
31 namespace syncer {
32
33 namespace syncable {
34 class Directory;
35 } // namespace syncable
36
37 class CommitContributor;
38 class DirectoryCommitContributor;
39 class DirectoryUpdateHandler;
40 class DirectoryTypeDebugInfoEmitter;
41 class UpdateHandler;
42
43 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
44 typedef std::map<ModelType, CommitContributor*> CommitContributorMap;
45 typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*>
46 DirectoryTypeDebugInfoEmitterMap;
47
48 // Keeps track of the sets of active update handlers and commit contributors.
49 class SYNC_EXPORT ModelTypeRegistry : public syncer_v2::ModelTypeConnector,
50 public SyncEncryptionHandler::Observer {
51 public:
52 // Constructs a ModelTypeRegistry that supports directory types.
53 ModelTypeRegistry(const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
54 syncable::Directory* directory,
55 NudgeHandler* nudge_handler);
56 ~ModelTypeRegistry() override;
57
58 // Sets the set of enabled types.
59 void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info);
60
61 // Enables an off-thread type for syncing. Connects the given proxy
62 // and its task_runner to the newly created worker.
63 //
64 // Expects that the proxy's ModelType is not currently enabled.
65 void ConnectType(syncer::ModelType type,
66 std::unique_ptr<syncer_v2::ActivationContext>
67 activation_context) override;
68
69 // Disables the syncing of an off-thread type.
70 //
71 // Expects that the type is currently enabled.
72 // Deletes the worker associated with the type.
73 void DisconnectType(syncer::ModelType type) override;
74
75 // Implementation of SyncEncryptionHandler::Observer.
76 void OnPassphraseRequired(
77 PassphraseRequiredReason reason,
78 const sync_pb::EncryptedData& pending_keys) override;
79 void OnPassphraseAccepted() override;
80 void OnBootstrapTokenUpdated(const std::string& bootstrap_token,
81 BootstrapTokenType type) override;
82 void OnEncryptedTypesChanged(ModelTypeSet encrypted_types,
83 bool encrypt_everything) override;
84 void OnEncryptionComplete() override;
85 void OnCryptographerStateChanged(Cryptographer* cryptographer) override;
86 void OnPassphraseTypeChanged(PassphraseType type,
87 base::Time passphrase_time) override;
88 void OnLocalSetPassphraseEncryption(
89 const SyncEncryptionHandler::NigoriState& nigori_state) override;
90
91 // Gets the set of enabled types.
92 ModelTypeSet GetEnabledTypes() const;
93
94 // Returns set of types for which initial set of updates was downloaded and
95 // applied.
96 ModelTypeSet GetInitialSyncEndedTypes() const;
97
98 // Simple getters.
99 UpdateHandlerMap* update_handler_map();
100 CommitContributorMap* commit_contributor_map();
101 DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map();
102
103 void RegisterDirectoryTypeDebugInfoObserver(
104 syncer::TypeDebugInfoObserver* observer);
105 void UnregisterDirectoryTypeDebugInfoObserver(
106 syncer::TypeDebugInfoObserver* observer);
107 bool HasDirectoryTypeDebugInfoObserver(
108 const syncer::TypeDebugInfoObserver* observer) const;
109 void RequestEmitDebugInfo();
110
111 base::WeakPtr<ModelTypeConnector> AsWeakPtr();
112
113 private:
114 void OnEncryptionStateChanged();
115
116 ModelTypeSet GetEnabledNonBlockingTypes() const;
117 ModelTypeSet GetEnabledDirectoryTypes() const;
118
119 // Sets of handlers and contributors.
120 ScopedVector<DirectoryCommitContributor> directory_commit_contributors_;
121 ScopedVector<DirectoryUpdateHandler> directory_update_handlers_;
122 ScopedVector<DirectoryTypeDebugInfoEmitter>
123 directory_type_debug_info_emitters_;
124
125 ScopedVector<syncer_v2::ModelTypeWorker> model_type_workers_;
126
127 // Maps of UpdateHandlers and CommitContributors.
128 // They do not own any of the objects they point to.
129 UpdateHandlerMap update_handler_map_;
130 CommitContributorMap commit_contributor_map_;
131
132 // Map of DebugInfoEmitters for directory types.
133 // Non-blocking types handle debug info differently.
134 // Does not own its contents.
135 DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_;
136
137 // The known ModelSafeWorkers.
138 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_map_;
139
140 // The directory. Not owned.
141 syncable::Directory* directory_;
142
143 // A copy of the directory's most recent cryptographer.
144 std::unique_ptr<Cryptographer> cryptographer_;
145
146 // The set of encrypted types.
147 ModelTypeSet encrypted_types_;
148
149 // The NudgeHandler. Not owned.
150 NudgeHandler* nudge_handler_;
151
152 // The set of enabled directory types.
153 ModelTypeSet enabled_directory_types_;
154
155 // The set of observers of per-type debug info.
156 //
157 // Each of the DirectoryTypeDebugInfoEmitters needs such a list. There's
158 // a lot of them, and their lifetimes are unpredictable, so it makes the
159 // book-keeping easier if we just store the list here. That way it's
160 // guaranteed to live as long as this sync backend.
161 base::ObserverList<TypeDebugInfoObserver> type_debug_info_observers_;
162
163 base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_;
164
165 DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry);
166 };
167
168 } // namespace syncer
169
170 #endif // SYNC_SESSIONS_MODEL_TYPE_REGISTRY_H_
OLDNEW
« no previous file with comments | « sync/sessions/directory_type_debug_info_emitter.cc ('k') | sync/sessions/model_type_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698