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 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 5 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return true; | 44 return true; |
45 case MODEL_SAFE_GROUP_COUNT: | 45 case MODEL_SAFE_GROUP_COUNT: |
46 default: | 46 default: |
47 return false; | 47 return false; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 SyncBackendRegistrar::SyncBackendRegistrar( | 53 SyncBackendRegistrar::SyncBackendRegistrar( |
54 syncable::ModelEnumSet initial_types, | 54 syncable::ModelTypeSet initial_types, |
55 const std::string& name, Profile* profile, | 55 const std::string& name, Profile* profile, |
56 MessageLoop* sync_loop) : | 56 MessageLoop* sync_loop) : |
57 name_(name), | 57 name_(name), |
58 profile_(profile), | 58 profile_(profile), |
59 sync_loop_(sync_loop), | 59 sync_loop_(sync_loop), |
60 ui_worker_(new UIModelWorker()), | 60 ui_worker_(new UIModelWorker()), |
61 stopped_on_ui_thread_(false) { | 61 stopped_on_ui_thread_(false) { |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
63 CHECK(profile_); | 63 CHECK(profile_); |
64 DCHECK(sync_loop_); | 64 DCHECK(sync_loop_); |
65 workers_[GROUP_DB] = new DatabaseModelWorker(); | 65 workers_[GROUP_DB] = new DatabaseModelWorker(); |
66 workers_[GROUP_FILE] = new FileModelWorker(); | 66 workers_[GROUP_FILE] = new FileModelWorker(); |
67 workers_[GROUP_UI] = ui_worker_; | 67 workers_[GROUP_UI] = ui_worker_; |
68 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_); | 68 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_); |
69 | 69 |
70 // Any datatypes that we want the syncer to pull down must be in the | 70 // Any datatypes that we want the syncer to pull down must be in the |
71 // routing_info map. We set them to group passive, meaning that | 71 // routing_info map. We set them to group passive, meaning that |
72 // updates will be applied to sync, but not dispatched to the native | 72 // updates will be applied to sync, but not dispatched to the native |
73 // models. | 73 // models. |
74 for (syncable::ModelEnumSet::Iterator it = initial_types.First(); | 74 for (syncable::ModelTypeSet::Iterator it = initial_types.First(); |
75 it.Good(); it.Inc()) { | 75 it.Good(); it.Inc()) { |
76 routing_info_[it.Get()] = GROUP_PASSIVE; | 76 routing_info_[it.Get()] = GROUP_PASSIVE; |
77 } | 77 } |
78 | 78 |
79 HistoryService* history_service = profile->GetHistoryService( | 79 HistoryService* history_service = profile->GetHistoryService( |
80 Profile::IMPLICIT_ACCESS); | 80 Profile::IMPLICIT_ACCESS); |
81 if (history_service) { | 81 if (history_service) { |
82 workers_[GROUP_HISTORY] = new HistoryModelWorker(history_service); | 82 workers_[GROUP_HISTORY] = new HistoryModelWorker(history_service); |
83 } else { | 83 } else { |
84 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS)) | 84 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS)) |
(...skipping 16 matching lines...) Expand all Loading... |
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
102 DCHECK(stopped_on_ui_thread_); | 102 DCHECK(stopped_on_ui_thread_); |
103 } | 103 } |
104 | 104 |
105 bool SyncBackendRegistrar::IsNigoriEnabled() const { | 105 bool SyncBackendRegistrar::IsNigoriEnabled() const { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
107 base::AutoLock lock(lock_); | 107 base::AutoLock lock(lock_); |
108 return routing_info_.find(syncable::NIGORI) != routing_info_.end(); | 108 return routing_info_.find(syncable::NIGORI) != routing_info_.end(); |
109 } | 109 } |
110 | 110 |
111 syncable::ModelEnumSet SyncBackendRegistrar::ConfigureDataTypes( | 111 syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( |
112 syncable::ModelEnumSet types_to_add, | 112 syncable::ModelTypeSet types_to_add, |
113 syncable::ModelEnumSet types_to_remove) { | 113 syncable::ModelTypeSet types_to_remove) { |
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
115 DCHECK(Intersection(types_to_add, types_to_remove).Empty()); | 115 DCHECK(Intersection(types_to_add, types_to_remove).Empty()); |
116 syncable::ModelEnumSet filtered_types_to_add = types_to_add; | 116 syncable::ModelTypeSet filtered_types_to_add = types_to_add; |
117 if (workers_.count(GROUP_HISTORY) == 0) { | 117 if (workers_.count(GROUP_HISTORY) == 0) { |
118 LOG(WARNING) << "No history worker -- removing TYPED_URLS"; | 118 LOG(WARNING) << "No history worker -- removing TYPED_URLS"; |
119 filtered_types_to_add.Remove(syncable::TYPED_URLS); | 119 filtered_types_to_add.Remove(syncable::TYPED_URLS); |
120 } | 120 } |
121 if (workers_.count(GROUP_PASSWORD) == 0) { | 121 if (workers_.count(GROUP_PASSWORD) == 0) { |
122 LOG(WARNING) << "No password worker -- removing PASSWORDS"; | 122 LOG(WARNING) << "No password worker -- removing PASSWORDS"; |
123 filtered_types_to_add.Remove(syncable::PASSWORDS); | 123 filtered_types_to_add.Remove(syncable::PASSWORDS); |
124 } | 124 } |
125 | 125 |
126 base::AutoLock lock(lock_); | 126 base::AutoLock lock(lock_); |
127 syncable::ModelEnumSet newly_added_types; | 127 syncable::ModelTypeSet newly_added_types; |
128 for (syncable::ModelEnumSet::Iterator it = | 128 for (syncable::ModelTypeSet::Iterator it = |
129 filtered_types_to_add.First(); | 129 filtered_types_to_add.First(); |
130 it.Good(); it.Inc()) { | 130 it.Good(); it.Inc()) { |
131 // Add a newly specified data type as GROUP_PASSIVE into the | 131 // Add a newly specified data type as GROUP_PASSIVE into the |
132 // routing_info, if it does not already exist. | 132 // routing_info, if it does not already exist. |
133 if (routing_info_.count(it.Get()) == 0) { | 133 if (routing_info_.count(it.Get()) == 0) { |
134 routing_info_[it.Get()] = GROUP_PASSIVE; | 134 routing_info_[it.Get()] = GROUP_PASSIVE; |
135 newly_added_types.Put(it.Get()); | 135 newly_added_types.Put(it.Get()); |
136 } | 136 } |
137 } | 137 } |
138 for (syncable::ModelEnumSet::Iterator it = types_to_remove.First(); | 138 for (syncable::ModelTypeSet::Iterator it = types_to_remove.First(); |
139 it.Good(); it.Inc()) { | 139 it.Good(); it.Inc()) { |
140 routing_info_.erase(it.Get()); | 140 routing_info_.erase(it.Get()); |
141 } | 141 } |
142 | 142 |
143 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. | 143 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. |
144 DVLOG(1) << name_ << ": Adding types " | 144 DVLOG(1) << name_ << ": Adding types " |
145 << syncable::ModelEnumSetToString(types_to_add) | 145 << syncable::ModelTypeSetToString(types_to_add) |
146 << " (with newly-added types " | 146 << " (with newly-added types " |
147 << syncable::ModelEnumSetToString(newly_added_types) | 147 << syncable::ModelTypeSetToString(newly_added_types) |
148 << ") and removing types " | 148 << ") and removing types " |
149 << syncable::ModelEnumSetToString(types_to_remove) | 149 << syncable::ModelTypeSetToString(types_to_remove) |
150 << " to get new routing info " | 150 << " to get new routing info " |
151 << ModelSafeRoutingInfoToString(routing_info_); | 151 << ModelSafeRoutingInfoToString(routing_info_); |
152 | 152 |
153 return newly_added_types; | 153 return newly_added_types; |
154 } | 154 } |
155 | 155 |
156 void SyncBackendRegistrar::StopOnUIThread() { | 156 void SyncBackendRegistrar::StopOnUIThread() { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 DCHECK(!stopped_on_ui_thread_); | 158 DCHECK(!stopped_on_ui_thread_); |
159 ui_worker_->Stop(); | 159 ui_worker_->Stop(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return it->second; | 278 return it->second; |
279 } | 279 } |
280 | 280 |
281 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 281 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
282 syncable::ModelType model_type) const { | 282 syncable::ModelType model_type) const { |
283 lock_.AssertAcquired(); | 283 lock_.AssertAcquired(); |
284 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); | 284 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); |
285 } | 285 } |
286 | 286 |
287 } // namespace browser_sync | 287 } // namespace browser_sync |
OLD | NEW |