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

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

Issue 10520010: Not for review: Support sync init with missing or corrupt store (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Documentation Created 8 years, 6 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 return true; 46 return true;
47 case MODEL_SAFE_GROUP_COUNT: 47 case MODEL_SAFE_GROUP_COUNT:
48 default: 48 default:
49 return false; 49 return false;
50 } 50 }
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 SyncBackendRegistrar::SyncBackendRegistrar( 55 SyncBackendRegistrar::SyncBackendRegistrar(
56 syncable::ModelTypeSet initial_types,
57 const std::string& name, Profile* profile, 56 const std::string& name, Profile* profile,
58 MessageLoop* sync_loop) : 57 MessageLoop* sync_loop) :
59 name_(name), 58 name_(name),
60 profile_(profile), 59 profile_(profile),
61 sync_loop_(sync_loop), 60 sync_loop_(sync_loop),
62 ui_worker_(new UIModelWorker()), 61 ui_worker_(new UIModelWorker()),
63 stopped_on_ui_thread_(false) { 62 stopped_on_ui_thread_(false) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 CHECK(profile_); 64 CHECK(profile_);
66 DCHECK(sync_loop_); 65 DCHECK(sync_loop_);
67 workers_[GROUP_DB] = new DatabaseModelWorker(); 66 workers_[GROUP_DB] = new DatabaseModelWorker();
68 workers_[GROUP_FILE] = new FileModelWorker(); 67 workers_[GROUP_FILE] = new FileModelWorker();
69 workers_[GROUP_UI] = ui_worker_; 68 workers_[GROUP_UI] = ui_worker_;
70 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_); 69 workers_[GROUP_PASSIVE] = new PassiveModelWorker(sync_loop_);
71 70
72 // Any datatypes that we want the syncer to pull down must be in the
73 // routing_info map. We set them to group passive, meaning that
74 // updates will be applied to sync, but not dispatched to the native
75 // models.
76 for (syncable::ModelTypeSet::Iterator it = initial_types.First();
77 it.Good(); it.Inc()) {
78 routing_info_[it.Get()] = GROUP_PASSIVE;
79 }
80
81 HistoryService* history_service = profile->GetHistoryService( 71 HistoryService* history_service = profile->GetHistoryService(
82 Profile::IMPLICIT_ACCESS); 72 Profile::IMPLICIT_ACCESS);
83 if (history_service) { 73 if (history_service) {
84 workers_[GROUP_HISTORY] = new HistoryModelWorker(history_service); 74 workers_[GROUP_HISTORY] = new HistoryModelWorker(history_service);
85 } else {
86 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS))
87 << "History store disabled, cannot sync Omnibox History";
88 routing_info_.erase(syncable::TYPED_URLS);
89 } 75 }
90 76
91 scoped_refptr<PasswordStore> password_store = 77 scoped_refptr<PasswordStore> password_store =
92 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); 78 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS);
93 if (password_store.get()) { 79 if (password_store.get()) {
94 workers_[GROUP_PASSWORD] = new PasswordModelWorker(password_store); 80 workers_[GROUP_PASSWORD] = new PasswordModelWorker(password_store);
95 } else {
96 LOG_IF(WARNING, initial_types.Has(syncable::PASSWORDS))
97 << "Password store not initialized, cannot sync passwords";
98 routing_info_.erase(syncable::PASSWORDS);
99 } 81 }
100 } 82 }
101 83
102 SyncBackendRegistrar::~SyncBackendRegistrar() { 84 SyncBackendRegistrar::~SyncBackendRegistrar() {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 DCHECK(stopped_on_ui_thread_); 86 DCHECK(stopped_on_ui_thread_);
105 } 87 }
106 88
89 void SyncBackendRegistrar::SetInitialTypes(
90 syncable::ModelTypeSet initial_types) {
91 // Set our initial state to reflect the current status of the sync directory.
rlarocque 2012/06/04 20:07:09 I could use a flag and some DCHECKs to ensure that
92 // This will ensure that our calculations in ConfigureDataTypes() will always
93 // return correct results.
94 for (syncable::ModelTypeSet::Iterator it = initial_types.First();
95 it.Good(); it.Inc()) {
96 routing_info_[it.Get()] = GROUP_PASSIVE;
97 }
98
99 if (!workers_.count(GROUP_HISTORY)) {
100 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS))
101 << "History store disabled, cannot sync Omnibox History";
102 routing_info_.erase(syncable::TYPED_URLS);
103 }
104
105 if (!workers_.count(GROUP_PASSWORD)) {
106 LOG_IF(WARNING, initial_types.Has(syncable::PASSWORDS))
107 << "Password store not initialized, cannot sync passwords";
108 routing_info_.erase(syncable::PASSWORDS);
109 }
110 }
111
107 bool SyncBackendRegistrar::IsNigoriEnabled() const { 112 bool SyncBackendRegistrar::IsNigoriEnabled() const {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 base::AutoLock lock(lock_); 114 base::AutoLock lock(lock_);
110 return routing_info_.find(syncable::NIGORI) != routing_info_.end(); 115 return routing_info_.find(syncable::NIGORI) != routing_info_.end();
111 } 116 }
112 117
113 syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( 118 syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes(
114 syncable::ModelTypeSet types_to_add, 119 syncable::ModelTypeSet types_to_add,
115 syncable::ModelTypeSet types_to_remove) { 120 syncable::ModelTypeSet types_to_remove) {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return it->second; 285 return it->second;
281 } 286 }
282 287
283 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( 288 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel(
284 syncable::ModelType model_type) const { 289 syncable::ModelType model_type) const {
285 lock_.AssertAcquired(); 290 lock_.AssertAcquired();
286 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); 291 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_));
287 } 292 }
288 293
289 } // namespace browser_sync 294 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698