| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 event_handler, | 404 event_handler, |
| 405 sync_service_url, | 405 sync_service_url, |
| 406 base::Bind(&MakeHttpBridgeFactory, | 406 base::Bind(&MakeHttpBridgeFactory, |
| 407 make_scoped_refptr(profile_->GetRequestContext())), | 407 make_scoped_refptr(profile_->GetRequestContext())), |
| 408 credentials, | 408 credentials, |
| 409 chrome_sync_notification_bridge_.get(), | 409 chrome_sync_notification_bridge_.get(), |
| 410 &sync_notifier_factory_, | 410 &sync_notifier_factory_, |
| 411 sync_manager_factory, | 411 sync_manager_factory, |
| 412 delete_sync_data_folder, | 412 delete_sync_data_folder, |
| 413 sync_prefs_->GetEncryptionBootstrapToken(), | 413 sync_prefs_->GetEncryptionBootstrapToken(), |
| 414 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
| 414 new InternalComponentsFactoryImpl(), | 415 new InternalComponentsFactoryImpl(), |
| 415 unrecoverable_error_handler, | 416 unrecoverable_error_handler, |
| 416 report_unrecoverable_error_function)); | 417 report_unrecoverable_error_function)); |
| 417 } | 418 } |
| 418 | 419 |
| 419 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 420 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
| 420 sync_thread_.message_loop()->PostTask(FROM_HERE, | 421 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 421 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), | 422 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), |
| 422 credentials)); | 423 credentials)); |
| 423 } | 424 } |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 780 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
| 780 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 781 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 781 const GURL& service_url, | 782 const GURL& service_url, |
| 782 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 783 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
| 783 const syncer::SyncCredentials& credentials, | 784 const syncer::SyncCredentials& credentials, |
| 784 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, | 785 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, |
| 785 syncer::SyncNotifierFactory* sync_notifier_factory, | 786 syncer::SyncNotifierFactory* sync_notifier_factory, |
| 786 syncer::SyncManagerFactory* sync_manager_factory, | 787 syncer::SyncManagerFactory* sync_manager_factory, |
| 787 bool delete_sync_data_folder, | 788 bool delete_sync_data_folder, |
| 788 const std::string& restored_key_for_bootstrapping, | 789 const std::string& restored_key_for_bootstrapping, |
| 790 const std::string& restored_keystore_key_for_bootstrapping, |
| 789 InternalComponentsFactory* internal_components_factory, | 791 InternalComponentsFactory* internal_components_factory, |
| 790 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 792 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 791 syncer::ReportUnrecoverableErrorFunction | 793 syncer::ReportUnrecoverableErrorFunction |
| 792 report_unrecoverable_error_function) | 794 report_unrecoverable_error_function) |
| 793 : sync_loop(sync_loop), | 795 : sync_loop(sync_loop), |
| 794 registrar(registrar), | 796 registrar(registrar), |
| 795 routing_info(routing_info), | 797 routing_info(routing_info), |
| 796 workers(workers), | 798 workers(workers), |
| 797 extensions_activity_monitor(extensions_activity_monitor), | 799 extensions_activity_monitor(extensions_activity_monitor), |
| 798 event_handler(event_handler), | 800 event_handler(event_handler), |
| 799 service_url(service_url), | 801 service_url(service_url), |
| 800 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 802 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
| 801 credentials(credentials), | 803 credentials(credentials), |
| 802 chrome_sync_notification_bridge(chrome_sync_notification_bridge), | 804 chrome_sync_notification_bridge(chrome_sync_notification_bridge), |
| 803 sync_notifier_factory(sync_notifier_factory), | 805 sync_notifier_factory(sync_notifier_factory), |
| 804 sync_manager_factory(sync_manager_factory), | 806 sync_manager_factory(sync_manager_factory), |
| 805 delete_sync_data_folder(delete_sync_data_folder), | 807 delete_sync_data_folder(delete_sync_data_folder), |
| 806 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 808 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
| 809 restored_keystore_key_for_bootstrapping( |
| 810 restored_keystore_key_for_bootstrapping), |
| 807 internal_components_factory(internal_components_factory), | 811 internal_components_factory(internal_components_factory), |
| 808 unrecoverable_error_handler(unrecoverable_error_handler), | 812 unrecoverable_error_handler(unrecoverable_error_handler), |
| 809 report_unrecoverable_error_function( | 813 report_unrecoverable_error_function( |
| 810 report_unrecoverable_error_function) { | 814 report_unrecoverable_error_function) { |
| 811 } | 815 } |
| 812 | 816 |
| 813 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 817 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
| 814 | 818 |
| 815 SyncBackendHost::Core::Core(const std::string& name, | 819 SyncBackendHost::Core::Core(const std::string& name, |
| 816 const FilePath& sync_data_folder_path, | 820 const FilePath& sync_data_folder_path, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 827 SyncBackendHost::Core::~Core() { | 831 SyncBackendHost::Core::~Core() { |
| 828 DCHECK(!sync_manager_.get()); | 832 DCHECK(!sync_manager_.get()); |
| 829 DCHECK(!sync_loop_); | 833 DCHECK(!sync_loop_); |
| 830 } | 834 } |
| 831 | 835 |
| 832 void SyncBackendHost::Core::OnSyncCycleCompleted( | 836 void SyncBackendHost::Core::OnSyncCycleCompleted( |
| 833 const SyncSessionSnapshot& snapshot) { | 837 const SyncSessionSnapshot& snapshot) { |
| 834 if (!sync_loop_) | 838 if (!sync_loop_) |
| 835 return; | 839 return; |
| 836 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 840 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 841 |
| 842 if (snapshot.model_neutral_state().last_get_key_result == |
| 843 syncer::SYNCER_OK) { |
| 844 // If we just received a new keystore key, get it and make sure we update |
| 845 // the bootstrap token with it. |
| 846 std::string keystore_token; |
| 847 sync_manager_->GetKeystoreKeyBootstrapToken(&keystore_token); |
| 848 if (!keystore_token.empty()) { |
| 849 DVLOG(1) << "Persisting keystore encryption bootstrap token."; |
| 850 host_.Call(FROM_HERE, |
| 851 &SyncBackendHost::PersistEncryptionBootstrapToken, |
| 852 keystore_token, |
| 853 KEYSTORE_BOOTSTRAP_TOKEN); |
| 854 } else { |
| 855 NOTREACHED(); |
| 856 } |
| 857 } |
| 858 |
| 837 host_.Call( | 859 host_.Call( |
| 838 FROM_HERE, | 860 FROM_HERE, |
| 839 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, | 861 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, |
| 840 snapshot); | 862 snapshot); |
| 841 } | 863 } |
| 842 | 864 |
| 843 | 865 |
| 844 void SyncBackendHost::Core::OnInitializationComplete( | 866 void SyncBackendHost::Core::OnInitializationComplete( |
| 845 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 867 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 846 bool success, | 868 bool success, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 host_.Call( | 908 host_.Call( |
| 887 FROM_HERE, | 909 FROM_HERE, |
| 888 &SyncBackendHost::NotifyPassphraseAccepted); | 910 &SyncBackendHost::NotifyPassphraseAccepted); |
| 889 } | 911 } |
| 890 | 912 |
| 891 void SyncBackendHost::Core::OnBootstrapTokenUpdated( | 913 void SyncBackendHost::Core::OnBootstrapTokenUpdated( |
| 892 const std::string& bootstrap_token) { | 914 const std::string& bootstrap_token) { |
| 893 if (!sync_loop_) | 915 if (!sync_loop_) |
| 894 return; | 916 return; |
| 895 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 917 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 896 host_.Call( | 918 host_.Call(FROM_HERE, |
| 897 FROM_HERE, | 919 &SyncBackendHost::PersistEncryptionBootstrapToken, |
| 898 &SyncBackendHost::PersistEncryptionBootstrapToken, bootstrap_token); | 920 bootstrap_token, |
| 921 PASSPHRASE_BOOTSTRAP_TOKEN); |
| 899 } | 922 } |
| 900 | 923 |
| 901 void SyncBackendHost::Core::OnStopSyncingPermanently() { | 924 void SyncBackendHost::Core::OnStopSyncingPermanently() { |
| 902 if (!sync_loop_) | 925 if (!sync_loop_) |
| 903 return; | 926 return; |
| 904 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 927 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 905 host_.Call( | 928 host_.Call( |
| 906 FROM_HERE, | 929 FROM_HERE, |
| 907 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop); | 930 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop); |
| 908 } | 931 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 BrowserThread::GetBlockingPool(), | 1008 BrowserThread::GetBlockingPool(), |
| 986 options.make_http_bridge_factory_fn.Run().Pass(), | 1009 options.make_http_bridge_factory_fn.Run().Pass(), |
| 987 options.workers, | 1010 options.workers, |
| 988 options.extensions_activity_monitor, | 1011 options.extensions_activity_monitor, |
| 989 options.registrar /* as SyncManager::ChangeDelegate */, | 1012 options.registrar /* as SyncManager::ChangeDelegate */, |
| 990 options.credentials, | 1013 options.credentials, |
| 991 scoped_ptr<syncer::SyncNotifier>(new BridgedSyncNotifier( | 1014 scoped_ptr<syncer::SyncNotifier>(new BridgedSyncNotifier( |
| 992 options.chrome_sync_notification_bridge, | 1015 options.chrome_sync_notification_bridge, |
| 993 options.sync_notifier_factory->CreateSyncNotifier())), | 1016 options.sync_notifier_factory->CreateSyncNotifier())), |
| 994 options.restored_key_for_bootstrapping, | 1017 options.restored_key_for_bootstrapping, |
| 1018 options.restored_keystore_key_for_bootstrapping, |
| 995 CommandLine::ForCurrentProcess()->HasSwitch( | 1019 CommandLine::ForCurrentProcess()->HasSwitch( |
| 996 switches::kSyncKeystoreEncryption), | 1020 switches::kSyncKeystoreEncryption), |
| 997 scoped_ptr<InternalComponentsFactory>( | 1021 scoped_ptr<InternalComponentsFactory>( |
| 998 options.internal_components_factory), | 1022 options.internal_components_factory), |
| 999 &encryptor_, | 1023 &encryptor_, |
| 1000 options.unrecoverable_error_handler, | 1024 options.unrecoverable_error_handler, |
| 1001 options.report_unrecoverable_error_function); | 1025 options.report_unrecoverable_error_function); |
| 1002 LOG_IF(ERROR, !success) << "Syncapi initialization failed!"; | 1026 LOG_IF(ERROR, !success) << "Syncapi initialization failed!"; |
| 1003 | 1027 |
| 1004 // Now check the command line to see if we need to simulate an | 1028 // Now check the command line to see if we need to simulate an |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 frontend_->OnSyncCycleCompleted(); | 1278 frontend_->OnSyncCycleCompleted(); |
| 1255 } | 1279 } |
| 1256 | 1280 |
| 1257 void SyncBackendHost::RetryConfigurationOnFrontendLoop( | 1281 void SyncBackendHost::RetryConfigurationOnFrontendLoop( |
| 1258 const base::Closure& retry_callback) { | 1282 const base::Closure& retry_callback) { |
| 1259 SDVLOG(1) << "Failed to complete configuration, informing of retry."; | 1283 SDVLOG(1) << "Failed to complete configuration, informing of retry."; |
| 1260 retry_callback.Run(); | 1284 retry_callback.Run(); |
| 1261 } | 1285 } |
| 1262 | 1286 |
| 1263 void SyncBackendHost::PersistEncryptionBootstrapToken( | 1287 void SyncBackendHost::PersistEncryptionBootstrapToken( |
| 1264 const std::string& token) { | 1288 const std::string& token, |
| 1289 BootstrapTokenType token_type) { |
| 1265 CHECK(sync_prefs_.get()); | 1290 CHECK(sync_prefs_.get()); |
| 1266 sync_prefs_->SetEncryptionBootstrapToken(token); | 1291 DCHECK(!token.empty()); |
| 1292 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN) |
| 1293 sync_prefs_->SetEncryptionBootstrapToken(token); |
| 1294 else |
| 1295 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); |
| 1267 } | 1296 } |
| 1268 | 1297 |
| 1269 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( | 1298 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( |
| 1270 const syncer::SyncProtocolError& sync_error) { | 1299 const syncer::SyncProtocolError& sync_error) { |
| 1271 if (!frontend_) | 1300 if (!frontend_) |
| 1272 return; | 1301 return; |
| 1273 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1302 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1274 frontend_->OnActionableError(sync_error); | 1303 frontend_->OnActionableError(sync_error); |
| 1275 } | 1304 } |
| 1276 | 1305 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 FROM_HERE, | 1410 FROM_HERE, |
| 1382 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1411 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| 1383 core_.get(), sync_thread_done_callback)); | 1412 core_.get(), sync_thread_done_callback)); |
| 1384 } | 1413 } |
| 1385 | 1414 |
| 1386 #undef SDVLOG | 1415 #undef SDVLOG |
| 1387 | 1416 |
| 1388 #undef SLOG | 1417 #undef SLOG |
| 1389 | 1418 |
| 1390 } // namespace browser_sync | 1419 } // namespace browser_sync |
| OLD | NEW |