| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #if defined(BROWSER_SYNC) | 5 #if defined(BROWSER_SYNC) |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 SyncBackendHost::~SyncBackendHost() { | 39 SyncBackendHost::~SyncBackendHost() { |
| 40 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 40 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SyncBackendHost::Initialize(const GURL& sync_service_url, | 43 void SyncBackendHost::Initialize(const GURL& sync_service_url, |
| 44 URLRequestContext* baseline_context) { | 44 URLRequestContext* baseline_context) { |
| 45 if (!core_thread_.Start()) | 45 if (!core_thread_.Start()) |
| 46 return; | 46 return; |
| 47 bookmark_model_worker_ = new BookmarkModelWorker(frontend_loop_); | 47 bookmark_model_worker_ = new BookmarkModelWorker(frontend_loop_); |
| 48 core_.get()->SetBaseRequestContext(baseline_context); | 48 |
| 49 core_thread_.message_loop()->PostTask(FROM_HERE, | 49 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 50 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoInitialize, | 50 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoInitialize, |
| 51 sync_service_url, bookmark_model_worker_, true)); | 51 sync_service_url, bookmark_model_worker_, true, |
| 52 new HttpBridgeFactory(baseline_context), |
| 53 new HttpBridgeFactory(baseline_context))); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void SyncBackendHost::Authenticate(const std::string& username, | 56 void SyncBackendHost::Authenticate(const std::string& username, |
| 55 const std::string& password) { | 57 const std::string& password) { |
| 56 core_thread_.message_loop()->PostTask(FROM_HERE, | 58 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 57 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoAuthenticate, | 59 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoAuthenticate, |
| 58 username, password)); | 60 username, password)); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void SyncBackendHost::Shutdown(bool sync_disabled) { | 63 void SyncBackendHost::Shutdown(bool sync_disabled) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 122 } |
| 121 | 123 |
| 122 string16 SyncBackendHost::GetAuthenticatedUsername() const { | 124 string16 SyncBackendHost::GetAuthenticatedUsername() const { |
| 123 return UTF8ToUTF16(core_->syncapi()->GetAuthenticatedUsername()); | 125 return UTF8ToUTF16(core_->syncapi()->GetAuthenticatedUsername()); |
| 124 } | 126 } |
| 125 | 127 |
| 126 AuthErrorState SyncBackendHost::GetAuthErrorState() const { | 128 AuthErrorState SyncBackendHost::GetAuthErrorState() const { |
| 127 return last_auth_error_; | 129 return last_auth_error_; |
| 128 } | 130 } |
| 129 | 131 |
| 130 void SyncBackendHost::Core::SetBaseRequestContext( | |
| 131 URLRequestContext* request_context) { | |
| 132 DCHECK(base_request_context_ == NULL); | |
| 133 base_request_context_ = request_context; | |
| 134 // This ref is removed on the IO thread after the core thread is over. | |
| 135 base_request_context_->AddRef(); | |
| 136 } | |
| 137 | |
| 138 SyncBackendHost::Core::Core(SyncBackendHost* backend) | 132 SyncBackendHost::Core::Core(SyncBackendHost* backend) |
| 139 : host_(backend), | 133 : host_(backend), |
| 140 base_request_context_(NULL), | |
| 141 syncapi_(new sync_api::SyncManager()) { | 134 syncapi_(new sync_api::SyncManager()) { |
| 142 } | 135 } |
| 143 | 136 |
| 144 SyncBackendHost::Core::~Core() { | |
| 145 if (base_request_context_) { | |
| 146 ChromeThread::GetMessageLoop(ChromeThread::IO)->ReleaseSoon(FROM_HERE, | |
| 147 base_request_context_); | |
| 148 base_request_context_ = NULL; | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 // Helper to construct a user agent string (ASCII) suitable for use by | 137 // Helper to construct a user agent string (ASCII) suitable for use by |
| 153 // the syncapi for any HTTP communication. This string is used by the sync | 138 // the syncapi for any HTTP communication. This string is used by the sync |
| 154 // backend for classifying client types when calculating statistics. | 139 // backend for classifying client types when calculating statistics. |
| 155 std::string MakeUserAgentForSyncapi() { | 140 std::string MakeUserAgentForSyncapi() { |
| 156 std::string user_agent; | 141 std::string user_agent; |
| 157 user_agent = "Chrome "; | 142 user_agent = "Chrome "; |
| 158 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
| 159 user_agent += "WIN "; | 144 user_agent += "WIN "; |
| 160 #elif defined(OS_LINUX) | 145 #elif defined(OS_LINUX) |
| 161 user_agent += "LINUX "; | 146 user_agent += "LINUX "; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 user_agent += WideToASCII(version_info->product_version()); | 157 user_agent += WideToASCII(version_info->product_version()); |
| 173 user_agent += " (" + WideToASCII(version_info->last_change()) + ")"; | 158 user_agent += " (" + WideToASCII(version_info->last_change()) + ")"; |
| 174 if (!version_info->is_official_build()) | 159 if (!version_info->is_official_build()) |
| 175 user_agent += "-devel"; | 160 user_agent += "-devel"; |
| 176 return user_agent; | 161 return user_agent; |
| 177 } | 162 } |
| 178 | 163 |
| 179 void SyncBackendHost::Core::DoInitialize( | 164 void SyncBackendHost::Core::DoInitialize( |
| 180 const GURL& service_url, | 165 const GURL& service_url, |
| 181 BookmarkModelWorker* bookmark_model_worker, | 166 BookmarkModelWorker* bookmark_model_worker, |
| 182 bool attempt_last_user_authentication) { | 167 bool attempt_last_user_authentication, |
| 168 sync_api::HttpPostProviderFactory* http_provider_factory, |
| 169 sync_api::HttpPostProviderFactory* auth_http_provider_factory) { |
| 183 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 170 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 184 | 171 |
| 185 // Make sure that the directory exists before initializing the backend. | 172 // Make sure that the directory exists before initializing the backend. |
| 186 // If it already exists, this will do no harm. | 173 // If it already exists, this will do no harm. |
| 187 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); | 174 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); |
| 188 DCHECK(success); | 175 DCHECK(success); |
| 189 | 176 |
| 190 syncapi_->SetObserver(this); | 177 syncapi_->SetObserver(this); |
| 191 string16 path_str; | 178 string16 path_str; |
| 192 #if defined (OS_WIN) | 179 #if defined (OS_WIN) |
| 193 path_str = host_->sync_data_folder_path().value(); | 180 path_str = host_->sync_data_folder_path().value(); |
| 194 #elif defined(OS_LINUX) || defined(OS_MACOSX) | 181 #elif defined(OS_LINUX) || defined(OS_MACOSX) |
| 195 path_str = UTF8ToUTF16(host_->sync_data_folder_path().value()); | 182 path_str = UTF8ToUTF16(host_->sync_data_folder_path().value()); |
| 196 #endif | 183 #endif |
| 197 success = syncapi_->Init(path_str.c_str(), | 184 success = syncapi_->Init(path_str.c_str(), |
| 198 (service_url.host() + service_url.path()).c_str(), | 185 (service_url.host() + service_url.path()).c_str(), |
| 199 service_url.EffectiveIntPort(), | 186 service_url.EffectiveIntPort(), |
| 200 kGaiaServiceId, | 187 kGaiaServiceId, |
| 201 kGaiaSourceForChrome, | 188 kGaiaSourceForChrome, |
| 202 service_url.SchemeIsSecure(), | 189 service_url.SchemeIsSecure(), |
| 203 new HttpBridgeFactory(base_request_context_), | 190 http_provider_factory, |
| 204 new HttpBridgeFactory(base_request_context_), | 191 auth_http_provider_factory, |
| 205 bookmark_model_worker, | 192 bookmark_model_worker, |
| 206 attempt_last_user_authentication, | 193 attempt_last_user_authentication, |
| 207 MakeUserAgentForSyncapi().c_str()); | 194 MakeUserAgentForSyncapi().c_str()); |
| 208 DCHECK(success) << "Syncapi initialization failed!"; | 195 DCHECK(success) << "Syncapi initialization failed!"; |
| 209 } | 196 } |
| 210 | 197 |
| 211 void SyncBackendHost::Core::DoAuthenticate(const std::string& username, | 198 void SyncBackendHost::Core::DoAuthenticate(const std::string& username, |
| 212 const std::string& password) { | 199 const std::string& password) { |
| 213 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 200 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 214 syncapi_->Authenticate(username.c_str(), password.c_str()); | 201 syncapi_->Authenticate(username.c_str(), password.c_str()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 this, &Core::SaveChanges); | 307 this, &Core::SaveChanges); |
| 321 } | 308 } |
| 322 | 309 |
| 323 void SyncBackendHost::Core::SaveChanges() { | 310 void SyncBackendHost::Core::SaveChanges() { |
| 324 syncapi_->SaveChanges(); | 311 syncapi_->SaveChanges(); |
| 325 } | 312 } |
| 326 | 313 |
| 327 } // namespace browser_sync | 314 } // namespace browser_sync |
| 328 | 315 |
| 329 #endif // defined(BROWSER_SYNC) | 316 #endif // defined(BROWSER_SYNC) |
| OLD | NEW |