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

Side by Side Diff: components/sync/driver/glue/sync_backend_registrar.h

Issue 2501743005: [Sync] Remove SyncClient dep from SyncBackendRegistrar. (Closed)
Patch Set: Self-review. Created 4 years, 1 month 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_ 5 #ifndef COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_
6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_ 6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
19 #include "components/sync/base/model_type.h" 20 #include "components/sync/base/model_type.h"
20 #include "components/sync/engine/model_safe_worker.h" 21 #include "components/sync/engine/model_safe_worker.h"
21 #include "components/sync/engine/sync_manager.h" 22 #include "components/sync/engine/sync_manager.h"
22 23
23 namespace syncer { 24 namespace syncer {
24 25
25 class ChangeProcessor; 26 class ChangeProcessor;
26 class SyncClient;
27 struct UserShare; 27 struct UserShare;
28 28
29 // A class that keep track of the workers, change processors, and 29 // A class that keep track of the workers, change processors, and
30 // routing info for the enabled sync types, and also routes change 30 // routing info for the enabled sync types, and also routes change
31 // events to the right processors. 31 // events to the right processors.
32 class SyncBackendRegistrar : public SyncManager::ChangeDelegate { 32 class SyncBackendRegistrar : public SyncManager::ChangeDelegate {
33 public: 33 public:
34 using ModelSafeWorkerFactory =
35 base::Callback<scoped_refptr<ModelSafeWorker>(ModelSafeGroup)>;
36
34 // |name| is used for debugging. Must be created on the UI thread. 37 // |name| is used for debugging. Must be created on the UI thread.
35 SyncBackendRegistrar(const std::string& name, SyncClient* sync_client); 38 SyncBackendRegistrar(const std::string& name,
39 ModelSafeWorkerFactory worker_factory);
36 40
37 // A SyncBackendRegistrar is owned by a SyncBackendHostImpl. It is destroyed 41 // A SyncBackendRegistrar is owned by a SyncBackendHostImpl. It is destroyed
38 // by SyncBackendHostImpl::Shutdown() which performs the following operations 42 // by SyncBackendHostImpl::Shutdown() which performs the following operations
39 // on the UI thread: 43 // on the UI thread:
40 // 44 //
41 // 1) Call SyncBackendRegistrar::RequestWorkerStopOnUIThread(). 45 // 1) Call SyncBackendRegistrar::RequestWorkerStopOnUIThread().
42 // 2) Post a SyncBackendHostCore::DoShutdown() task to the sync thread. This 46 // 2) Post a SyncBackendHostCore::DoShutdown() task to the sync thread. This
43 // task destroys SyncManager which holds a SyncBackendRegistrar pointer. 47 // task destroys SyncManager which holds a SyncBackendRegistrar pointer.
44 // 3) Take ownership of the sync thread. 48 // 3) Take ownership of the sync thread.
45 // 4) Post a task to delete the SyncBackendRegistrar on the sync thread. 49 // 4) Post a task to delete the SyncBackendRegistrar on the sync thread.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const ImmutableChangeRecordList& changes) override; 112 const ImmutableChangeRecordList& changes) override;
109 void OnChangesComplete(ModelType model_type) override; 113 void OnChangesComplete(ModelType model_type) override;
110 114
111 void GetWorkers(std::vector<scoped_refptr<ModelSafeWorker>>* out); 115 void GetWorkers(std::vector<scoped_refptr<ModelSafeWorker>>* out);
112 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out); 116 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out);
113 117
114 private: 118 private:
115 typedef std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker>> WorkerMap; 119 typedef std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker>> WorkerMap;
116 typedef std::map<ModelType, ChangeProcessor*> ProcessorMap; 120 typedef std::map<ModelType, ChangeProcessor*> ProcessorMap;
117 121
118 // Add a worker for |group| to the worker map if one can be created. 122 // Add a worker for |group| to the worker map if one is successfully created
119 void MaybeAddWorker(ModelSafeGroup group); 123 // by |worker_factory|.
124 void MaybeAddWorker(ModelSafeWorkerFactory worker_factory,
125 ModelSafeGroup group);
120 126
121 // Returns the change processor for the given model, or null if none 127 // Returns the change processor for the given model, or null if none
122 // exists. Must be called from |group|'s native thread. 128 // exists. Must be called from |group|'s native thread.
123 ChangeProcessor* GetProcessor(ModelType type) const; 129 ChangeProcessor* GetProcessor(ModelType type) const;
124 130
125 // Must be called with |lock_| held. Simply returns the change 131 // Must be called with |lock_| held. Simply returns the change
126 // processor for the given type, if it exists. May be called from 132 // processor for the given type, if it exists. May be called from
127 // any thread. 133 // any thread.
128 ChangeProcessor* GetProcessorUnsafe(ModelType type) const; 134 ChangeProcessor* GetProcessorUnsafe(ModelType type) const;
129 135
130 // Return true if |model_type| lives on the current thread. Must be 136 // Return true if |model_type| lives on the current thread. Must be
131 // called with |lock_| held. May be called on any thread. 137 // called with |lock_| held. May be called on any thread.
132 bool IsCurrentThreadSafeForModel(ModelType model_type) const; 138 bool IsCurrentThreadSafeForModel(ModelType model_type) const;
133 139
134 // Returns model safe group that should be assigned to type when it is first 140 // Returns model safe group that should be assigned to type when it is first
135 // configured (before activation). Returns GROUP_PASSIVE for directory types 141 // configured (before activation). Returns GROUP_PASSIVE for directory types
136 // and GROUP_NON_BLOCKING for non-blocking types. 142 // and GROUP_NON_BLOCKING for non-blocking types.
137 ModelSafeGroup GetInitialGroupForType(ModelType type) const; 143 ModelSafeGroup GetInitialGroupForType(ModelType type) const;
138 144
139 // Name used for debugging. 145 // Name used for debugging.
140 const std::string name_; 146 const std::string name_;
141 147
142 // A pointer to the sync client.
143 SyncClient* const sync_client_;
144
145 // Checker for the UI thread (where this object is constructed). 148 // Checker for the UI thread (where this object is constructed).
146 base::ThreadChecker ui_thread_checker_; 149 base::ThreadChecker ui_thread_checker_;
147 150
148 // Protects all variables below. 151 // Protects all variables below.
149 mutable base::Lock lock_; 152 mutable base::Lock lock_;
150 153
151 // Workers created by this SyncBackendRegistrar. 154 // Workers created by this SyncBackendRegistrar.
152 WorkerMap workers_; 155 WorkerMap workers_;
153 156
154 ModelSafeRoutingInfo routing_info_; 157 ModelSafeRoutingInfo routing_info_;
155 158
156 // The change processors that handle the different data types. 159 // The change processors that handle the different data types.
157 ProcessorMap processors_; 160 ProcessorMap processors_;
158 161
159 // The types that were enabled as of the last configuration. Updated on each 162 // The types that were enabled as of the last configuration. Updated on each
160 // call to ConfigureDataTypes as well as SetInitialTypes. 163 // call to ConfigureDataTypes as well as SetInitialTypes.
161 ModelTypeSet last_configured_types_; 164 ModelTypeSet last_configured_types_;
162 165
163 // Set of types with non-blocking implementation (as opposed to directory 166 // Set of types with non-blocking implementation (as opposed to directory
164 // based). 167 // based).
165 ModelTypeSet non_blocking_types_; 168 ModelTypeSet non_blocking_types_;
166 169
167 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); 170 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar);
168 }; 171 };
169 172
170 } // namespace syncer 173 } // namespace syncer
171 174
172 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_ 175 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_host_impl.cc ('k') | components/sync/driver/glue/sync_backend_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698