| 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 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/lock.h" | 14 #include "base/lock.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
| 17 #include "base/thread.h" | 17 #include "base/thread.h" |
| 18 #include "base/timer.h" | 18 #include "base/timer.h" |
| 19 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/sync/notification_method.h" | 20 #include "chrome/browser/sync/notification_method.h" |
| 20 #include "chrome/browser/sync/engine/syncapi.h" | 21 #include "chrome/browser/sync/engine/syncapi.h" |
| 21 #include "chrome/browser/sync/engine/model_safe_worker.h" | 22 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 22 #include "chrome/browser/sync/glue/data_type_controller.h" | 23 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 23 #include "chrome/browser/sync/glue/ui_model_worker.h" | 24 #include "chrome/browser/sync/glue/ui_model_worker.h" |
| 24 #include "chrome/browser/sync/syncable/model_type.h" | 25 #include "chrome/browser/sync/syncable/model_type.h" |
| 25 #include "chrome/common/net/gaia/google_service_auth_error.h" | 26 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 26 #include "chrome/common/net/url_request_context_getter.h" | 27 #include "chrome/common/net/url_request_context_getter.h" |
| 27 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
| 28 | 29 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 SyncBackendHost(); | 95 SyncBackendHost(); |
| 95 ~SyncBackendHost(); | 96 ~SyncBackendHost(); |
| 96 | 97 |
| 97 // Called on |frontend_loop_| to kick off asynchronous initialization. | 98 // Called on |frontend_loop_| to kick off asynchronous initialization. |
| 98 // As a fallback when no cached auth information is available, try to | 99 // As a fallback when no cached auth information is available, try to |
| 99 // bootstrap authentication using |lsid|, if it isn't empty. | 100 // bootstrap authentication using |lsid|, if it isn't empty. |
| 100 // Optionally delete the Sync Data folder (if it's corrupt). | 101 // Optionally delete the Sync Data folder (if it's corrupt). |
| 101 void Initialize(const GURL& service_url, | 102 void Initialize(const GURL& service_url, |
| 102 const syncable::ModelTypeSet& types, | 103 const syncable::ModelTypeSet& types, |
| 103 URLRequestContextGetter* baseline_context_getter, | 104 URLRequestContextGetter* baseline_context_getter, |
| 104 const std::string& lsid, | 105 const sync_api::SyncCredentials& credentials, |
| 105 bool delete_sync_data_folder, | 106 bool delete_sync_data_folder, |
| 106 bool invalidate_sync_login, | |
| 107 bool invalidate_sync_xmpp_login, | |
| 108 bool use_chrome_async_socket, | 107 bool use_chrome_async_socket, |
| 109 bool try_ssltcp_first, | 108 bool try_ssltcp_first, |
| 110 NotificationMethod notification_method); | 109 NotificationMethod notification_method); |
| 111 | 110 |
| 112 // Called on |frontend_loop_| to kick off asynchronous authentication. | 111 // Called from |frontend_loop| to update SyncCredentials. |
| 113 void Authenticate(const std::string& username, const std::string& password, | 112 void UpdateCredentials(const sync_api::SyncCredentials& credentials); |
| 114 const std::string& captcha); | |
| 115 | 113 |
| 116 // This starts the SyncerThread running a Syncer object to communicate with | 114 // This starts the SyncerThread running a Syncer object to communicate with |
| 117 // sync servers. Until this is called, no changes will leave or enter this | 115 // sync servers. Until this is called, no changes will leave or enter this |
| 118 // browser from the cloud / sync servers. | 116 // browser from the cloud / sync servers. |
| 119 // Called on |frontend_loop_|. | 117 // Called on |frontend_loop_|. |
| 120 virtual void StartSyncingWithServer(); | 118 virtual void StartSyncingWithServer(); |
| 121 | 119 |
| 122 // Called on |frontend_loop_| to asynchronously set the passphrase. | 120 // Called on |frontend_loop_| to asynchronously set the passphrase. |
| 123 void SetPassphrase(const std::string& passphrase); | 121 void SetPassphrase(const std::string& passphrase); |
| 124 | 122 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 int change_count); | 199 int change_count); |
| 202 virtual void OnSyncCycleCompleted( | 200 virtual void OnSyncCycleCompleted( |
| 203 const sessions::SyncSessionSnapshot* snapshot); | 201 const sessions::SyncSessionSnapshot* snapshot); |
| 204 virtual void OnInitializationComplete(); | 202 virtual void OnInitializationComplete(); |
| 205 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); | 203 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); |
| 206 virtual void OnPassphraseRequired(); | 204 virtual void OnPassphraseRequired(); |
| 207 virtual void OnPassphraseAccepted(const std::string& bootstrap_token); | 205 virtual void OnPassphraseAccepted(const std::string& bootstrap_token); |
| 208 virtual void OnPaused(); | 206 virtual void OnPaused(); |
| 209 virtual void OnResumed(); | 207 virtual void OnResumed(); |
| 210 virtual void OnStopSyncingPermanently(); | 208 virtual void OnStopSyncingPermanently(); |
| 209 virtual void OnUpdatedToken(const std::string& token); |
| 211 | 210 |
| 212 struct DoInitializeOptions { | 211 struct DoInitializeOptions { |
| 213 DoInitializeOptions( | 212 DoInitializeOptions( |
| 214 const GURL& service_url, | 213 const GURL& service_url, |
| 215 bool attempt_last_user_authentication, | |
| 216 sync_api::HttpPostProviderFactory* http_bridge_factory, | 214 sync_api::HttpPostProviderFactory* http_bridge_factory, |
| 217 sync_api::HttpPostProviderFactory* auth_http_bridge_factory, | 215 const sync_api::SyncCredentials& credentials, |
| 218 const std::string& lsid, | |
| 219 bool delete_sync_data_folder, | 216 bool delete_sync_data_folder, |
| 220 bool invalidate_sync_login, | |
| 221 bool invalidate_sync_xmpp_login, | |
| 222 bool use_chrome_async_socket, | 217 bool use_chrome_async_socket, |
| 223 bool try_ssltcp_first, | 218 bool try_ssltcp_first, |
| 224 NotificationMethod notification_method, | 219 NotificationMethod notification_method, |
| 225 std::string restored_key_for_bootstrapping) | 220 std::string restored_key_for_bootstrapping) |
| 226 : service_url(service_url), | 221 : service_url(service_url), |
| 227 attempt_last_user_authentication(attempt_last_user_authentication), | |
| 228 http_bridge_factory(http_bridge_factory), | 222 http_bridge_factory(http_bridge_factory), |
| 229 auth_http_bridge_factory(auth_http_bridge_factory), | 223 credentials(credentials), |
| 230 lsid(lsid), | |
| 231 delete_sync_data_folder(delete_sync_data_folder), | 224 delete_sync_data_folder(delete_sync_data_folder), |
| 232 invalidate_sync_login(invalidate_sync_login), | |
| 233 invalidate_sync_xmpp_login(invalidate_sync_xmpp_login), | |
| 234 use_chrome_async_socket(use_chrome_async_socket), | 225 use_chrome_async_socket(use_chrome_async_socket), |
| 235 try_ssltcp_first(try_ssltcp_first), | 226 try_ssltcp_first(try_ssltcp_first), |
| 236 notification_method(notification_method), | 227 notification_method(notification_method), |
| 237 restored_key_for_bootstrapping(restored_key_for_bootstrapping) {} | 228 restored_key_for_bootstrapping(restored_key_for_bootstrapping) {} |
| 238 | 229 |
| 239 GURL service_url; | 230 GURL service_url; |
| 240 bool attempt_last_user_authentication; | 231 bool attempt_last_user_authentication; |
| 241 sync_api::HttpPostProviderFactory* http_bridge_factory; | 232 sync_api::HttpPostProviderFactory* http_bridge_factory; |
| 242 sync_api::HttpPostProviderFactory* auth_http_bridge_factory; | 233 sync_api::SyncCredentials credentials; |
| 243 std::string lsid; | 234 std::string lsid; |
| 244 bool delete_sync_data_folder; | 235 bool delete_sync_data_folder; |
| 245 bool invalidate_sync_login; | 236 bool invalidate_sync_login; |
| 246 bool invalidate_sync_xmpp_login; | 237 bool invalidate_sync_xmpp_login; |
| 247 bool use_chrome_async_socket; | 238 bool use_chrome_async_socket; |
| 248 bool try_ssltcp_first; | 239 bool try_ssltcp_first; |
| 249 NotificationMethod notification_method; | 240 NotificationMethod notification_method; |
| 250 std::string restored_key_for_bootstrapping; | 241 std::string restored_key_for_bootstrapping; |
| 251 }; | 242 }; |
| 252 | 243 |
| 253 // Note: | 244 // Note: |
| 254 // | 245 // |
| 255 // The Do* methods are the various entry points from our SyncBackendHost. | 246 // The Do* methods are the various entry points from our SyncBackendHost. |
| 256 // It calls us on a dedicated thread to actually perform synchronous | 247 // It calls us on a dedicated thread to actually perform synchronous |
| 257 // (and potentially blocking) syncapi operations. | 248 // (and potentially blocking) syncapi operations. |
| 258 // | 249 // |
| 259 // Called on the SyncBackendHost core_thread_ to perform initialization | 250 // Called on the SyncBackendHost core_thread_ to perform initialization |
| 260 // of the syncapi on behalf of SyncBackendHost::Initialize. | 251 // of the syncapi on behalf of SyncBackendHost::Initialize. |
| 261 void DoInitialize(const DoInitializeOptions& options); | 252 void DoInitialize(const DoInitializeOptions& options); |
| 262 | 253 |
| 263 // Called on our SyncBackendHost's core_thread_ to perform authentication | 254 // Called on our SyncBackendHost's core_thread_ to perform credential |
| 264 // on behalf of SyncBackendHost::Authenticate. | 255 // update on behalf of SyncBackendHost::UpdateCredentials |
| 265 void DoAuthenticate(const std::string& username, | 256 void DoUpdateCredentials(const sync_api::SyncCredentials& credentials); |
| 266 const std::string& password, | |
| 267 const std::string& captcha); | |
| 268 | 257 |
| 269 // Called on the SyncBackendHost core_thread_ to tell the syncapi to start | 258 // Called on the SyncBackendHost core_thread_ to tell the syncapi to start |
| 270 // syncing (generally after initialization and authentication). | 259 // syncing (generally after initialization and authentication). |
| 271 void DoStartSyncing(); | 260 void DoStartSyncing(); |
| 272 | 261 |
| 273 // Called on the SyncBackendHost core_thread_ to nudge/pause/resume the | 262 // Called on the SyncBackendHost core_thread_ to nudge/pause/resume the |
| 274 // syncer. | 263 // syncer. |
| 275 void DoRequestNudge(); | 264 void DoRequestNudge(); |
| 276 void DoRequestPause(); | 265 void DoRequestPause(); |
| 277 void DoRequestResume(); | 266 void DoRequestResume(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 301 // time sync is enabled for a user (to prevent accidentally reusing old | 290 // time sync is enabled for a user (to prevent accidentally reusing old |
| 302 // sync databases), as well as shutdown when you're no longer syncing. | 291 // sync databases), as well as shutdown when you're no longer syncing. |
| 303 void DeleteSyncDataFolder(); | 292 void DeleteSyncDataFolder(); |
| 304 | 293 |
| 305 #if defined(UNIT_TEST) | 294 #if defined(UNIT_TEST) |
| 306 // Special form of initialization that does not try and authenticate the | 295 // Special form of initialization that does not try and authenticate the |
| 307 // last known user (since it will fail in test mode) and does some extra | 296 // last known user (since it will fail in test mode) and does some extra |
| 308 // setup to nudge the syncapi into a useable state. | 297 // setup to nudge the syncapi into a useable state. |
| 309 void DoInitializeForTest(const std::wstring& test_user, | 298 void DoInitializeForTest(const std::wstring& test_user, |
| 310 sync_api::HttpPostProviderFactory* factory, | 299 sync_api::HttpPostProviderFactory* factory, |
| 311 sync_api::HttpPostProviderFactory* auth_factory, | |
| 312 bool delete_sync_data_folder, | 300 bool delete_sync_data_folder, |
| 313 NotificationMethod notification_method) { | 301 NotificationMethod notification_method) { |
| 314 DoInitialize(DoInitializeOptions(GURL(), false, factory, auth_factory, | 302 // Construct dummy credentials for test. |
| 315 std::string(), delete_sync_data_folder, | 303 sync_api::SyncCredentials credentials; |
| 316 false, false, false, false, | 304 credentials.email = WideToUTF8(test_user); |
| 317 notification_method, "")); | 305 credentials.sync_token = "token"; |
| 318 syncapi_->SetupForTestMode(test_user); | 306 DoInitialize(DoInitializeOptions(GURL(), factory, |
| 307 credentials, |
| 308 delete_sync_data_folder, false, false, |
| 309 notification_method, std::string())); |
| 310 syncapi_->SetupForTestMode(test_user); |
| 319 } | 311 } |
| 320 #endif | 312 #endif |
| 321 | 313 |
| 322 private: | 314 private: |
| 323 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 315 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
| 324 friend class SyncBackendHostForProfileSyncTest; | 316 friend class SyncBackendHostForProfileSyncTest; |
| 325 | 317 |
| 326 ~Core(); | 318 ~Core(); |
| 327 | 319 |
| 328 // Sends a SYNC_PAUSED notification to the notification service on | 320 // Sends a SYNC_PAUSED notification to the notification service on |
| (...skipping 22 matching lines...) Expand all Loading... |
| 351 // frontend UI components. | 343 // frontend UI components. |
| 352 void HandleAuthErrorEventOnFrontendLoop( | 344 void HandleAuthErrorEventOnFrontendLoop( |
| 353 const GoogleServiceAuthError& new_auth_error); | 345 const GoogleServiceAuthError& new_auth_error); |
| 354 | 346 |
| 355 // Invoked when a passphrase is required to decrypt a set of Nigori keys. | 347 // Invoked when a passphrase is required to decrypt a set of Nigori keys. |
| 356 void NotifyPassphraseRequired(); | 348 void NotifyPassphraseRequired(); |
| 357 | 349 |
| 358 // Invoked when the passphrase provided by the user has been accepted. | 350 // Invoked when the passphrase provided by the user has been accepted. |
| 359 void NotifyPassphraseAccepted(const std::string& bootstrap_token); | 351 void NotifyPassphraseAccepted(const std::string& bootstrap_token); |
| 360 | 352 |
| 353 // Invoked when an updated token is available from the sync server. |
| 354 void NotifyUpdatedToken(const std::string& token); |
| 355 |
| 361 // Called from Core::OnSyncCycleCompleted to handle updating frontend | 356 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
| 362 // thread components. | 357 // thread components. |
| 363 void HandleSyncCycleCompletedOnFrontendLoop( | 358 void HandleSyncCycleCompletedOnFrontendLoop( |
| 364 sessions::SyncSessionSnapshot* snapshot); | 359 sessions::SyncSessionSnapshot* snapshot); |
| 365 | 360 |
| 366 void HandleStopSyncingPermanentlyOnFrontendLoop(); | 361 void HandleStopSyncingPermanentlyOnFrontendLoop(); |
| 367 | 362 |
| 368 // Called from Core::OnInitializationComplete to handle updating | 363 // Called from Core::OnInitializationComplete to handle updating |
| 369 // frontend thread components. | 364 // frontend thread components. |
| 370 void HandleInitalizationCompletedOnFrontendLoop(); | 365 void HandleInitalizationCompletedOnFrontendLoop(); |
| 371 | 366 |
| 372 // Return true if a model lives on the current thread. | 367 // Return true if a model lives on the current thread. |
| 373 bool IsCurrentThreadSafeForModel(syncable::ModelType model_type); | 368 bool IsCurrentThreadSafeForModel(syncable::ModelType model_type); |
| 374 | 369 |
| 370 // True if credentials are ready for sync use. |
| 371 bool CredentialsAvailable(); |
| 372 |
| 375 // Our parent SyncBackendHost | 373 // Our parent SyncBackendHost |
| 376 SyncBackendHost* host_; | 374 SyncBackendHost* host_; |
| 377 | 375 |
| 378 // The timer used to periodically call SaveChanges. | 376 // The timer used to periodically call SaveChanges. |
| 379 base::RepeatingTimer<Core> save_changes_timer_; | 377 base::RepeatingTimer<Core> save_changes_timer_; |
| 380 | 378 |
| 381 // The top-level syncapi entry point. | 379 // The top-level syncapi entry point. |
| 382 scoped_ptr<sync_api::SyncManager> syncapi_; | 380 scoped_ptr<sync_api::SyncManager> syncapi_; |
| 383 | 381 |
| 384 DISALLOW_COPY_AND_ASSIGN(Core); | 382 DISALLOW_COPY_AND_ASSIGN(Core); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 480 |
| 483 // Whether we've processed the initialization complete callback. | 481 // Whether we've processed the initialization complete callback. |
| 484 bool syncapi_initialized_; | 482 bool syncapi_initialized_; |
| 485 | 483 |
| 486 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 484 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 487 }; | 485 }; |
| 488 | 486 |
| 489 } // namespace browser_sync | 487 } // namespace browser_sync |
| 490 | 488 |
| 491 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 489 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |