Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/browser/sync/glue/sync_backend_registrar.cc

Issue 8851006: [Sync] Replace all instances of ModelTypeSet with ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <cstddef> 8 #include <cstddef>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return true; 45 return true;
46 case MODEL_SAFE_GROUP_COUNT: 46 case MODEL_SAFE_GROUP_COUNT:
47 default: 47 default:
48 return false; 48 return false;
49 } 49 }
50 } 50 }
51 51
52 } // namespace 52 } // namespace
53 53
54 SyncBackendRegistrar::SyncBackendRegistrar( 54 SyncBackendRegistrar::SyncBackendRegistrar(
55 const syncable::ModelTypeSet& initial_types, 55 syncable::ModelEnumSet initial_types,
56 const std::string& name, Profile* profile, 56 const std::string& name, Profile* profile,
57 MessageLoop* sync_loop) : 57 MessageLoop* sync_loop) :
58 name_(name), 58 name_(name),
59 profile_(profile), 59 profile_(profile),
60 sync_loop_(sync_loop), 60 sync_loop_(sync_loop),
61 ui_worker_(new UIModelWorker()), 61 ui_worker_(new UIModelWorker()),
62 stopped_on_ui_thread_(false) { 62 stopped_on_ui_thread_(false) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 CHECK(profile_); 64 CHECK(profile_);
65 DCHECK(sync_loop_); 65 DCHECK(sync_loop_);
66 workers_[GROUP_DB] = new DatabaseModelWorker(); 66 workers_[GROUP_DB] = new DatabaseModelWorker();
67 workers_[GROUP_FILE] = new FileModelWorker(); 67 workers_[GROUP_FILE] = new FileModelWorker();
68 workers_[GROUP_UI] = ui_worker_; 68 workers_[GROUP_UI] = ui_worker_;
69 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_); 69 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_);
70 70
71 // Any datatypes that we want the syncer to pull down must be in the 71 // Any datatypes that we want the syncer to pull down must be in the
72 // routing_info map. We set them to group passive, meaning that 72 // routing_info map. We set them to group passive, meaning that
73 // updates will be applied to sync, but not dispatched to the native 73 // updates will be applied to sync, but not dispatched to the native
74 // models. 74 // models.
75 for (syncable::ModelTypeSet::const_iterator it = initial_types.begin(); 75 for (syncable::ModelEnumSet::Iterator it = initial_types.First();
76 it != initial_types.end(); ++it) { 76 it.Good(); it.Inc()) {
77 routing_info_[*it] = GROUP_PASSIVE; 77 routing_info_[it.Get()] = GROUP_PASSIVE;
78 } 78 }
79 79
80 HistoryService* history_service = profile->GetHistoryService( 80 HistoryService* history_service = profile->GetHistoryService(
81 Profile::IMPLICIT_ACCESS); 81 Profile::IMPLICIT_ACCESS);
82 if (history_service) { 82 if (history_service) {
83 workers_[GROUP_HISTORY] = new HistoryModelWorker(history_service); 83 workers_[GROUP_HISTORY] = new HistoryModelWorker(history_service);
84 } else { 84 } else {
85 LOG_IF(WARNING, initial_types.count(syncable::TYPED_URLS) > 0) 85 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS))
86 << "History store disabled, cannot sync Omnibox History"; 86 << "History store disabled, cannot sync Omnibox History";
87 routing_info_.erase(syncable::TYPED_URLS); 87 routing_info_.erase(syncable::TYPED_URLS);
88 } 88 }
89 89
90 PasswordStore* password_store = 90 PasswordStore* password_store =
91 profile->GetPasswordStore(Profile::IMPLICIT_ACCESS); 91 profile->GetPasswordStore(Profile::IMPLICIT_ACCESS);
92 if (password_store) { 92 if (password_store) {
93 workers_[GROUP_PASSWORD] = new PasswordModelWorker(password_store); 93 workers_[GROUP_PASSWORD] = new PasswordModelWorker(password_store);
94 } else { 94 } else {
95 LOG_IF(WARNING, initial_types.count(syncable::PASSWORDS) > 0) 95 LOG_IF(WARNING, initial_types.Has(syncable::PASSWORDS))
96 << "Password store not initialized, cannot sync passwords"; 96 << "Password store not initialized, cannot sync passwords";
97 routing_info_.erase(syncable::PASSWORDS); 97 routing_info_.erase(syncable::PASSWORDS);
98 } 98 }
99 } 99 }
100 100
101 SyncBackendRegistrar::~SyncBackendRegistrar() { 101 SyncBackendRegistrar::~SyncBackendRegistrar() {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
103 DCHECK(stopped_on_ui_thread_); 103 DCHECK(stopped_on_ui_thread_);
104 } 104 }
105 105
106 bool SyncBackendRegistrar::IsNigoriEnabled() const { 106 bool SyncBackendRegistrar::IsNigoriEnabled() const {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
108 base::AutoLock lock(lock_); 108 base::AutoLock lock(lock_);
109 return routing_info_.find(syncable::NIGORI) != routing_info_.end(); 109 return routing_info_.find(syncable::NIGORI) != routing_info_.end();
110 } 110 }
111 111
112 syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( 112 syncable::ModelEnumSet SyncBackendRegistrar::ConfigureDataTypes(
113 const syncable::ModelTypeSet& types_to_add, 113 syncable::ModelEnumSet types_to_add,
114 const syncable::ModelTypeSet& types_to_remove) { 114 syncable::ModelEnumSet types_to_remove) {
115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
116 if (DCHECK_IS_ON()) { 116 DCHECK(Intersection(types_to_add, types_to_remove).Empty());
117 syncable::ModelTypeSet intersection; 117 syncable::ModelEnumSet filtered_types_to_add = types_to_add;
118 std::set_intersection(types_to_add.begin(), types_to_add.end(),
119 types_to_remove.begin(), types_to_remove.end(),
120 std::inserter(intersection, intersection.end()));
121 DCHECK(intersection.empty());
122 }
123 syncable::ModelTypeSet filtered_types_to_add = types_to_add;
124 if (workers_.count(GROUP_HISTORY) == 0) { 118 if (workers_.count(GROUP_HISTORY) == 0) {
125 LOG(WARNING) << "No history worker -- removing TYPED_URLS"; 119 LOG(WARNING) << "No history worker -- removing TYPED_URLS";
126 filtered_types_to_add.erase(syncable::TYPED_URLS); 120 filtered_types_to_add.Remove(syncable::TYPED_URLS);
127 } 121 }
128 if (workers_.count(GROUP_PASSWORD) == 0) { 122 if (workers_.count(GROUP_PASSWORD) == 0) {
129 LOG(WARNING) << "No password worker -- removing PASSWORDS"; 123 LOG(WARNING) << "No password worker -- removing PASSWORDS";
130 filtered_types_to_add.erase(syncable::PASSWORDS); 124 filtered_types_to_add.Remove(syncable::PASSWORDS);
131 } 125 }
132 126
133 base::AutoLock lock(lock_); 127 base::AutoLock lock(lock_);
134 syncable::ModelTypeSet newly_added_types; 128 syncable::ModelEnumSet newly_added_types;
135 for (syncable::ModelTypeSet::const_iterator it = 129 for (syncable::ModelEnumSet::Iterator it =
136 filtered_types_to_add.begin(); 130 filtered_types_to_add.First();
137 it != filtered_types_to_add.end(); ++it) { 131 it.Good(); it.Inc()) {
138 // Add a newly specified data type as GROUP_PASSIVE into the 132 // Add a newly specified data type as GROUP_PASSIVE into the
139 // routing_info, if it does not already exist. 133 // routing_info, if it does not already exist.
140 if (routing_info_.count(*it) == 0) { 134 if (routing_info_.count(it.Get()) == 0) {
141 routing_info_[*it] = GROUP_PASSIVE; 135 routing_info_[it.Get()] = GROUP_PASSIVE;
142 newly_added_types.insert(*it); 136 newly_added_types.Put(it.Get());
143 } 137 }
144 } 138 }
145 for (syncable::ModelTypeSet::const_iterator it = types_to_remove.begin(); 139 for (syncable::ModelEnumSet::Iterator it = types_to_remove.First();
146 it != types_to_remove.end(); ++it) { 140 it.Good(); it.Inc()) {
147 routing_info_.erase(*it); 141 routing_info_.erase(it.Get());
148 } 142 }
149 143
150 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. 144 // TODO(akalin): Use SVLOG/SLOG if we add any more logging.
151 DVLOG(1) << name_ << ": Adding types " 145 DVLOG(1) << name_ << ": Adding types "
152 << syncable::ModelTypeSetToString(types_to_add) 146 << syncable::ModelEnumSetToString(types_to_add)
153 << " (with newly-added types " 147 << " (with newly-added types "
154 << syncable::ModelTypeSetToString(newly_added_types) 148 << syncable::ModelEnumSetToString(newly_added_types)
155 << ") and removing types " 149 << ") and removing types "
156 << syncable::ModelTypeSetToString(types_to_remove) 150 << syncable::ModelEnumSetToString(types_to_remove)
157 << " to get new routing info " 151 << " to get new routing info "
158 << ModelSafeRoutingInfoToString(routing_info_); 152 << ModelSafeRoutingInfoToString(routing_info_);
159 153
160 return newly_added_types; 154 return newly_added_types;
161 } 155 }
162 156
163 void SyncBackendRegistrar::StopOnUIThread() { 157 void SyncBackendRegistrar::StopOnUIThread() {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
165 DCHECK(!stopped_on_ui_thread_); 159 DCHECK(!stopped_on_ui_thread_);
166 ui_worker_->Stop(); 160 ui_worker_->Stop();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 return it->second; 279 return it->second;
286 } 280 }
287 281
288 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( 282 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel(
289 syncable::ModelType model_type) const { 283 syncable::ModelType model_type) const {
290 lock_.AssertAcquired(); 284 lock_.AssertAcquired();
291 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); 285 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_));
292 } 286 }
293 287
294 } // namespace browser_sync 288 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698