| 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/sync/glue/database_model_worker.h" | 23 #include "chrome/browser/sync/glue/database_model_worker.h" |
| 24 #include "chrome/browser/sync/glue/history_model_worker.h" | 24 #include "chrome/browser/sync/glue/history_model_worker.h" |
| 25 #include "chrome/browser/sync/glue/sync_backend_host.h" | 25 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 26 #include "chrome/browser/sync/glue/http_bridge.h" | 26 #include "chrome/browser/sync/glue/http_bridge.h" |
| 27 #include "chrome/browser/sync/glue/password_model_worker.h" | 27 #include "chrome/browser/sync/glue/password_model_worker.h" |
| 28 #include "chrome/browser/sync/js_arg_list.h" | 28 #include "chrome/browser/sync/js_arg_list.h" |
| 29 #include "chrome/browser/sync/sessions/session_state.h" | 29 #include "chrome/browser/sync/sessions/session_state.h" |
| 30 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. | 30 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. |
| 31 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. | 31 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. |
| 32 #include "chrome/browser/sync/syncable/model_type.h" | 32 #include "chrome/browser/sync/syncable/model_type.h" |
| 33 #include "chrome/browser/sync/syncable/nigori_util.h" |
| 33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/chrome_version_info.h" | 35 #include "chrome/common/chrome_version_info.h" |
| 35 #include "chrome/common/net/gaia/gaia_constants.h" | 36 #include "chrome/common/net/gaia/gaia_constants.h" |
| 36 #include "chrome/common/notification_service.h" | 37 #include "chrome/common/notification_service.h" |
| 37 #include "chrome/common/notification_type.h" | 38 #include "chrome/common/notification_type.h" |
| 38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 39 #include "webkit/glue/webkit_glue.h" | 40 #include "webkit/glue/webkit_glue.h" |
| 40 | 41 |
| 41 static const int kSaveChangesIntervalSeconds = 10; | 42 static const int kSaveChangesIntervalSeconds = 10; |
| 42 static const FilePath::CharType kSyncDataFolderName[] = | 43 static const FilePath::CharType kSyncDataFolderName[] = |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 it != types.end(); ++it) { | 119 it != types.end(); ++it) { |
| 119 registrar_.routing_info[(*it)] = GROUP_PASSIVE; | 120 registrar_.routing_info[(*it)] = GROUP_PASSIVE; |
| 120 } | 121 } |
| 121 | 122 |
| 122 PasswordStore* password_store = | 123 PasswordStore* password_store = |
| 123 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); | 124 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); |
| 124 if (password_store) { | 125 if (password_store) { |
| 125 registrar_.workers[GROUP_PASSWORD] = | 126 registrar_.workers[GROUP_PASSWORD] = |
| 126 new PasswordModelWorker(password_store); | 127 new PasswordModelWorker(password_store); |
| 127 } else { | 128 } else { |
| 128 LOG(WARNING) << "Password store not initialized, cannot sync passwords"; | 129 LOG_IF(WARNING, types.count(syncable::PASSWORDS) > 0) << "Password store " |
| 130 << "not initialized, cannot sync passwords"; |
| 129 registrar_.routing_info.erase(syncable::PASSWORDS); | 131 registrar_.routing_info.erase(syncable::PASSWORDS); |
| 130 } | 132 } |
| 131 | 133 |
| 132 // TODO(tim): Remove this special case once NIGORI is populated by | 134 // Nigori is populated by default now. |
| 133 // default. We piggy back off of the passwords flag for now to not | 135 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; |
| 134 // require both encryption and passwords flags. | |
| 135 bool enable_encryption = !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 136 switches::kDisableSyncPasswords) || types.count(syncable::PASSWORDS); | |
| 137 if (enable_encryption) | |
| 138 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; | |
| 139 | 136 |
| 140 InitCore(Core::DoInitializeOptions( | 137 InitCore(Core::DoInitializeOptions( |
| 141 sync_service_url, | 138 sync_service_url, |
| 142 MakeHttpBridgeFactory(baseline_context_getter), | 139 MakeHttpBridgeFactory(baseline_context_getter), |
| 143 credentials, | 140 credentials, |
| 144 delete_sync_data_folder, | 141 delete_sync_data_folder, |
| 145 notifier_options, | 142 notifier_options, |
| 146 RestoreEncryptionBootstrapToken(), | 143 RestoreEncryptionBootstrapToken(), |
| 147 false)); | 144 false)); |
| 148 } | 145 } |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // notice that the routing info has changed and start the process of | 388 // notice that the routing info has changed and start the process of |
| 392 // downloading updates for newly added data types. Once this is | 389 // downloading updates for newly added data types. Once this is |
| 393 // complete, the configure_ready_task_ is run via an | 390 // complete, the configure_ready_task_ is run via an |
| 394 // OnInitializationComplete notification. | 391 // OnInitializationComplete notification. |
| 395 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) | 392 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) |
| 396 // We can only nudge when we've either deleted a dataype or added one, else | 393 // We can only nudge when we've either deleted a dataype or added one, else |
| 397 // we break all the profile sync unit tests. | 394 // we break all the profile sync unit tests. |
| 398 RequestNudge(); | 395 RequestNudge(); |
| 399 } | 396 } |
| 400 | 397 |
| 398 void SyncBackendHost::EncryptDataTypes( |
| 399 const syncable::ModelTypeSet& encrypted_types) { |
| 400 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 401 NewRunnableMethod(core_.get(), |
| 402 &SyncBackendHost::Core::DoEncryptDataTypes, |
| 403 encrypted_types)); |
| 404 } |
| 405 |
| 401 void SyncBackendHost::RequestNudge() { | 406 void SyncBackendHost::RequestNudge() { |
| 402 core_thread_.message_loop()->PostTask(FROM_HERE, | 407 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 403 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); | 408 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); |
| 404 } | 409 } |
| 405 | 410 |
| 406 void SyncBackendHost::ActivateDataType( | 411 void SyncBackendHost::ActivateDataType( |
| 407 DataTypeController* data_type_controller, | 412 DataTypeController* data_type_controller, |
| 408 ChangeProcessor* change_processor) { | 413 ChangeProcessor* change_processor) { |
| 409 base::AutoLock lock(registrar_lock_); | 414 base::AutoLock lock(registrar_lock_); |
| 410 | 415 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 if (!host_) | 500 if (!host_) |
| 496 return; | 501 return; |
| 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 498 TokenAvailableDetails details(GaiaConstants::kSyncService, token); | 503 TokenAvailableDetails details(GaiaConstants::kSyncService, token); |
| 499 NotificationService::current()->Notify( | 504 NotificationService::current()->Notify( |
| 500 NotificationType::TOKEN_UPDATED, | 505 NotificationType::TOKEN_UPDATED, |
| 501 NotificationService::AllSources(), | 506 NotificationService::AllSources(), |
| 502 Details<const TokenAvailableDetails>(&details)); | 507 Details<const TokenAvailableDetails>(&details)); |
| 503 } | 508 } |
| 504 | 509 |
| 510 void SyncBackendHost::Core::NotifyEncryptionComplete( |
| 511 const syncable::ModelTypeSet& encrypted_types) { |
| 512 if (!host_) |
| 513 return; |
| 514 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); |
| 515 host_->frontend_->OnEncryptionComplete(encrypted_types); |
| 516 } |
| 517 |
| 505 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( | 518 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( |
| 506 const GURL& service_url, | 519 const GURL& service_url, |
| 507 sync_api::HttpPostProviderFactory* http_bridge_factory, | 520 sync_api::HttpPostProviderFactory* http_bridge_factory, |
| 508 const sync_api::SyncCredentials& credentials, | 521 const sync_api::SyncCredentials& credentials, |
| 509 bool delete_sync_data_folder, | 522 bool delete_sync_data_folder, |
| 510 const notifier::NotifierOptions& notifier_options, | 523 const notifier::NotifierOptions& notifier_options, |
| 511 std::string restored_key_for_bootstrapping, | 524 std::string restored_key_for_bootstrapping, |
| 512 bool setup_for_test_mode) | 525 bool setup_for_test_mode) |
| 513 : service_url(service_url), | 526 : service_url(service_url), |
| 514 http_bridge_factory(http_bridge_factory), | 527 http_bridge_factory(http_bridge_factory), |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 660 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 648 syncapi_->StartSyncing(); | 661 syncapi_->StartSyncing(); |
| 649 } | 662 } |
| 650 | 663 |
| 651 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, | 664 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, |
| 652 bool is_explicit) { | 665 bool is_explicit) { |
| 653 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 666 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 654 syncapi_->SetPassphrase(passphrase, is_explicit); | 667 syncapi_->SetPassphrase(passphrase, is_explicit); |
| 655 } | 668 } |
| 656 | 669 |
| 670 void SyncBackendHost::Core::DoEncryptDataTypes( |
| 671 const syncable::ModelTypeSet& encrypted_types) { |
| 672 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 673 syncapi_->EncryptDataTypes(encrypted_types); |
| 674 } |
| 675 |
| 657 UIModelWorker* SyncBackendHost::ui_worker() { | 676 UIModelWorker* SyncBackendHost::ui_worker() { |
| 658 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; | 677 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; |
| 659 if (w == NULL) | 678 if (w == NULL) |
| 660 return NULL; | 679 return NULL; |
| 661 if (w->GetModelSafeGroup() != GROUP_UI) | 680 if (w->GetModelSafeGroup() != GROUP_UI) |
| 662 NOTREACHED(); | 681 NOTREACHED(); |
| 663 return static_cast<UIModelWorker*>(w); | 682 return static_cast<UIModelWorker*>(w); |
| 664 } | 683 } |
| 665 | 684 |
| 666 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 685 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 void SyncBackendHost::Core::OnClearServerDataSucceeded() { | 885 void SyncBackendHost::Core::OnClearServerDataSucceeded() { |
| 867 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 886 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 868 &Core::HandleClearServerDataSucceededOnFrontendLoop)); | 887 &Core::HandleClearServerDataSucceededOnFrontendLoop)); |
| 869 } | 888 } |
| 870 | 889 |
| 871 void SyncBackendHost::Core::OnClearServerDataFailed() { | 890 void SyncBackendHost::Core::OnClearServerDataFailed() { |
| 872 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 891 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 873 &Core::HandleClearServerDataFailedOnFrontendLoop)); | 892 &Core::HandleClearServerDataFailedOnFrontendLoop)); |
| 874 } | 893 } |
| 875 | 894 |
| 895 void SyncBackendHost::Core::OnEncryptionComplete( |
| 896 const syncable::ModelTypeSet& encrypted_types) { |
| 897 host_->frontend_loop_->PostTask( |
| 898 FROM_HERE, |
| 899 NewRunnableMethod(this, &Core::NotifyEncryptionComplete, |
| 900 encrypted_types)); |
| 901 } |
| 902 |
| 876 void SyncBackendHost::Core::RouteJsEvent( | 903 void SyncBackendHost::Core::RouteJsEvent( |
| 877 const std::string& name, const JsArgList& args, | 904 const std::string& name, const JsArgList& args, |
| 878 const JsEventHandler* target) { | 905 const JsEventHandler* target) { |
| 879 host_->frontend_loop_->PostTask( | 906 host_->frontend_loop_->PostTask( |
| 880 FROM_HERE, NewRunnableMethod( | 907 FROM_HERE, NewRunnableMethod( |
| 881 this, &Core::RouteJsEventOnFrontendLoop, name, args, target)); | 908 this, &Core::RouteJsEventOnFrontendLoop, name, args, target)); |
| 882 } | 909 } |
| 883 | 910 |
| 884 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { | 911 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { |
| 885 if (!host_ || !host_->frontend_) | 912 if (!host_ || !host_->frontend_) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 } | 1039 } |
| 1013 | 1040 |
| 1014 void SyncBackendHost::Core::DoProcessMessage( | 1041 void SyncBackendHost::Core::DoProcessMessage( |
| 1015 const std::string& name, const JsArgList& args, | 1042 const std::string& name, const JsArgList& args, |
| 1016 const JsEventHandler* sender) { | 1043 const JsEventHandler* sender) { |
| 1017 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); | 1044 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); |
| 1018 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); | 1045 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); |
| 1019 } | 1046 } |
| 1020 | 1047 |
| 1021 } // namespace browser_sync | 1048 } // namespace browser_sync |
| OLD | NEW |