| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 78 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| 79 DCHECK(registrar_.workers.empty()); | 79 DCHECK(registrar_.workers.empty()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void SyncBackendHost::Initialize( | 82 void SyncBackendHost::Initialize( |
| 83 SyncFrontend* frontend, | 83 SyncFrontend* frontend, |
| 84 const GURL& sync_service_url, | 84 const GURL& sync_service_url, |
| 85 const syncable::ModelTypeSet& types, | 85 const syncable::ModelTypeSet& types, |
| 86 URLRequestContextGetter* baseline_context_getter, | 86 URLRequestContextGetter* baseline_context_getter, |
| 87 const SyncCredentials& credentials, | 87 const SyncCredentials& credentials, |
| 88 bool delete_sync_data_folder, | 88 bool delete_sync_data_folder) { |
| 89 const notifier::NotifierOptions& notifier_options) { | |
| 90 if (!core_thread_.Start()) | 89 if (!core_thread_.Start()) |
| 91 return; | 90 return; |
| 92 | 91 |
| 93 frontend_ = frontend; | 92 frontend_ = frontend; |
| 94 DCHECK(frontend); | 93 DCHECK(frontend); |
| 95 | 94 |
| 96 // Create a worker for the UI thread and route bookmark changes to it. | 95 // Create a worker for the UI thread and route bookmark changes to it. |
| 97 // TODO(tim): Pull this into a method to reuse. For now we don't even | 96 // TODO(tim): Pull this into a method to reuse. For now we don't even |
| 98 // need to lock because we init before the syncapi exists and we tear down | 97 // need to lock because we init before the syncapi exists and we tear down |
| 99 // after the syncapi is destroyed. Make sure to NULL-check workers_ indices | 98 // after the syncapi is destroyed. Make sure to NULL-check workers_ indices |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 131 } |
| 133 | 132 |
| 134 // Nigori is populated by default now. | 133 // Nigori is populated by default now. |
| 135 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; | 134 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; |
| 136 | 135 |
| 137 InitCore(Core::DoInitializeOptions( | 136 InitCore(Core::DoInitializeOptions( |
| 138 sync_service_url, | 137 sync_service_url, |
| 139 MakeHttpBridgeFactory(baseline_context_getter), | 138 MakeHttpBridgeFactory(baseline_context_getter), |
| 140 credentials, | 139 credentials, |
| 141 delete_sync_data_folder, | 140 delete_sync_data_folder, |
| 142 notifier_options, | |
| 143 RestoreEncryptionBootstrapToken(), | 141 RestoreEncryptionBootstrapToken(), |
| 144 false)); | 142 false)); |
| 145 } | 143 } |
| 146 | 144 |
| 147 void SyncBackendHost::PersistEncryptionBootstrapToken( | 145 void SyncBackendHost::PersistEncryptionBootstrapToken( |
| 148 const std::string& token) { | 146 const std::string& token) { |
| 149 PrefService* prefs = profile_->GetPrefs(); | 147 PrefService* prefs = profile_->GetPrefs(); |
| 150 | 148 |
| 151 prefs->SetString(prefs::kEncryptionBootstrapToken, token); | 149 prefs->SetString(prefs::kEncryptionBootstrapToken, token); |
| 152 prefs->ScheduleSavePersistentPrefs(); | 150 prefs->ScheduleSavePersistentPrefs(); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 return; | 547 return; |
| 550 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); | 548 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); |
| 551 host_->frontend_->OnEncryptionComplete(encrypted_types); | 549 host_->frontend_->OnEncryptionComplete(encrypted_types); |
| 552 } | 550 } |
| 553 | 551 |
| 554 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( | 552 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( |
| 555 const GURL& service_url, | 553 const GURL& service_url, |
| 556 sync_api::HttpPostProviderFactory* http_bridge_factory, | 554 sync_api::HttpPostProviderFactory* http_bridge_factory, |
| 557 const sync_api::SyncCredentials& credentials, | 555 const sync_api::SyncCredentials& credentials, |
| 558 bool delete_sync_data_folder, | 556 bool delete_sync_data_folder, |
| 559 const notifier::NotifierOptions& notifier_options, | |
| 560 std::string restored_key_for_bootstrapping, | 557 std::string restored_key_for_bootstrapping, |
| 561 bool setup_for_test_mode) | 558 bool setup_for_test_mode) |
| 562 : service_url(service_url), | 559 : service_url(service_url), |
| 563 http_bridge_factory(http_bridge_factory), | 560 http_bridge_factory(http_bridge_factory), |
| 564 credentials(credentials), | 561 credentials(credentials), |
| 565 delete_sync_data_folder(delete_sync_data_folder), | 562 delete_sync_data_folder(delete_sync_data_folder), |
| 566 notifier_options(notifier_options), | |
| 567 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 563 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
| 568 setup_for_test_mode(setup_for_test_mode) { | 564 setup_for_test_mode(setup_for_test_mode) { |
| 569 } | 565 } |
| 570 | 566 |
| 571 SyncBackendHost::Core::DoInitializeOptions::~DoInitializeOptions() {} | 567 SyncBackendHost::Core::DoInitializeOptions::~DoInitializeOptions() {} |
| 572 | 568 |
| 573 sync_api::UserShare* SyncBackendHost::GetUserShare() const { | 569 sync_api::UserShare* SyncBackendHost::GetUserShare() const { |
| 574 DCHECK(syncapi_initialized_); | 570 DCHECK(syncapi_initialized_); |
| 575 return core_->syncapi()->GetUserShare(); | 571 return core_->syncapi()->GetUserShare(); |
| 576 } | 572 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 const FilePath& path_str = host_->sync_data_folder_path(); | 670 const FilePath& path_str = host_->sync_data_folder_path(); |
| 675 success = syncapi_->Init( | 671 success = syncapi_->Init( |
| 676 path_str, | 672 path_str, |
| 677 (options.service_url.host() + options.service_url.path()).c_str(), | 673 (options.service_url.host() + options.service_url.path()).c_str(), |
| 678 options.service_url.EffectiveIntPort(), | 674 options.service_url.EffectiveIntPort(), |
| 679 options.service_url.SchemeIsSecure(), | 675 options.service_url.SchemeIsSecure(), |
| 680 options.http_bridge_factory, | 676 options.http_bridge_factory, |
| 681 host_, // ModelSafeWorkerRegistrar. | 677 host_, // ModelSafeWorkerRegistrar. |
| 682 MakeUserAgentForSyncapi().c_str(), | 678 MakeUserAgentForSyncapi().c_str(), |
| 683 options.credentials, | 679 options.credentials, |
| 684 options.notifier_options, | |
| 685 options.restored_key_for_bootstrapping, | 680 options.restored_key_for_bootstrapping, |
| 686 options.setup_for_test_mode); | 681 options.setup_for_test_mode); |
| 687 DCHECK(success) << "Syncapi initialization failed!"; | 682 DCHECK(success) << "Syncapi initialization failed!"; |
| 688 } | 683 } |
| 689 | 684 |
| 690 void SyncBackendHost::Core::DoUpdateCredentials( | 685 void SyncBackendHost::Core::DoUpdateCredentials( |
| 691 const SyncCredentials& credentials) { | 686 const SyncCredentials& credentials) { |
| 692 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 687 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 693 syncapi_->UpdateCredentials(credentials); | 688 syncapi_->UpdateCredentials(credentials); |
| 694 } | 689 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 } | 1092 } |
| 1098 | 1093 |
| 1099 void SyncBackendHost::Core::DoProcessMessage( | 1094 void SyncBackendHost::Core::DoProcessMessage( |
| 1100 const std::string& name, const JsArgList& args, | 1095 const std::string& name, const JsArgList& args, |
| 1101 const JsEventHandler* sender) { | 1096 const JsEventHandler* sender) { |
| 1102 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); | 1097 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); |
| 1103 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); | 1098 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); |
| 1104 } | 1099 } |
| 1105 | 1100 |
| 1106 } // namespace browser_sync | 1101 } // namespace browser_sync |
| OLD | NEW |