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

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

Issue 10832286: sync: Introduce control data types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to Tim's comments Created 8 years, 4 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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "chrome/browser/history/history_service_factory.h" 12 #include "chrome/browser/history/history_service_factory.h"
13 #include "chrome/browser/password_manager/password_store.h" 13 #include "chrome/browser/password_manager/password_store.h"
14 #include "chrome/browser/password_manager/password_store_factory.h" 14 #include "chrome/browser/password_manager/password_store_factory.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sync/glue/browser_thread_model_worker.h" 16 #include "chrome/browser/sync/glue/browser_thread_model_worker.h"
17 #include "chrome/browser/sync/glue/change_processor.h" 17 #include "chrome/browser/sync/glue/change_processor.h"
18 #include "chrome/browser/sync/glue/history_model_worker.h" 18 #include "chrome/browser/sync/glue/history_model_worker.h"
19 #include "chrome/browser/sync/glue/password_model_worker.h" 19 #include "chrome/browser/sync/glue/password_model_worker.h"
20 #include "chrome/browser/sync/glue/ui_model_worker.h" 20 #include "chrome/browser/sync/glue/ui_model_worker.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "sync/internal_api/public/engine/control_model_worker.h"
22 #include "sync/internal_api/public/engine/passive_model_worker.h" 23 #include "sync/internal_api/public/engine/passive_model_worker.h"
23 24
24 using content::BrowserThread; 25 using content::BrowserThread;
25 26
26 namespace browser_sync { 27 namespace browser_sync {
27 28
28 namespace { 29 namespace {
29 30
30 // Returns true if the current thread is the native thread for the 31 // Returns true if the current thread is the native thread for the
31 // given group (or if it is undeterminable). 32 // given group (or if it is undeterminable).
32 bool IsOnThreadForGroup(syncer::ModelSafeGroup group) { 33 bool IsOnThreadForGroup(syncer::ModelSafeGroup group) {
33 switch (group) { 34 switch (group) {
34 case syncer::GROUP_PASSIVE: 35 case syncer::GROUP_PASSIVE:
35 return false; 36 return false;
37 case syncer::GROUP_CONTROL:
38 return false;
36 case syncer::GROUP_UI: 39 case syncer::GROUP_UI:
37 return BrowserThread::CurrentlyOn(BrowserThread::UI); 40 return BrowserThread::CurrentlyOn(BrowserThread::UI);
38 case syncer::GROUP_DB: 41 case syncer::GROUP_DB:
39 return BrowserThread::CurrentlyOn(BrowserThread::DB); 42 return BrowserThread::CurrentlyOn(BrowserThread::DB);
40 case syncer::GROUP_FILE: 43 case syncer::GROUP_FILE:
41 return BrowserThread::CurrentlyOn(BrowserThread::FILE); 44 return BrowserThread::CurrentlyOn(BrowserThread::FILE);
42 case syncer::GROUP_HISTORY: 45 case syncer::GROUP_HISTORY:
43 // TODO(ncarter): How to determine this? 46 // TODO(ncarter): How to determine this?
44 return true; 47 return true;
45 case syncer::GROUP_PASSWORD: 48 case syncer::GROUP_PASSWORD:
(...skipping 15 matching lines...) Expand all
61 sync_loop_(sync_loop), 64 sync_loop_(sync_loop),
62 ui_worker_(new UIModelWorker()), 65 ui_worker_(new UIModelWorker()),
63 stopped_on_ui_thread_(false) { 66 stopped_on_ui_thread_(false) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 CHECK(profile_); 68 CHECK(profile_);
66 DCHECK(sync_loop_); 69 DCHECK(sync_loop_);
67 workers_[syncer::GROUP_DB] = new DatabaseModelWorker(); 70 workers_[syncer::GROUP_DB] = new DatabaseModelWorker();
68 workers_[syncer::GROUP_FILE] = new FileModelWorker(); 71 workers_[syncer::GROUP_FILE] = new FileModelWorker();
69 workers_[syncer::GROUP_UI] = ui_worker_; 72 workers_[syncer::GROUP_UI] = ui_worker_;
70 workers_[syncer::GROUP_PASSIVE] = new syncer::PassiveModelWorker(sync_loop_); 73 workers_[syncer::GROUP_PASSIVE] = new syncer::PassiveModelWorker(sync_loop_);
74 workers_[syncer::GROUP_CONTROL] = new syncer::ControlModelWorker(sync_loop_);
71 75
72 HistoryService* history_service = 76 HistoryService* history_service =
73 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); 77 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS);
74 if (history_service) { 78 if (history_service) {
75 workers_[syncer::GROUP_HISTORY] = new HistoryModelWorker(history_service); 79 workers_[syncer::GROUP_HISTORY] = new HistoryModelWorker(history_service);
76 } 80 }
77 81
78 scoped_refptr<PasswordStore> password_store = 82 scoped_refptr<PasswordStore> password_store =
79 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); 83 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS);
80 if (password_store.get()) { 84 if (password_store.get()) {
81 workers_[syncer::GROUP_PASSWORD] = new PasswordModelWorker(password_store); 85 workers_[syncer::GROUP_PASSWORD] = new PasswordModelWorker(password_store);
82 } 86 }
83 } 87 }
84 88
85 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) { 89 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) {
tim (not reviewing) 2012/08/30 20:18:33 nit - shouldn't this be a const ModelTypeSet&?
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
87 base::AutoLock lock(lock_); 91 base::AutoLock lock(lock_);
88 92
89 // This function should be called only once, shortly after construction. The 93 // This function should be called only once, shortly after construction. The
90 // routing info at that point is expected to be emtpy. 94 // routing info at that point is expected to be emtpy.
91 DCHECK(routing_info_.empty()); 95 DCHECK(routing_info_.empty());
92 96
93 // Set our initial state to reflect the current status of the sync directory. 97 // Set our initial state to reflect the current status of the sync directory.
94 // This will ensure that our calculations in ConfigureDataTypes() will always 98 // This will ensure that our calculations in ConfigureDataTypes() will always
95 // return correct results. 99 // return correct results.
96 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); 100 for (syncer::ModelTypeSet::Iterator it = initial_types.First();
97 it.Good(); it.Inc()) { 101 it.Good(); it.Inc()) {
98 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; 102 if (IsControlType(it.Get())) {
103 routing_info_[it.Get()] = syncer::GROUP_CONTROL;
104 } else {
105 routing_info_[it.Get()] = syncer::GROUP_PASSIVE;
106 }
99 } 107 }
100 108
101 if (!workers_.count(syncer::GROUP_HISTORY)) { 109 if (!workers_.count(syncer::GROUP_HISTORY)) {
102 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) 110 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS))
103 << "History store disabled, cannot sync Omnibox History"; 111 << "History store disabled, cannot sync Omnibox History";
104 routing_info_.erase(syncer::TYPED_URLS); 112 routing_info_.erase(syncer::TYPED_URLS);
105 } 113 }
106 114
107 if (!workers_.count(syncer::GROUP_PASSWORD)) { 115 if (!workers_.count(syncer::GROUP_PASSWORD)) {
108 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) 116 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS))
(...skipping 29 matching lines...) Expand all
138 } 146 }
139 147
140 base::AutoLock lock(lock_); 148 base::AutoLock lock(lock_);
141 syncer::ModelTypeSet newly_added_types; 149 syncer::ModelTypeSet newly_added_types;
142 for (syncer::ModelTypeSet::Iterator it = 150 for (syncer::ModelTypeSet::Iterator it =
143 filtered_types_to_add.First(); 151 filtered_types_to_add.First();
144 it.Good(); it.Inc()) { 152 it.Good(); it.Inc()) {
145 // Add a newly specified data type as syncer::GROUP_PASSIVE into the 153 // Add a newly specified data type as syncer::GROUP_PASSIVE into the
146 // routing_info, if it does not already exist. 154 // routing_info, if it does not already exist.
147 if (routing_info_.count(it.Get()) == 0) { 155 if (routing_info_.count(it.Get()) == 0) {
148 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; 156 if (IsControlType(it.Get())) {
157 routing_info_[it.Get()] = syncer::GROUP_CONTROL;
158 } else {
159 routing_info_[it.Get()] = syncer::GROUP_PASSIVE;
160 }
149 newly_added_types.Put(it.Get()); 161 newly_added_types.Put(it.Get());
150 } 162 }
151 } 163 }
152 for (syncer::ModelTypeSet::Iterator it = types_to_remove.First(); 164 for (syncer::ModelTypeSet::Iterator it = types_to_remove.First();
153 it.Good(); it.Inc()) { 165 it.Good(); it.Inc()) {
154 routing_info_.erase(it.Get()); 166 routing_info_.erase(it.Get());
155 } 167 }
156 168
157 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. 169 // TODO(akalin): Use SVLOG/SLOG if we add any more logging.
158 DVLOG(1) << name_ << ": Adding types " 170 DVLOG(1) << name_ << ": Adding types "
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 return it->second; 303 return it->second;
292 } 304 }
293 305
294 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( 306 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel(
295 syncer::ModelType model_type) const { 307 syncer::ModelType model_type) const {
296 lock_.AssertAcquired(); 308 lock_.AssertAcquired();
297 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); 309 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_));
298 } 310 }
299 311
300 } // namespace browser_sync 312 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host_unittest.cc ('k') | chrome/browser/sync/glue/sync_backend_registrar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698