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

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

Issue 10911073: NOT FOR COMMIT: Add DeviceInfo type and ChangeProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix several issues Created 8 years, 3 months 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) 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 #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 11 matching lines...) Expand all
22 #include "sync/internal_api/public/engine/passive_model_worker.h" 22 #include "sync/internal_api/public/engine/passive_model_worker.h"
23 23
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 namespace browser_sync { 26 namespace browser_sync {
27 27
28 namespace { 28 namespace {
29 29
30 // Returns true if the current thread is the native thread for the 30 // Returns true if the current thread is the native thread for the
31 // given group (or if it is undeterminable). 31 // given group (or if it is undeterminable).
32 bool IsOnThreadForGroup(syncer::ModelSafeGroup group) { 32 bool IsOnThreadForGroup(syncer::ModelType type, syncer::ModelSafeGroup group) {
33 switch (group) { 33 switch (group) {
34 case syncer::GROUP_PASSIVE: 34 case syncer::GROUP_PASSIVE:
35 return false; 35 return IsControlType(type);
36 case syncer::GROUP_UI: 36 case syncer::GROUP_UI:
37 return BrowserThread::CurrentlyOn(BrowserThread::UI); 37 return BrowserThread::CurrentlyOn(BrowserThread::UI);
38 case syncer::GROUP_DB: 38 case syncer::GROUP_DB:
39 return BrowserThread::CurrentlyOn(BrowserThread::DB); 39 return BrowserThread::CurrentlyOn(BrowserThread::DB);
40 case syncer::GROUP_FILE: 40 case syncer::GROUP_FILE:
41 return BrowserThread::CurrentlyOn(BrowserThread::FILE); 41 return BrowserThread::CurrentlyOn(BrowserThread::FILE);
42 case syncer::GROUP_HISTORY: 42 case syncer::GROUP_HISTORY:
43 // TODO(ncarter): How to determine this? 43 // TODO(sync): How to check we're on the right thread?
44 return true; 44 return type == syncer::TYPED_URLS;
45 case syncer::GROUP_PASSWORD: 45 case syncer::GROUP_PASSWORD:
46 // TODO(ncarter): How to determine this? 46 // TODO(sync): How to check we're on the right thread?
47 return true; 47 return type == syncer::PASSWORDS;
48 case syncer::MODEL_SAFE_GROUP_COUNT: 48 case syncer::MODEL_SAFE_GROUP_COUNT:
49 default: 49 default:
50 return false; 50 return false;
51 } 51 }
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 SyncBackendRegistrar::SyncBackendRegistrar( 56 SyncBackendRegistrar::SyncBackendRegistrar(
57 const std::string& name, Profile* profile, 57 const std::string& name, Profile* profile,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void SyncBackendRegistrar::OnSyncerShutdownComplete() { 177 void SyncBackendRegistrar::OnSyncerShutdownComplete() {
178 DCHECK_EQ(MessageLoop::current(), sync_loop_); 178 DCHECK_EQ(MessageLoop::current(), sync_loop_);
179 ui_worker_->OnSyncerShutdownComplete(); 179 ui_worker_->OnSyncerShutdownComplete();
180 } 180 }
181 181
182 void SyncBackendRegistrar::ActivateDataType( 182 void SyncBackendRegistrar::ActivateDataType(
183 syncer::ModelType type, 183 syncer::ModelType type,
184 syncer::ModelSafeGroup group, 184 syncer::ModelSafeGroup group,
185 ChangeProcessor* change_processor, 185 ChangeProcessor* change_processor,
186 syncer::UserShare* user_share) { 186 syncer::UserShare* user_share) {
187 CHECK(IsOnThreadForGroup(group)); 187 CHECK(IsOnThreadForGroup(type, group));
188 base::AutoLock lock(lock_); 188 base::AutoLock lock(lock_);
189 // Ensure that the given data type is in the PASSIVE group. 189 // Ensure that the given data type is in the PASSIVE group.
190 syncer::ModelSafeRoutingInfo::iterator i = routing_info_.find(type); 190 syncer::ModelSafeRoutingInfo::iterator i = routing_info_.find(type);
191 DCHECK(i != routing_info_.end()); 191 DCHECK(i != routing_info_.end());
192 DCHECK_EQ(i->second, syncer::GROUP_PASSIVE); 192 DCHECK_EQ(i->second, syncer::GROUP_PASSIVE);
193 routing_info_[type] = group; 193 routing_info_[type] = group;
194 CHECK(IsCurrentThreadSafeForModel(type)); 194 CHECK(IsCurrentThreadSafeForModel(type));
195 195
196 // Add the data type's change processor to the list of change 196 // Add the data type's change processor to the list of change
197 // processors so it can receive updates. 197 // processors so it can receive updates.
198 DCHECK_EQ(processors_.count(type), 0U); 198 DCHECK_EQ(processors_.count(type), 0U);
199 processors_[type] = change_processor; 199 processors_[type] = change_processor;
200 200
201 // Start the change processor. 201 // Start the change processor.
202 change_processor->Start(profile_, user_share); 202 change_processor->Start(profile_, user_share);
203 DCHECK(GetProcessorUnsafe(type)); 203 DCHECK(GetProcessorUnsafe(type));
204 } 204 }
205 205
206 void SyncBackendRegistrar::DeactivateDataType(syncer::ModelType type) { 206 void SyncBackendRegistrar::DeactivateDataType(syncer::ModelType type) {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || IsControlType(type));
208 base::AutoLock lock(lock_); 208 base::AutoLock lock(lock_);
209 ChangeProcessor* change_processor = GetProcessorUnsafe(type); 209 ChangeProcessor* change_processor = GetProcessorUnsafe(type);
210 if (change_processor) 210 if (change_processor)
211 change_processor->Stop(); 211 change_processor->Stop();
212 212
213 routing_info_.erase(type); 213 routing_info_.erase(type);
214 ignore_result(processors_.erase(type)); 214 ignore_result(processors_.erase(type));
215 DCHECK(!GetProcessorUnsafe(type)); 215 DCHECK(!GetProcessorUnsafe(type));
216 } 216 }
217 217
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // |processors_| list. 287 // |processors_| list.
288 if (it == processors_.end()) 288 if (it == processors_.end())
289 return NULL; 289 return NULL;
290 290
291 return it->second; 291 return it->second;
292 } 292 }
293 293
294 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( 294 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel(
295 syncer::ModelType model_type) const { 295 syncer::ModelType model_type) const {
296 lock_.AssertAcquired(); 296 lock_.AssertAcquired();
297 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); 297 return IsOnThreadForGroup(model_type,
298 GetGroupForModelType(model_type, routing_info_));
298 } 299 }
299 300
300 } // namespace browser_sync 301 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host_unittest.cc ('k') | chrome/browser/sync/glue/synced_device_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698