| OLD | NEW |
| 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/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "components/sync/base/model_type.h" | 19 #include "components/sync/base/model_type.h" |
| 20 #include "components/sync/engine/model_safe_worker.h" | 20 #include "components/sync/engine/model_safe_worker.h" |
| 21 #include "components/sync/engine/sync_manager.h" | 21 #include "components/sync/engine/sync_manager.h" |
| 22 | 22 |
| 23 namespace syncer { | 23 namespace syncer { |
| 24 | 24 |
| 25 class ChangeProcessor; | 25 class ChangeProcessor; |
| 26 class SyncClient; | 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 // |name| is used for debugging. Must be created on the UI thread. | 34 // |name| is used for debugging. Must be created on the UI thread. |
| 35 SyncBackendRegistrar( | 35 SyncBackendRegistrar(const std::string& name, SyncClient* sync_client); |
| 36 const std::string& name, | |
| 37 SyncClient* sync_client, | |
| 38 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | |
| 39 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | |
| 40 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread); | |
| 41 | 36 |
| 42 // A SyncBackendRegistrar is owned by a SyncBackendHostImpl. It is destroyed | 37 // A SyncBackendRegistrar is owned by a SyncBackendHostImpl. It is destroyed |
| 43 // by SyncBackendHostImpl::Shutdown() which performs the following operations | 38 // by SyncBackendHostImpl::Shutdown() which performs the following operations |
| 44 // on the UI thread: | 39 // on the UI thread: |
| 45 // | 40 // |
| 46 // 1) Call SyncBackendRegistrar::RequestWorkerStopOnUIThread(). | 41 // 1) Call SyncBackendRegistrar::RequestWorkerStopOnUIThread(). |
| 47 // 2) Post a SyncBackendHostCore::DoShutdown() task to the sync thread. This | 42 // 2) Post a SyncBackendHostCore::DoShutdown() task to the sync thread. This |
| 48 // task destroys SyncManager which holds a SyncBackendRegistrar pointer. | 43 // task destroys SyncManager which holds a SyncBackendRegistrar pointer. |
| 49 // 3) Take ownership of the sync thread. | 44 // 3) Take ownership of the sync thread. |
| 50 // 4) Post a task to delete the SyncBackendRegistrar on the sync thread. | 45 // 4) Post a task to delete the SyncBackendRegistrar on the sync thread. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 124 |
| 130 // Must be called with |lock_| held. Simply returns the change | 125 // Must be called with |lock_| held. Simply returns the change |
| 131 // processor for the given type, if it exists. May be called from | 126 // processor for the given type, if it exists. May be called from |
| 132 // any thread. | 127 // any thread. |
| 133 ChangeProcessor* GetProcessorUnsafe(ModelType type) const; | 128 ChangeProcessor* GetProcessorUnsafe(ModelType type) const; |
| 134 | 129 |
| 135 // Return true if |model_type| lives on the current thread. Must be | 130 // Return true if |model_type| lives on the current thread. Must be |
| 136 // called with |lock_| held. May be called on any thread. | 131 // called with |lock_| held. May be called on any thread. |
| 137 bool IsCurrentThreadSafeForModel(ModelType model_type) const; | 132 bool IsCurrentThreadSafeForModel(ModelType model_type) const; |
| 138 | 133 |
| 139 // Returns true if the current thread is the native thread for the | |
| 140 // given group (or if it is undeterminable). | |
| 141 bool IsOnThreadForGroup(ModelType type, ModelSafeGroup group) const; | |
| 142 | |
| 143 // Returns model safe group that should be assigned to type when it is first | 134 // Returns model safe group that should be assigned to type when it is first |
| 144 // configured (before activation). Returns GROUP_PASSIVE for directory types | 135 // configured (before activation). Returns GROUP_PASSIVE for directory types |
| 145 // and GROUP_NON_BLOCKING for non-blocking types. | 136 // and GROUP_NON_BLOCKING for non-blocking types. |
| 146 ModelSafeGroup GetInitialGroupForType(ModelType type) const; | 137 ModelSafeGroup GetInitialGroupForType(ModelType type) const; |
| 147 | 138 |
| 148 // Name used for debugging. | 139 // Name used for debugging. |
| 149 const std::string name_; | 140 const std::string name_; |
| 150 | 141 |
| 151 // A pointer to the sync client. | 142 // A pointer to the sync client. |
| 152 SyncClient* const sync_client_; | 143 SyncClient* const sync_client_; |
| 153 | 144 |
| 145 // Checker for the UI thread (where this object is constructed). |
| 146 base::ThreadChecker ui_thread_checker_; |
| 147 |
| 154 // Protects all variables below. | 148 // Protects all variables below. |
| 155 mutable base::Lock lock_; | 149 mutable base::Lock lock_; |
| 156 | 150 |
| 157 // Workers created by this SyncBackendRegistrar. | 151 // Workers created by this SyncBackendRegistrar. |
| 158 WorkerMap workers_; | 152 WorkerMap workers_; |
| 159 | 153 |
| 160 ModelSafeRoutingInfo routing_info_; | 154 ModelSafeRoutingInfo routing_info_; |
| 161 | 155 |
| 162 // The change processors that handle the different data types. | 156 // The change processors that handle the different data types. |
| 163 ProcessorMap processors_; | 157 ProcessorMap processors_; |
| 164 | 158 |
| 165 // The types that were enabled as of the last configuration. Updated on each | 159 // The types that were enabled as of the last configuration. Updated on each |
| 166 // call to ConfigureDataTypes as well as SetInitialTypes. | 160 // call to ConfigureDataTypes as well as SetInitialTypes. |
| 167 ModelTypeSet last_configured_types_; | 161 ModelTypeSet last_configured_types_; |
| 168 | 162 |
| 169 // References to the thread task runners that sync depends on. | |
| 170 const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_; | |
| 171 const scoped_refptr<base::SingleThreadTaskRunner> db_thread_; | |
| 172 const scoped_refptr<base::SingleThreadTaskRunner> file_thread_; | |
| 173 | |
| 174 // Set of types with non-blocking implementation (as opposed to directory | 163 // Set of types with non-blocking implementation (as opposed to directory |
| 175 // based). | 164 // based). |
| 176 ModelTypeSet non_blocking_types_; | 165 ModelTypeSet non_blocking_types_; |
| 177 | 166 |
| 178 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); | 167 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); |
| 179 }; | 168 }; |
| 180 | 169 |
| 181 } // namespace syncer | 170 } // namespace syncer |
| 182 | 171 |
| 183 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_ | 172 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_REGISTRAR_H_ |
| OLD | NEW |