OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "sync/internal_api/public/base/model_type.h" | 16 #include "sync/internal_api/public/base/model_type.h" |
17 #include "sync/internal_api/public/engine/model_safe_worker.h" | 17 #include "sync/internal_api/public/engine/model_safe_worker.h" |
18 #include "sync/internal_api/public/sync_manager.h" | 18 #include "sync/internal_api/public/sync_manager.h" |
19 | 19 |
20 class Profile; | 20 class Profile; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class MessageLoop; | 23 class MessageLoop; |
24 } | 24 } |
25 | 25 |
26 namespace syncer { | 26 namespace syncer { |
27 struct UserShare; | 27 struct UserShare; |
28 } // namespace syncer | 28 } // namespace syncer |
29 | 29 |
| 30 namespace sync_driver { |
| 31 class ChangeProcessor; |
| 32 } |
| 33 |
30 namespace browser_sync { | 34 namespace browser_sync { |
31 | 35 |
32 class ChangeProcessor; | |
33 class UIModelWorker; | 36 class UIModelWorker; |
34 | 37 |
35 // A class that keep track of the workers, change processors, and | 38 // A class that keep track of the workers, change processors, and |
36 // routing info for the enabled sync types, and also routes change | 39 // routing info for the enabled sync types, and also routes change |
37 // events to the right processors. | 40 // events to the right processors. |
38 class SyncBackendRegistrar : public syncer::SyncManager::ChangeDelegate, | 41 class SyncBackendRegistrar : public syncer::SyncManager::ChangeDelegate, |
39 public syncer::WorkerLoopDestructionObserver { | 42 public syncer::WorkerLoopDestructionObserver { |
40 public: | 43 public: |
41 // |name| is used for debugging. Does not take ownership of |profile| or | 44 // |name| is used for debugging. Does not take ownership of |profile| or |
42 // |sync_loop|. Must be created on the UI thread. | 45 // |sync_loop|. Must be created on the UI thread. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 syncer::ModelTypeSet GetLastConfiguredTypes() const; | 84 syncer::ModelTypeSet GetLastConfiguredTypes() const; |
82 | 85 |
83 // Must be called from the UI thread. (See destructor comment.) | 86 // Must be called from the UI thread. (See destructor comment.) |
84 void RequestWorkerStopOnUIThread(); | 87 void RequestWorkerStopOnUIThread(); |
85 | 88 |
86 // Activates the given data type (which should belong to the given | 89 // Activates the given data type (which should belong to the given |
87 // group) and starts the given change processor. Must be called | 90 // group) and starts the given change processor. Must be called |
88 // from |group|'s native thread. | 91 // from |group|'s native thread. |
89 void ActivateDataType(syncer::ModelType type, | 92 void ActivateDataType(syncer::ModelType type, |
90 syncer::ModelSafeGroup group, | 93 syncer::ModelSafeGroup group, |
91 ChangeProcessor* change_processor, | 94 sync_driver::ChangeProcessor* change_processor, |
92 syncer::UserShare* user_share); | 95 syncer::UserShare* user_share); |
93 | 96 |
94 // Deactivates the given type if necessary. Must be called from the | 97 // Deactivates the given type if necessary. Must be called from the |
95 // UI thread and not |type|'s native thread. Yes, this is | 98 // UI thread and not |type|'s native thread. Yes, this is |
96 // surprising: see http://crbug.com/92804. | 99 // surprising: see http://crbug.com/92804. |
97 void DeactivateDataType(syncer::ModelType type); | 100 void DeactivateDataType(syncer::ModelType type); |
98 | 101 |
99 // Returns true only between calls to ActivateDataType(type, ...) | 102 // Returns true only between calls to ActivateDataType(type, ...) |
100 // and DeactivateDataType(type). Used only by tests. | 103 // and DeactivateDataType(type). Used only by tests. |
101 bool IsTypeActivatedForTest(syncer::ModelType type) const; | 104 bool IsTypeActivatedForTest(syncer::ModelType type) const; |
(...skipping 17 matching lines...) Expand all Loading... |
119 scoped_ptr<base::Thread> ReleaseSyncThread(); | 122 scoped_ptr<base::Thread> ReleaseSyncThread(); |
120 | 123 |
121 // Unregister workers from loop destruction observation. | 124 // Unregister workers from loop destruction observation. |
122 void Shutdown(); | 125 void Shutdown(); |
123 | 126 |
124 base::Thread* sync_thread(); | 127 base::Thread* sync_thread(); |
125 | 128 |
126 private: | 129 private: |
127 typedef std::map<syncer::ModelSafeGroup, | 130 typedef std::map<syncer::ModelSafeGroup, |
128 scoped_refptr<syncer::ModelSafeWorker> > WorkerMap; | 131 scoped_refptr<syncer::ModelSafeWorker> > WorkerMap; |
129 typedef std::map<syncer::ModelType, ChangeProcessor*> | 132 typedef std::map<syncer::ModelType, sync_driver::ChangeProcessor*> |
130 ProcessorMap; | 133 ProcessorMap; |
131 | 134 |
132 // Callback after workers unregister from observing destruction of their | 135 // Callback after workers unregister from observing destruction of their |
133 // working loops. | 136 // working loops. |
134 void OnWorkerUnregistrationDone(syncer::ModelSafeGroup group); | 137 void OnWorkerUnregistrationDone(syncer::ModelSafeGroup group); |
135 | 138 |
136 void RemoveWorker(syncer::ModelSafeGroup group); | 139 void RemoveWorker(syncer::ModelSafeGroup group); |
137 | 140 |
138 // Returns the change processor for the given model, or NULL if none | 141 // Returns the change processor for the given model, or NULL if none |
139 // exists. Must be called from |group|'s native thread. | 142 // exists. Must be called from |group|'s native thread. |
140 ChangeProcessor* GetProcessor(syncer::ModelType type) const; | 143 sync_driver::ChangeProcessor* GetProcessor(syncer::ModelType type) const; |
141 | 144 |
142 // Must be called with |lock_| held. Simply returns the change | 145 // Must be called with |lock_| held. Simply returns the change |
143 // processor for the given type, if it exists. May be called from | 146 // processor for the given type, if it exists. May be called from |
144 // any thread. | 147 // any thread. |
145 ChangeProcessor* GetProcessorUnsafe(syncer::ModelType type) const; | 148 sync_driver::ChangeProcessor* GetProcessorUnsafe( |
| 149 syncer::ModelType type) const; |
146 | 150 |
147 // Return true if |model_type| lives on the current thread. Must be | 151 // Return true if |model_type| lives on the current thread. Must be |
148 // called with |lock_| held. May be called on any thread. | 152 // called with |lock_| held. May be called on any thread. |
149 bool IsCurrentThreadSafeForModel( | 153 bool IsCurrentThreadSafeForModel( |
150 syncer::ModelType model_type) const; | 154 syncer::ModelType model_type) const; |
151 | 155 |
152 // Name used for debugging. | 156 // Name used for debugging. |
153 const std::string name_; | 157 const std::string name_; |
154 | 158 |
155 Profile* const profile_; | 159 Profile* const profile_; |
(...skipping 29 matching lines...) Expand all Loading... |
185 // e.g. Shutdown() depends on |lock_|, SyncManager::Init() depends on | 189 // e.g. Shutdown() depends on |lock_|, SyncManager::Init() depends on |
186 // workers, etc. | 190 // workers, etc. |
187 scoped_ptr<base::Thread> sync_thread_; | 191 scoped_ptr<base::Thread> sync_thread_; |
188 | 192 |
189 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); | 193 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); |
190 }; | 194 }; |
191 | 195 |
192 } // namespace browser_sync | 196 } // namespace browser_sync |
193 | 197 |
194 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ | 198 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ |
OLD | NEW |