OLD | NEW |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return true; | 47 return true; |
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 syncer::ModelTypeSet initial_types, | |
58 const std::string& name, Profile* profile, | 57 const std::string& name, Profile* profile, |
59 MessageLoop* sync_loop) : | 58 MessageLoop* sync_loop) : |
60 name_(name), | 59 name_(name), |
61 profile_(profile), | 60 profile_(profile), |
62 sync_loop_(sync_loop), | 61 sync_loop_(sync_loop), |
63 ui_worker_(new UIModelWorker()), | 62 ui_worker_(new UIModelWorker()), |
64 stopped_on_ui_thread_(false) { | 63 stopped_on_ui_thread_(false) { |
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
66 CHECK(profile_); | 65 CHECK(profile_); |
67 DCHECK(sync_loop_); | 66 DCHECK(sync_loop_); |
68 workers_[syncer::GROUP_DB] = new DatabaseModelWorker(); | 67 workers_[syncer::GROUP_DB] = new DatabaseModelWorker(); |
69 workers_[syncer::GROUP_FILE] = new FileModelWorker(); | 68 workers_[syncer::GROUP_FILE] = new FileModelWorker(); |
70 workers_[syncer::GROUP_UI] = ui_worker_; | 69 workers_[syncer::GROUP_UI] = ui_worker_; |
71 workers_[syncer::GROUP_PASSIVE] = new syncer::PassiveModelWorker(sync_loop_); | 70 workers_[syncer::GROUP_PASSIVE] = new syncer::PassiveModelWorker(sync_loop_); |
72 | 71 |
73 // Any datatypes that we want the syncer to pull down must be in the | |
74 // routing_info map. We set them to group passive, meaning that | |
75 // updates will be applied to sync, but not dispatched to the native | |
76 // models. | |
77 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); | |
78 it.Good(); it.Inc()) { | |
79 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; | |
80 } | |
81 | |
82 HistoryService* history_service = | 72 HistoryService* history_service = |
83 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); | 73 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); |
84 if (history_service) { | 74 if (history_service) { |
85 workers_[syncer::GROUP_HISTORY] = new HistoryModelWorker(history_service); | 75 workers_[syncer::GROUP_HISTORY] = new HistoryModelWorker(history_service); |
86 } else { | |
87 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) | |
88 << "History store disabled, cannot sync Omnibox History"; | |
89 routing_info_.erase(syncer::TYPED_URLS); | |
90 } | 76 } |
91 | 77 |
92 scoped_refptr<PasswordStore> password_store = | 78 scoped_refptr<PasswordStore> password_store = |
93 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); | 79 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); |
94 if (password_store.get()) { | 80 if (password_store.get()) { |
95 workers_[syncer::GROUP_PASSWORD] = new PasswordModelWorker(password_store); | 81 workers_[syncer::GROUP_PASSWORD] = new PasswordModelWorker(password_store); |
96 } else { | 82 } |
| 83 } |
| 84 |
| 85 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) { |
| 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 87 base::AutoLock lock(lock_); |
| 88 |
| 89 // This function should be called only once, shortly after construction. The |
| 90 // routing info at that point is expected to be emtpy. |
| 91 DCHECK(routing_info_.empty()); |
| 92 |
| 93 // Set our initial state to reflect the current status of the sync directory. |
| 94 // This will ensure that our calculations in ConfigureDataTypes() will always |
| 95 // return correct results. |
| 96 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); |
| 97 it.Good(); it.Inc()) { |
| 98 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; |
| 99 } |
| 100 |
| 101 if (!workers_.count(syncer::GROUP_HISTORY)) { |
| 102 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) |
| 103 << "History store disabled, cannot sync Omnibox History"; |
| 104 routing_info_.erase(syncer::TYPED_URLS); |
| 105 } |
| 106 |
| 107 if (!workers_.count(syncer::GROUP_PASSWORD)) { |
97 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) | 108 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) |
98 << "Password store not initialized, cannot sync passwords"; | 109 << "Password store not initialized, cannot sync passwords"; |
99 routing_info_.erase(syncer::PASSWORDS); | 110 routing_info_.erase(syncer::PASSWORDS); |
100 } | 111 } |
101 } | 112 } |
102 | 113 |
103 SyncBackendRegistrar::~SyncBackendRegistrar() { | 114 SyncBackendRegistrar::~SyncBackendRegistrar() { |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
105 DCHECK(stopped_on_ui_thread_); | 116 DCHECK(stopped_on_ui_thread_); |
106 } | 117 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 return it->second; | 291 return it->second; |
281 } | 292 } |
282 | 293 |
283 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 294 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
284 syncer::ModelType model_type) const { | 295 syncer::ModelType model_type) const { |
285 lock_.AssertAcquired(); | 296 lock_.AssertAcquired(); |
286 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); | 297 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); |
287 } | 298 } |
288 | 299 |
289 } // namespace browser_sync | 300 } // namespace browser_sync |
OLD | NEW |