| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 prefs->ScheduleSavePersistentPrefs(); | 146 prefs->ScheduleSavePersistentPrefs(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 std::string SyncBackendHost::RestoreEncryptionBootstrapToken() { | 149 std::string SyncBackendHost::RestoreEncryptionBootstrapToken() { |
| 150 PrefService* prefs = profile_->GetPrefs(); | 150 PrefService* prefs = profile_->GetPrefs(); |
| 151 std::string token = prefs->GetString(prefs::kEncryptionBootstrapToken); | 151 std::string token = prefs->GetString(prefs::kEncryptionBootstrapToken); |
| 152 return token; | 152 return token; |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool SyncBackendHost::IsNigoriEnabled() const { | 155 bool SyncBackendHost::IsNigoriEnabled() const { |
| 156 AutoLock lock(registrar_lock_); | 156 base::AutoLock lock(registrar_lock_); |
| 157 // Note that NIGORI is only ever added/removed from routing_info once, | 157 // Note that NIGORI is only ever added/removed from routing_info once, |
| 158 // during initialization / first configuration, so there is no real 'race' | 158 // during initialization / first configuration, so there is no real 'race' |
| 159 // possible here or possibility of stale return value. | 159 // possible here or possibility of stale return value. |
| 160 return registrar_.routing_info.find(syncable::NIGORI) != | 160 return registrar_.routing_info.find(syncable::NIGORI) != |
| 161 registrar_.routing_info.end(); | 161 registrar_.routing_info.end(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool SyncBackendHost::IsUsingExplicitPassphrase() { | 164 bool SyncBackendHost::IsUsingExplicitPassphrase() { |
| 165 return IsNigoriEnabled() && syncapi_initialized_ && | 165 return IsNigoriEnabled() && syncapi_initialized_ && |
| 166 core_->syncapi()->InitialSyncEndedForAllEnabledTypes() && | 166 core_->syncapi()->InitialSyncEndedForAllEnabledTypes() && |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 DCHECK(!configure_ready_task_.get()); | 317 DCHECK(!configure_ready_task_.get()); |
| 318 DCHECK(syncapi_initialized_); | 318 DCHECK(syncapi_initialized_); |
| 319 | 319 |
| 320 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { | 320 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { |
| 321 ConfigureAutofillMigration(); | 321 ConfigureAutofillMigration(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 bool deleted_type = false; | 324 bool deleted_type = false; |
| 325 | 325 |
| 326 { | 326 { |
| 327 AutoLock lock(registrar_lock_); | 327 base::AutoLock lock(registrar_lock_); |
| 328 for (DataTypeController::TypeMap::const_iterator it = | 328 for (DataTypeController::TypeMap::const_iterator it = |
| 329 data_type_controllers_.begin(); | 329 data_type_controllers_.begin(); |
| 330 it != data_type_controllers_.end(); ++it) { | 330 it != data_type_controllers_.end(); ++it) { |
| 331 syncable::ModelType type = (*it).first; | 331 syncable::ModelType type = (*it).first; |
| 332 | 332 |
| 333 // If a type is not specified, remove it from the routing_info. | 333 // If a type is not specified, remove it from the routing_info. |
| 334 if (types.count(type) == 0) { | 334 if (types.count(type) == 0) { |
| 335 registrar_.routing_info.erase(type); | 335 registrar_.routing_info.erase(type); |
| 336 deleted_type = true; | 336 deleted_type = true; |
| 337 } else { | 337 } else { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 } | 375 } |
| 376 | 376 |
| 377 void SyncBackendHost::RequestNudge() { | 377 void SyncBackendHost::RequestNudge() { |
| 378 core_thread_.message_loop()->PostTask(FROM_HERE, | 378 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 379 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); | 379 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void SyncBackendHost::ActivateDataType( | 382 void SyncBackendHost::ActivateDataType( |
| 383 DataTypeController* data_type_controller, | 383 DataTypeController* data_type_controller, |
| 384 ChangeProcessor* change_processor) { | 384 ChangeProcessor* change_processor) { |
| 385 AutoLock lock(registrar_lock_); | 385 base::AutoLock lock(registrar_lock_); |
| 386 | 386 |
| 387 // Ensure that the given data type is in the PASSIVE group. | 387 // Ensure that the given data type is in the PASSIVE group. |
| 388 browser_sync::ModelSafeRoutingInfo::iterator i = | 388 browser_sync::ModelSafeRoutingInfo::iterator i = |
| 389 registrar_.routing_info.find(data_type_controller->type()); | 389 registrar_.routing_info.find(data_type_controller->type()); |
| 390 DCHECK(i != registrar_.routing_info.end()); | 390 DCHECK(i != registrar_.routing_info.end()); |
| 391 DCHECK((*i).second == GROUP_PASSIVE); | 391 DCHECK((*i).second == GROUP_PASSIVE); |
| 392 syncable::ModelType type = data_type_controller->type(); | 392 syncable::ModelType type = data_type_controller->type(); |
| 393 // Change the data type's routing info to its group. | 393 // Change the data type's routing info to its group. |
| 394 registrar_.routing_info[type] = data_type_controller->model_safe_group(); | 394 registrar_.routing_info[type] = data_type_controller->model_safe_group(); |
| 395 | 395 |
| 396 // Add the data type's change processor to the list of change | 396 // Add the data type's change processor to the list of change |
| 397 // processors so it can receive updates. | 397 // processors so it can receive updates. |
| 398 DCHECK_EQ(processors_.count(type), 0U); | 398 DCHECK_EQ(processors_.count(type), 0U); |
| 399 processors_[type] = change_processor; | 399 processors_[type] = change_processor; |
| 400 } | 400 } |
| 401 | 401 |
| 402 void SyncBackendHost::DeactivateDataType( | 402 void SyncBackendHost::DeactivateDataType( |
| 403 DataTypeController* data_type_controller, | 403 DataTypeController* data_type_controller, |
| 404 ChangeProcessor* change_processor) { | 404 ChangeProcessor* change_processor) { |
| 405 AutoLock lock(registrar_lock_); | 405 base::AutoLock lock(registrar_lock_); |
| 406 registrar_.routing_info.erase(data_type_controller->type()); | 406 registrar_.routing_info.erase(data_type_controller->type()); |
| 407 | 407 |
| 408 std::map<syncable::ModelType, ChangeProcessor*>::size_type erased = | 408 std::map<syncable::ModelType, ChangeProcessor*>::size_type erased = |
| 409 processors_.erase(data_type_controller->type()); | 409 processors_.erase(data_type_controller->type()); |
| 410 DCHECK_EQ(erased, 1U); | 410 DCHECK_EQ(erased, 1U); |
| 411 | 411 |
| 412 // TODO(sync): At this point we need to purge the data associated | 412 // TODO(sync): At this point we need to purge the data associated |
| 413 // with this data type from the sync db. | 413 // with this data type from the sync db. |
| 414 } | 414 } |
| 415 | 415 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 498 |
| 499 const GoogleServiceAuthError& SyncBackendHost::GetAuthError() const { | 499 const GoogleServiceAuthError& SyncBackendHost::GetAuthError() const { |
| 500 return last_auth_error_; | 500 return last_auth_error_; |
| 501 } | 501 } |
| 502 | 502 |
| 503 const SyncSessionSnapshot* SyncBackendHost::GetLastSessionSnapshot() const { | 503 const SyncSessionSnapshot* SyncBackendHost::GetLastSessionSnapshot() const { |
| 504 return last_snapshot_.get(); | 504 return last_snapshot_.get(); |
| 505 } | 505 } |
| 506 | 506 |
| 507 void SyncBackendHost::GetWorkers(std::vector<ModelSafeWorker*>* out) { | 507 void SyncBackendHost::GetWorkers(std::vector<ModelSafeWorker*>* out) { |
| 508 AutoLock lock(registrar_lock_); | 508 base::AutoLock lock(registrar_lock_); |
| 509 out->clear(); | 509 out->clear(); |
| 510 for (WorkerMap::const_iterator it = registrar_.workers.begin(); | 510 for (WorkerMap::const_iterator it = registrar_.workers.begin(); |
| 511 it != registrar_.workers.end(); ++it) { | 511 it != registrar_.workers.end(); ++it) { |
| 512 out->push_back((*it).second); | 512 out->push_back((*it).second); |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 | 515 |
| 516 void SyncBackendHost::GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 516 void SyncBackendHost::GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 517 AutoLock lock(registrar_lock_); | 517 base::AutoLock lock(registrar_lock_); |
| 518 ModelSafeRoutingInfo copy(registrar_.routing_info); | 518 ModelSafeRoutingInfo copy(registrar_.routing_info); |
| 519 out->swap(copy); | 519 out->swap(copy); |
| 520 } | 520 } |
| 521 | 521 |
| 522 bool SyncBackendHost::HasUnsyncedItems() const { | 522 bool SyncBackendHost::HasUnsyncedItems() const { |
| 523 DCHECK(syncapi_initialized_); | 523 DCHECK(syncapi_initialized_); |
| 524 return core_->syncapi()->HasUnsyncedItems(); | 524 return core_->syncapi()->HasUnsyncedItems(); |
| 525 } | 525 } |
| 526 | 526 |
| 527 SyncBackendHost::Core::Core(SyncBackendHost* backend) | 527 SyncBackendHost::Core::Core(SyncBackendHost* backend) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 753 |
| 754 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop() { | 754 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop() { |
| 755 if (!frontend_) | 755 if (!frontend_) |
| 756 return; | 756 return; |
| 757 syncapi_initialized_ = true; | 757 syncapi_initialized_ = true; |
| 758 frontend_->OnBackendInitialized(); | 758 frontend_->OnBackendInitialized(); |
| 759 } | 759 } |
| 760 | 760 |
| 761 bool SyncBackendHost::Core::IsCurrentThreadSafeForModel( | 761 bool SyncBackendHost::Core::IsCurrentThreadSafeForModel( |
| 762 syncable::ModelType model_type) { | 762 syncable::ModelType model_type) { |
| 763 AutoLock lock(host_->registrar_lock_); | 763 base::AutoLock lock(host_->registrar_lock_); |
| 764 | 764 |
| 765 browser_sync::ModelSafeRoutingInfo::const_iterator routing_it = | 765 browser_sync::ModelSafeRoutingInfo::const_iterator routing_it = |
| 766 host_->registrar_.routing_info.find(model_type); | 766 host_->registrar_.routing_info.find(model_type); |
| 767 if (routing_it == host_->registrar_.routing_info.end()) | 767 if (routing_it == host_->registrar_.routing_info.end()) |
| 768 return false; | 768 return false; |
| 769 browser_sync::ModelSafeGroup group = routing_it->second; | 769 browser_sync::ModelSafeGroup group = routing_it->second; |
| 770 WorkerMap::const_iterator worker_it = host_->registrar_.workers.find(group); | 770 WorkerMap::const_iterator worker_it = host_->registrar_.workers.find(group); |
| 771 if (worker_it == host_->registrar_.workers.end()) | 771 if (worker_it == host_->registrar_.workers.end()) |
| 772 return false; | 772 return false; |
| 773 ModelSafeWorker* worker = worker_it->second; | 773 ModelSafeWorker* worker = worker_it->second; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 } | 882 } |
| 883 | 883 |
| 884 void SyncBackendHost::Core::DeleteSyncDataFolder() { | 884 void SyncBackendHost::Core::DeleteSyncDataFolder() { |
| 885 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { | 885 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { |
| 886 if (!file_util::Delete(host_->sync_data_folder_path(), true)) | 886 if (!file_util::Delete(host_->sync_data_folder_path(), true)) |
| 887 LOG(DFATAL) << "Could not delete the Sync Data folder."; | 887 LOG(DFATAL) << "Could not delete the Sync Data folder."; |
| 888 } | 888 } |
| 889 } | 889 } |
| 890 | 890 |
| 891 } // namespace browser_sync | 891 } // namespace browser_sync |
| OLD | NEW |