| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // be called synchronously with the data type's model association so | 188 // be called synchronously with the data type's model association so |
| 189 // no changes are dropped between model association and change | 189 // no changes are dropped between model association and change |
| 190 // processor activation. | 190 // processor activation. |
| 191 void ActivateDataType(DataTypeController* data_type_controller, | 191 void ActivateDataType(DataTypeController* data_type_controller, |
| 192 ChangeProcessor* change_processor); | 192 ChangeProcessor* change_processor); |
| 193 | 193 |
| 194 // Deactivates change processing for the given data type. | 194 // Deactivates change processing for the given data type. |
| 195 void DeactivateDataType(DataTypeController* data_type_controller, | 195 void DeactivateDataType(DataTypeController* data_type_controller, |
| 196 ChangeProcessor* change_processor); | 196 ChangeProcessor* change_processor); |
| 197 | 197 |
| 198 // Requests the backend to pause. Returns true if the request is | |
| 199 // sent sucessfully. When the backend does pause, a SYNC_PAUSED | |
| 200 // notification is sent to the notification service. | |
| 201 virtual bool RequestPause(); | |
| 202 | |
| 203 // Requests the backend to resume. Returns true if the request is | |
| 204 // sent sucessfully. When the backend does resume, a SYNC_RESUMED | |
| 205 // notification is sent to the notification service. | |
| 206 virtual bool RequestResume(); | |
| 207 | |
| 208 // Asks the server to clear all data associated with ChromeSync. | 198 // Asks the server to clear all data associated with ChromeSync. |
| 209 virtual bool RequestClearServerData(); | 199 virtual bool RequestClearServerData(); |
| 210 | 200 |
| 211 // Called on |frontend_loop_| to obtain a handle to the UserShare needed | 201 // Called on |frontend_loop_| to obtain a handle to the UserShare needed |
| 212 // for creating transactions. | 202 // for creating transactions. |
| 213 sync_api::UserShare* GetUserShare() const; | 203 sync_api::UserShare* GetUserShare() const; |
| 214 | 204 |
| 215 // Called from any thread to obtain current status information in detailed or | 205 // Called from any thread to obtain current status information in detailed or |
| 216 // summarized form. | 206 // summarized form. |
| 217 Status GetDetailedStatus(); | 207 Status GetDetailedStatus(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 const sync_api::SyncManager::ChangeRecord* changes, | 265 const sync_api::SyncManager::ChangeRecord* changes, |
| 276 int change_count); | 266 int change_count); |
| 277 virtual void OnChangesComplete(syncable::ModelType model_type); | 267 virtual void OnChangesComplete(syncable::ModelType model_type); |
| 278 virtual void OnSyncCycleCompleted( | 268 virtual void OnSyncCycleCompleted( |
| 279 const sessions::SyncSessionSnapshot* snapshot); | 269 const sessions::SyncSessionSnapshot* snapshot); |
| 280 virtual void OnInitializationComplete(); | 270 virtual void OnInitializationComplete(); |
| 281 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); | 271 virtual void OnAuthError(const GoogleServiceAuthError& auth_error); |
| 282 virtual void OnPassphraseRequired(bool for_decryption); | 272 virtual void OnPassphraseRequired(bool for_decryption); |
| 283 virtual void OnPassphraseFailed(); | 273 virtual void OnPassphraseFailed(); |
| 284 virtual void OnPassphraseAccepted(const std::string& bootstrap_token); | 274 virtual void OnPassphraseAccepted(const std::string& bootstrap_token); |
| 285 virtual void OnPaused(); | |
| 286 virtual void OnResumed(); | |
| 287 virtual void OnStopSyncingPermanently(); | 275 virtual void OnStopSyncingPermanently(); |
| 288 virtual void OnUpdatedToken(const std::string& token); | 276 virtual void OnUpdatedToken(const std::string& token); |
| 289 virtual void OnClearServerDataFailed(); | 277 virtual void OnClearServerDataFailed(); |
| 290 virtual void OnClearServerDataSucceeded(); | 278 virtual void OnClearServerDataSucceeded(); |
| 291 virtual void OnEncryptionComplete( | 279 virtual void OnEncryptionComplete( |
| 292 const syncable::ModelTypeSet& encrypted_types); | 280 const syncable::ModelTypeSet& encrypted_types); |
| 293 | 281 |
| 294 // JsBackend implementation. | 282 // JsBackend implementation. |
| 295 virtual void SetParentJsEventRouter(JsEventRouter* router); | 283 virtual void SetParentJsEventRouter(JsEventRouter* router); |
| 296 virtual void RemoveParentJsEventRouter(); | 284 virtual void RemoveParentJsEventRouter(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // Called when the user disables or enables a sync type. | 331 // Called when the user disables or enables a sync type. |
| 344 void DoUpdateEnabledTypes(); | 332 void DoUpdateEnabledTypes(); |
| 345 | 333 |
| 346 // Called on the SyncBackendHost core_thread_ to tell the syncapi to start | 334 // Called on the SyncBackendHost core_thread_ to tell the syncapi to start |
| 347 // syncing (generally after initialization and authentication). | 335 // syncing (generally after initialization and authentication). |
| 348 void DoStartSyncing(); | 336 void DoStartSyncing(); |
| 349 | 337 |
| 350 // Called on the SyncBackendHost core_thread_ to nudge/pause/resume the | 338 // Called on the SyncBackendHost core_thread_ to nudge/pause/resume the |
| 351 // syncer. | 339 // syncer. |
| 352 void DoRequestNudge(const tracked_objects::Location& location); | 340 void DoRequestNudge(const tracked_objects::Location& location); |
| 353 void DoRequestPause(); | |
| 354 void DoRequestResume(); | |
| 355 void DoRequestClearServerData(); | 341 void DoRequestClearServerData(); |
| 356 | 342 |
| 357 // Sets |deferred_nudge_for_cleanup_requested_| to true. See comment below. | 343 // Sets |deferred_nudge_for_cleanup_requested_| to true. See comment below. |
| 358 void DeferNudgeForCleanup(); | 344 void DeferNudgeForCleanup(); |
| 359 | 345 |
| 360 // Called on our SyncBackendHost's |core_thread_| to set the passphrase | 346 // Called on our SyncBackendHost's |core_thread_| to set the passphrase |
| 361 // on behalf of SyncBackendHost::SupplyPassphrase. | 347 // on behalf of SyncBackendHost::SupplyPassphrase. |
| 362 void DoSetPassphrase(const std::string& passphrase, bool is_explicit); | 348 void DoSetPassphrase(const std::string& passphrase, bool is_explicit); |
| 363 | 349 |
| 364 // Getter/setter for whether we are waiting on SetPassphrase to process a | 350 // Getter/setter for whether we are waiting on SetPassphrase to process a |
| (...skipping 10 matching lines...) Expand all Loading... |
| 375 // 1) From |core_thread_|, invoke the syncapi Shutdown call to do a final | 361 // 1) From |core_thread_|, invoke the syncapi Shutdown call to do a final |
| 376 // SaveChanges, close sqlite handles, and halt the syncer thread (which | 362 // SaveChanges, close sqlite handles, and halt the syncer thread (which |
| 377 // could potentially block for 1 minute). | 363 // could potentially block for 1 minute). |
| 378 // 2) Then, from |frontend_loop_|, halt the core_thread_. This causes | 364 // 2) Then, from |frontend_loop_|, halt the core_thread_. This causes |
| 379 // syncapi thread-exit handlers to run and make use of cached pointers to | 365 // syncapi thread-exit handlers to run and make use of cached pointers to |
| 380 // various components owned implicitly by us. | 366 // various components owned implicitly by us. |
| 381 // 3) Destroy this Core. That will delete syncapi components in a safe order | 367 // 3) Destroy this Core. That will delete syncapi components in a safe order |
| 382 // because the thread that was using them has exited (in step 2). | 368 // because the thread that was using them has exited (in step 2). |
| 383 void DoShutdown(bool stopping_sync); | 369 void DoShutdown(bool stopping_sync); |
| 384 | 370 |
| 371 // Posts a config request on the core thread. |
| 372 virtual void DoRequestConfig(const syncable::ModelTypeBitSet& added_types); |
| 373 |
| 385 // Set the base request context to use when making HTTP calls. | 374 // Set the base request context to use when making HTTP calls. |
| 386 // This method will add a reference to the context to persist it | 375 // This method will add a reference to the context to persist it |
| 387 // on the IO thread. Must be removed from IO thread. | 376 // on the IO thread. Must be removed from IO thread. |
| 388 | 377 |
| 389 sync_api::SyncManager* syncapi() { return syncapi_.get(); } | 378 sync_api::SyncManager* syncapi() { return syncapi_.get(); } |
| 390 | 379 |
| 391 // Delete the sync data folder to cleanup backend data. Happens the first | 380 // Delete the sync data folder to cleanup backend data. Happens the first |
| 392 // time sync is enabled for a user (to prevent accidentally reusing old | 381 // time sync is enabled for a user (to prevent accidentally reusing old |
| 393 // sync databases), as well as shutdown when you're no longer syncing. | 382 // sync databases), as well as shutdown when you're no longer syncing. |
| 394 void DeleteSyncDataFolder(); | 383 void DeleteSyncDataFolder(); |
| 395 | 384 |
| 396 void ConnectChildJsEventRouter(); | 385 void ConnectChildJsEventRouter(); |
| 397 | 386 |
| 398 void DisconnectChildJsEventRouter(); | 387 void DisconnectChildJsEventRouter(); |
| 399 | 388 |
| 400 void DoProcessMessage( | 389 void DoProcessMessage( |
| 401 const std::string& name, const JsArgList& args, | 390 const std::string& name, const JsArgList& args, |
| 402 const JsEventHandler* sender); | 391 const JsEventHandler* sender); |
| 403 | 392 |
| 404 void DoStartConfigurationMode(); | |
| 405 | |
| 406 // A callback from the SyncerThread when it is safe to continue config. | 393 // A callback from the SyncerThread when it is safe to continue config. |
| 407 void FinishConfigureDataTypes(); | 394 void FinishConfigureDataTypes(); |
| 408 | 395 |
| 409 #if defined(UNIT_TEST) | 396 #if defined(UNIT_TEST) |
| 410 // Special form of initialization that does not try and authenticate the | 397 // Special form of initialization that does not try and authenticate the |
| 411 // last known user (since it will fail in test mode) and does some extra | 398 // last known user (since it will fail in test mode) and does some extra |
| 412 // setup to nudge the syncapi into a usable state. | 399 // setup to nudge the syncapi into a usable state. |
| 413 void DoInitializeForTest(const std::wstring& test_user, | 400 void DoInitializeForTest(const std::wstring& test_user, |
| 414 sync_api::HttpPostProviderFactory* factory, | 401 sync_api::HttpPostProviderFactory* factory, |
| 415 bool delete_sync_data_folder) { | 402 bool delete_sync_data_folder) { |
| 416 // Construct dummy credentials for test. | 403 // Construct dummy credentials for test. |
| 417 sync_api::SyncCredentials credentials; | 404 sync_api::SyncCredentials credentials; |
| 418 credentials.email = WideToUTF8(test_user); | 405 credentials.email = WideToUTF8(test_user); |
| 419 credentials.sync_token = "token"; | 406 credentials.sync_token = "token"; |
| 420 DoInitialize(DoInitializeOptions(GURL(), factory, credentials, | 407 DoInitialize(DoInitializeOptions(GURL(), factory, credentials, |
| 421 delete_sync_data_folder, | 408 delete_sync_data_folder, |
| 422 "", true)); | 409 "", true)); |
| 423 } | 410 } |
| 424 #endif | 411 #endif |
| 425 | 412 |
| 426 private: | 413 private: |
| 427 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 414 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
| 428 friend class SyncBackendHostForProfileSyncTest; | 415 friend class SyncBackendHostForProfileSyncTest; |
| 429 | 416 |
| 430 virtual ~Core(); | 417 virtual ~Core(); |
| 431 | 418 |
| 432 // Return change processor for a particular model (return NULL on failure). | 419 // Return change processor for a particular model (return NULL on failure). |
| 433 ChangeProcessor* GetProcessor(syncable::ModelType modeltype); | 420 ChangeProcessor* GetProcessor(syncable::ModelType modeltype); |
| 434 | 421 |
| 435 | |
| 436 // Sends a SYNC_PAUSED notification to the notification service on | |
| 437 // the UI thread. | |
| 438 void NotifyPaused(); | |
| 439 | |
| 440 // Sends a SYNC_RESUMED notification to the notification service | |
| 441 // on the UI thread. | |
| 442 void NotifyResumed(); | |
| 443 | |
| 444 // Invoked when initialization of syncapi is complete and we can start | 422 // Invoked when initialization of syncapi is complete and we can start |
| 445 // our timer. | 423 // our timer. |
| 446 // This must be called from the thread on which SaveChanges is intended to | 424 // This must be called from the thread on which SaveChanges is intended to |
| 447 // be run on; the host's |core_thread_|. | 425 // be run on; the host's |core_thread_|. |
| 448 void StartSavingChanges(); | 426 void StartSavingChanges(); |
| 449 | 427 |
| 450 // Invoked periodically to tell the syncapi to persist its state | 428 // Invoked periodically to tell the syncapi to persist its state |
| 451 // by writing to disk. | 429 // by writing to disk. |
| 452 // This is called from the thread we were created on (which is the | 430 // This is called from the thread we were created on (which is the |
| 453 // SyncBackendHost |core_thread_|), using a repeating timer that is kicked | 431 // SyncBackendHost |core_thread_|), using a repeating timer that is kicked |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 }; | 512 }; |
| 535 | 513 |
| 536 // InitializationComplete passes through the SyncBackendHost to forward | 514 // InitializationComplete passes through the SyncBackendHost to forward |
| 537 // on to |frontend_|, and so that tests can intercept here if they need to | 515 // on to |frontend_|, and so that tests can intercept here if they need to |
| 538 // set up initial conditions. | 516 // set up initial conditions. |
| 539 virtual void HandleInitializationCompletedOnFrontendLoop(); | 517 virtual void HandleInitializationCompletedOnFrontendLoop(); |
| 540 | 518 |
| 541 // Posts a nudge request on the core thread. | 519 // Posts a nudge request on the core thread. |
| 542 virtual void RequestNudge(const tracked_objects::Location& location); | 520 virtual void RequestNudge(const tracked_objects::Location& location); |
| 543 | 521 |
| 544 // Posts a config request on the core thread. | |
| 545 virtual void RequestConfig(const syncable::ModelTypeBitSet& added_types); | |
| 546 | |
| 547 // Called to finish the job of ConfigureDataTypes once the syncer is in | 522 // Called to finish the job of ConfigureDataTypes once the syncer is in |
| 548 // configuration mode. | 523 // configuration mode. |
| 549 void FinishConfigureDataTypes(); | 524 void FinishConfigureDataTypes(); |
| 550 void FinishConfigureDataTypesOnFrontendLoop(); | 525 void FinishConfigureDataTypesOnFrontendLoop(); |
| 551 | 526 |
| 552 // Allows tests to perform alternate core initialization work. | 527 // Allows tests to perform alternate core initialization work. |
| 553 virtual void InitCore(const Core::DoInitializeOptions& options); | 528 virtual void InitCore(const Core::DoInitializeOptions& options); |
| 554 | 529 |
| 555 // Factory method for HttpPostProviderFactories. | 530 // Factory method for HttpPostProviderFactories. |
| 556 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( | 531 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 | 625 |
| 651 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; | 626 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; |
| 652 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; | 627 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; |
| 653 | 628 |
| 654 // UI-thread cache of the last AuthErrorState received from syncapi. | 629 // UI-thread cache of the last AuthErrorState received from syncapi. |
| 655 GoogleServiceAuthError last_auth_error_; | 630 GoogleServiceAuthError last_auth_error_; |
| 656 | 631 |
| 657 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 632 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 658 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 633 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
| 659 | 634 |
| 660 // While two impls are in flight, using this for sanity checking. Bug 26339. | |
| 661 const bool using_new_syncer_thread_; | |
| 662 | |
| 663 // Whether we've processed the initialization complete callback. | 635 // Whether we've processed the initialization complete callback. |
| 664 bool syncapi_initialized_; | 636 bool syncapi_initialized_; |
| 665 | 637 |
| 666 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 638 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 667 }; | 639 }; |
| 668 | 640 |
| 669 } // namespace browser_sync | 641 } // namespace browser_sync |
| 670 | 642 |
| 671 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 643 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |