| 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 #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 "sync/internal_api/public/engine/model_safe_worker.h" | 16 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 17 #include "sync/internal_api/public/sync_manager.h" | 17 #include "sync/internal_api/public/sync_manager.h" |
| 18 #include "sync/internal_api/public/syncable/model_type.h" | 18 #include "sync/internal_api/public/syncable/model_type.h" |
| 19 | 19 |
| 20 class MessageLoop; | 20 class MessageLoop; |
| 21 class Profile; | 21 class Profile; |
| 22 | 22 |
| 23 namespace csync { | 23 namespace syncer { |
| 24 struct UserShare; | 24 struct UserShare; |
| 25 } // namespace csync | 25 } // namespace syncer |
| 26 | 26 |
| 27 namespace browser_sync { | 27 namespace browser_sync { |
| 28 | 28 |
| 29 class ChangeProcessor; | 29 class ChangeProcessor; |
| 30 class UIModelWorker; | 30 class UIModelWorker; |
| 31 | 31 |
| 32 // A class that keep track of the workers, change processors, and | 32 // A class that keep track of the workers, change processors, and |
| 33 // routing info for the enabled sync types, and also routes change | 33 // routing info for the enabled sync types, and also routes change |
| 34 // events to the right processors. | 34 // events to the right processors. |
| 35 class SyncBackendRegistrar : public csync::SyncManager::ChangeDelegate { | 35 class SyncBackendRegistrar : public syncer::SyncManager::ChangeDelegate { |
| 36 public: | 36 public: |
| 37 // |initial_types| contains the initial set of types to sync | 37 // |initial_types| contains the initial set of types to sync |
| 38 // (initially put in the passive group). |name| is used for | 38 // (initially put in the passive group). |name| is used for |
| 39 // debugging. Does not take ownership of |profile| or |sync_loop|. | 39 // debugging. Does not take ownership of |profile| or |sync_loop|. |
| 40 // Must be created on the UI thread. | 40 // Must be created on the UI thread. |
| 41 SyncBackendRegistrar(syncable::ModelTypeSet initial_types, | 41 SyncBackendRegistrar(syncable::ModelTypeSet initial_types, |
| 42 const std::string& name, | 42 const std::string& name, |
| 43 Profile* profile, | 43 Profile* profile, |
| 44 MessageLoop* sync_loop); | 44 MessageLoop* sync_loop); |
| 45 | 45 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 72 // Must be called from the UI thread. (See destructor comment.) | 72 // Must be called from the UI thread. (See destructor comment.) |
| 73 void StopOnUIThread(); | 73 void StopOnUIThread(); |
| 74 | 74 |
| 75 // Must be called from the sync thread. (See destructor comment.) | 75 // Must be called from the sync thread. (See destructor comment.) |
| 76 void OnSyncerShutdownComplete(); | 76 void OnSyncerShutdownComplete(); |
| 77 | 77 |
| 78 // Activates the given data type (which should belong to the given | 78 // Activates the given data type (which should belong to the given |
| 79 // group) and starts the given change processor. Must be called | 79 // group) and starts the given change processor. Must be called |
| 80 // from |group|'s native thread. | 80 // from |group|'s native thread. |
| 81 void ActivateDataType(syncable::ModelType type, | 81 void ActivateDataType(syncable::ModelType type, |
| 82 csync::ModelSafeGroup group, | 82 syncer::ModelSafeGroup group, |
| 83 ChangeProcessor* change_processor, | 83 ChangeProcessor* change_processor, |
| 84 csync::UserShare* user_share); | 84 syncer::UserShare* user_share); |
| 85 | 85 |
| 86 // Deactivates the given type if necessary. Must be called from the | 86 // Deactivates the given type if necessary. Must be called from the |
| 87 // UI thread and not |type|'s native thread. Yes, this is | 87 // UI thread and not |type|'s native thread. Yes, this is |
| 88 // surprising: see http://crbug.com/92804. | 88 // surprising: see http://crbug.com/92804. |
| 89 void DeactivateDataType(syncable::ModelType type); | 89 void DeactivateDataType(syncable::ModelType type); |
| 90 | 90 |
| 91 // Returns true only between calls to ActivateDataType(type, ...) | 91 // Returns true only between calls to ActivateDataType(type, ...) |
| 92 // and DeactivateDataType(type). Used only by tests. | 92 // and DeactivateDataType(type). Used only by tests. |
| 93 bool IsTypeActivatedForTest(syncable::ModelType type) const; | 93 bool IsTypeActivatedForTest(syncable::ModelType type) const; |
| 94 | 94 |
| 95 // SyncManager::ChangeDelegate implementation. May be called from | 95 // SyncManager::ChangeDelegate implementation. May be called from |
| 96 // any thread. | 96 // any thread. |
| 97 virtual void OnChangesApplied( | 97 virtual void OnChangesApplied( |
| 98 syncable::ModelType model_type, | 98 syncable::ModelType model_type, |
| 99 const csync::BaseTransaction* trans, | 99 const syncer::BaseTransaction* trans, |
| 100 const csync::ImmutableChangeRecordList& changes) OVERRIDE; | 100 const syncer::ImmutableChangeRecordList& changes) OVERRIDE; |
| 101 virtual void OnChangesComplete(syncable::ModelType model_type) OVERRIDE; | 101 virtual void OnChangesComplete(syncable::ModelType model_type) OVERRIDE; |
| 102 | 102 |
| 103 void GetWorkers(std::vector<csync::ModelSafeWorker*>* out); | 103 void GetWorkers(std::vector<syncer::ModelSafeWorker*>* out); |
| 104 void GetModelSafeRoutingInfo(csync::ModelSafeRoutingInfo* out); | 104 void GetModelSafeRoutingInfo(syncer::ModelSafeRoutingInfo* out); |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 typedef std::map<csync::ModelSafeGroup, | 107 typedef std::map<syncer::ModelSafeGroup, |
| 108 scoped_refptr<csync::ModelSafeWorker> > WorkerMap; | 108 scoped_refptr<syncer::ModelSafeWorker> > WorkerMap; |
| 109 | 109 |
| 110 // Returns the change processor for the given model, or NULL if none | 110 // Returns the change processor for the given model, or NULL if none |
| 111 // exists. Must be called from |group|'s native thread. | 111 // exists. Must be called from |group|'s native thread. |
| 112 ChangeProcessor* GetProcessor(syncable::ModelType type) const; | 112 ChangeProcessor* GetProcessor(syncable::ModelType type) const; |
| 113 | 113 |
| 114 // Must be called with |lock_| held. Simply returns the change | 114 // Must be called with |lock_| held. Simply returns the change |
| 115 // processor for the given type, if it exists. May be called from | 115 // processor for the given type, if it exists. May be called from |
| 116 // any thread. | 116 // any thread. |
| 117 ChangeProcessor* GetProcessorUnsafe(syncable::ModelType type) const; | 117 ChangeProcessor* GetProcessorUnsafe(syncable::ModelType type) const; |
| 118 | 118 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 135 // Protects all variables below. | 135 // Protects all variables below. |
| 136 mutable base::Lock lock_; | 136 mutable base::Lock lock_; |
| 137 | 137 |
| 138 // We maintain ownership of all workers. In some cases, we need to | 138 // We maintain ownership of all workers. In some cases, we need to |
| 139 // ensure shutdown occurs in an expected sequence by Stop()ing | 139 // ensure shutdown occurs in an expected sequence by Stop()ing |
| 140 // certain workers. They are guaranteed to be valid because we only | 140 // certain workers. They are guaranteed to be valid because we only |
| 141 // destroy elements of |workers_| after the syncapi has been | 141 // destroy elements of |workers_| after the syncapi has been |
| 142 // destroyed. Unless a worker is no longer needed because all types | 142 // destroyed. Unless a worker is no longer needed because all types |
| 143 // that get routed to it have been disabled (from syncing). In that | 143 // that get routed to it have been disabled (from syncing). In that |
| 144 // case, we'll destroy on demand *after* routing any dependent types | 144 // case, we'll destroy on demand *after* routing any dependent types |
| 145 // to csync::GROUP_PASSIVE, so that the syncapi doesn't call into garbage. | 145 // to syncer::GROUP_PASSIVE, so that the syncapi doesn't call into garbage. |
| 146 // If a key is present, it means at least one ModelType that routes | 146 // If a key is present, it means at least one ModelType that routes |
| 147 // to that model safe group is being synced. | 147 // to that model safe group is being synced. |
| 148 WorkerMap workers_; | 148 WorkerMap workers_; |
| 149 csync::ModelSafeRoutingInfo routing_info_; | 149 syncer::ModelSafeRoutingInfo routing_info_; |
| 150 | 150 |
| 151 // The change processors that handle the different data types. | 151 // The change processors that handle the different data types. |
| 152 std::map<syncable::ModelType, ChangeProcessor*> processors_; | 152 std::map<syncable::ModelType, ChangeProcessor*> processors_; |
| 153 | 153 |
| 154 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); | 154 DISALLOW_COPY_AND_ASSIGN(SyncBackendRegistrar); |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 } // namespace browser_sync | 157 } // namespace browser_sync |
| 158 | 158 |
| 159 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ | 159 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_REGISTRAR_H_ |
| OLD | NEW |