| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 scoped_refptr<PasswordStore> password_store = | 80 scoped_refptr<PasswordStore> password_store = |
| 81 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); | 81 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); |
| 82 if (password_store.get()) { | 82 if (password_store.get()) { |
| 83 workers_[syncer::GROUP_PASSWORD] = | 83 workers_[syncer::GROUP_PASSWORD] = |
| 84 new PasswordModelWorker(password_store, this); | 84 new PasswordModelWorker(password_store, this); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 SyncBackendRegistrar::~SyncBackendRegistrar() { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 90 DCHECK(stopped_on_ui_thread_); |
| 91 } |
| 92 |
| 88 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) { | 93 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 90 base::AutoLock lock(lock_); | 95 base::AutoLock lock(lock_); |
| 91 | 96 |
| 92 // This function should be called only once, shortly after construction. The | 97 // This function should be called only once, shortly after construction. The |
| 93 // routing info at that point is expected to be emtpy. | 98 // routing info at that point is expected to be emtpy. |
| 94 DCHECK(routing_info_.empty()); | 99 DCHECK(routing_info_.empty()); |
| 95 | 100 |
| 96 // Set our initial state to reflect the current status of the sync directory. | 101 // Set our initial state to reflect the current status of the sync directory. |
| 97 // This will ensure that our calculations in ConfigureDataTypes() will always | 102 // This will ensure that our calculations in ConfigureDataTypes() will always |
| 98 // return correct results. | 103 // return correct results. |
| 99 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); | 104 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); |
| 100 it.Good(); it.Inc()) { | 105 it.Good(); it.Inc()) { |
| 101 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; | 106 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; |
| 102 } | 107 } |
| 103 | 108 |
| 104 if (!workers_.count(syncer::GROUP_HISTORY)) { | 109 if (!workers_.count(syncer::GROUP_HISTORY)) { |
| 105 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) | 110 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) |
| 106 << "History store disabled, cannot sync Omnibox History"; | 111 << "History store disabled, cannot sync Omnibox History"; |
| 107 routing_info_.erase(syncer::TYPED_URLS); | 112 routing_info_.erase(syncer::TYPED_URLS); |
| 108 } | 113 } |
| 109 | 114 |
| 110 if (!workers_.count(syncer::GROUP_PASSWORD)) { | 115 if (!workers_.count(syncer::GROUP_PASSWORD)) { |
| 111 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) | 116 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) |
| 112 << "Password store not initialized, cannot sync passwords"; | 117 << "Password store not initialized, cannot sync passwords"; |
| 113 routing_info_.erase(syncer::PASSWORDS); | 118 routing_info_.erase(syncer::PASSWORDS); |
| 114 } | 119 } |
| 115 } | |
| 116 | 120 |
| 117 SyncBackendRegistrar::~SyncBackendRegistrar() { | 121 last_configured_types_ = syncer::GetRoutingInfoTypes(routing_info_); |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 119 DCHECK(stopped_on_ui_thread_); | |
| 120 } | 122 } |
| 121 | 123 |
| 122 bool SyncBackendRegistrar::IsNigoriEnabled() const { | 124 bool SyncBackendRegistrar::IsNigoriEnabled() const { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 base::AutoLock lock(lock_); | 126 base::AutoLock lock(lock_); |
| 125 return routing_info_.find(syncer::NIGORI) != routing_info_.end(); | 127 return routing_info_.find(syncer::NIGORI) != routing_info_.end(); |
| 126 } | 128 } |
| 127 | 129 |
| 128 syncer::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( | 130 syncer::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( |
| 129 syncer::ModelTypeSet types_to_add, | 131 syncer::ModelTypeSet types_to_add, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 158 | 160 |
| 159 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. | 161 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. |
| 160 DVLOG(1) << name_ << ": Adding types " | 162 DVLOG(1) << name_ << ": Adding types " |
| 161 << syncer::ModelTypeSetToString(types_to_add) | 163 << syncer::ModelTypeSetToString(types_to_add) |
| 162 << " (with newly-added types " | 164 << " (with newly-added types " |
| 163 << syncer::ModelTypeSetToString(newly_added_types) | 165 << syncer::ModelTypeSetToString(newly_added_types) |
| 164 << ") and removing types " | 166 << ") and removing types " |
| 165 << syncer::ModelTypeSetToString(types_to_remove) | 167 << syncer::ModelTypeSetToString(types_to_remove) |
| 166 << " to get new routing info " | 168 << " to get new routing info " |
| 167 <<syncer::ModelSafeRoutingInfoToString(routing_info_); | 169 <<syncer::ModelSafeRoutingInfoToString(routing_info_); |
| 170 last_configured_types_ = syncer::GetRoutingInfoTypes(routing_info_); |
| 168 | 171 |
| 169 return newly_added_types; | 172 return newly_added_types; |
| 170 } | 173 } |
| 171 | 174 |
| 175 syncer::ModelTypeSet SyncBackendRegistrar::GetLastConfiguredTypes() const { |
| 176 return last_configured_types_; |
| 177 } |
| 178 |
| 172 void SyncBackendRegistrar::StopOnUIThread() { | 179 void SyncBackendRegistrar::StopOnUIThread() { |
| 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 174 DCHECK(!stopped_on_ui_thread_); | 181 DCHECK(!stopped_on_ui_thread_); |
| 175 ui_worker_->Stop(); | 182 ui_worker_->Stop(); |
| 176 stopped_on_ui_thread_ = true; | 183 stopped_on_ui_thread_ = true; |
| 177 } | 184 } |
| 178 | 185 |
| 179 void SyncBackendRegistrar::OnSyncerShutdownComplete() { | 186 void SyncBackendRegistrar::OnSyncerShutdownComplete() { |
| 180 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 187 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 181 ui_worker_->OnSyncerShutdownComplete(); | 188 ui_worker_->OnSyncerShutdownComplete(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 lock_.AssertAcquired(); | 302 lock_.AssertAcquired(); |
| 296 return IsOnThreadForGroup(model_type, | 303 return IsOnThreadForGroup(model_type, |
| 297 GetGroupForModelType(model_type, routing_info_)); | 304 GetGroupForModelType(model_type, routing_info_)); |
| 298 } | 305 } |
| 299 | 306 |
| 300 void SyncBackendRegistrar::OnWorkerLoopDestroyed(syncer::ModelSafeGroup group) { | 307 void SyncBackendRegistrar::OnWorkerLoopDestroyed(syncer::ModelSafeGroup group) { |
| 301 // Do nothing for now. | 308 // Do nothing for now. |
| 302 } | 309 } |
| 303 | 310 |
| 304 } // namespace browser_sync | 311 } // namespace browser_sync |
| OLD | NEW |