OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "chrome/browser/sync/engine/model_safe_worker.h" | 16 #include "chrome/browser/sync/engine/model_safe_worker.h" |
17 #include "chrome/browser/sync/internal_api/sync_manager.h" | |
17 #include "chrome/browser/sync/syncable/model_type.h" | 18 #include "chrome/browser/sync/syncable/model_type.h" |
18 | 19 |
19 class MessageLoop; | 20 class MessageLoop; |
20 class Profile; | 21 class Profile; |
21 | 22 |
22 namespace sync_api { | 23 namespace sync_api { |
23 struct UserShare; | 24 struct UserShare; |
24 } // namespace sync_api | 25 } // namespace sync_api |
25 | 26 |
26 namespace browser_sync { | 27 namespace browser_sync { |
27 | 28 |
28 class ChangeProcessor; | 29 class ChangeProcessor; |
29 class UIModelWorker; | 30 class UIModelWorker; |
30 | 31 |
31 // A class to keep track of the workers and routing info for the | 32 // A class that keep track of the workers, change processors, and |
32 // enabled sync types. | 33 // routing info for the enabled sync types, and also routes change |
33 class SyncBackendRegistrar : public ModelSafeWorkerRegistrar { | 34 // events to the right processors. |
35 class SyncBackendRegistrar : public ModelSafeWorkerRegistrar, | |
akalin
2011/09/16 02:20:20
not sure if SyncBackendRegistrar is the best name
| |
36 public sync_api::SyncManager::ChangeDelegate { | |
34 public: | 37 public: |
35 // |initial_types| contains the initial set of types to sync | 38 // |initial_types| contains the initial set of types to sync |
36 // (initially put in the passive group). |name| is used for | 39 // (initially put in the passive group). |name| is used for |
37 // debugging. Does not take ownership of |profile| or |sync_loop|. | 40 // debugging. Does not take ownership of |profile| or |sync_loop|. |
38 // Must be created on the UI thread. | 41 // Must be created on the UI thread. |
39 SyncBackendRegistrar(const syncable::ModelTypeSet& initial_types, | 42 SyncBackendRegistrar(const syncable::ModelTypeSet& initial_types, |
40 const std::string& name, | 43 const std::string& name, |
41 Profile* profile, | 44 Profile* profile, |
42 MessageLoop* sync_loop); | 45 MessageLoop* sync_loop); |
43 | 46 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 void ActivateDataType(syncable::ModelType type, | 82 void ActivateDataType(syncable::ModelType type, |
80 ModelSafeGroup group, | 83 ModelSafeGroup group, |
81 ChangeProcessor* change_processor, | 84 ChangeProcessor* change_processor, |
82 sync_api::UserShare* user_share); | 85 sync_api::UserShare* user_share); |
83 | 86 |
84 // Deactivates the given type if necessary. Must be called from the | 87 // Deactivates the given type if necessary. Must be called from the |
85 // UI thread and not |type|'s native thread. Yes, this is | 88 // UI thread and not |type|'s native thread. Yes, this is |
86 // surprising: see http://crbug.com/92804. | 89 // surprising: see http://crbug.com/92804. |
87 void DeactivateDataType(syncable::ModelType type); | 90 void DeactivateDataType(syncable::ModelType type); |
88 | 91 |
89 // Returns the change processor for the given model, or NULL if none | 92 // Returns true only between calls to ActivateDataType(type, ...) |
90 // exists. Must be called from |group|'s native thread. | 93 // and DeactivateDataType(type). Used only by tests. |
91 ChangeProcessor* GetProcessor(syncable::ModelType type); | 94 bool IsTypeActivatedForTest(syncable::ModelType type) const; |
95 | |
96 // SyncManager::ChangeDelegate implementation. May be called from | |
97 // any thread. | |
98 virtual void OnChangesApplied( | |
99 syncable::ModelType model_type, | |
100 const sync_api::BaseTransaction* trans, | |
101 const sync_api::ImmutableChangeRecordList& changes) OVERRIDE; | |
102 virtual void OnChangesComplete(syncable::ModelType model_type) OVERRIDE; | |
92 | 103 |
93 // ModelSafeWorkerRegistrar implementation. May be called from any | 104 // ModelSafeWorkerRegistrar implementation. May be called from any |
94 // thread. | 105 // thread. |
95 virtual void GetWorkers( | 106 virtual void GetWorkers( |
96 std::vector<ModelSafeWorker*>* out) OVERRIDE; | 107 std::vector<ModelSafeWorker*>* out) OVERRIDE; |
97 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE; | 108 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) OVERRIDE; |
98 | 109 |
99 private: | 110 private: |
100 typedef std::map<ModelSafeGroup, | 111 typedef std::map<ModelSafeGroup, |
101 scoped_refptr<ModelSafeWorker> > WorkerMap; | 112 scoped_refptr<ModelSafeWorker> > WorkerMap; |
102 | 113 |
114 // Returns the change processor for the given model, or NULL if none | |
115 // exists. Must be called from |group|'s native thread. | |
116 ChangeProcessor* GetProcessor(syncable::ModelType type) const; | |
117 | |
103 // Must be called with |lock_| held. Simply returns the change | 118 // Must be called with |lock_| held. Simply returns the change |
104 // processor for the given type, if it exists. May be called from | 119 // processor for the given type, if it exists. May be called from |
105 // any thread. | 120 // any thread. |
106 ChangeProcessor* GetProcessorUnsafe(syncable::ModelType type); | 121 ChangeProcessor* GetProcessorUnsafe(syncable::ModelType type) const; |
107 | 122 |
108 // Return true if |model_type| lives on the current thread. Must be | 123 // Return true if |model_type| lives on the current thread. Must be |
109 // called with |lock_| held. May be called on any thread. | 124 // called with |lock_| held. May be called on any thread. |
110 bool IsCurrentThreadSafeForModel( | 125 bool IsCurrentThreadSafeForModel( |
111 syncable::ModelType model_type) const; | 126 syncable::ModelType model_type) const; |
112 | 127 |
113 // Name used for debugging. | 128 // Name used for debugging. |
114 const std::string name_; | 129 const std::string name_; |
115 | 130 |
116 Profile* const profile_; | 131 Profile* const profile_; |
(...skipping 22 matching lines...) Expand all Loading... | |
139 | 154 |
140 // The change processors that handle the different data types. | 155 // The change processors that handle the different data types. |
141 std::map<syncable::ModelType, ChangeProcessor*> processors_; | 156 std::map<syncable::ModelType, ChangeProcessor*> processors_; |
142 | 157 |
143 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); | 158 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); |
144 }; | 159 }; |
145 | 160 |
146 } // namespace browser_sync | 161 } // namespace browser_sync |
147 | 162 |
148 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ | 163 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ |
OLD | NEW |