| 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 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 20 #include "base/string16.h" | 20 #include "base/string16.h" |
| 21 #include "base/time.h" | 21 #include "base/time.h" |
| 22 #include "base/timer.h" | 22 #include "base/timer.h" |
| 23 #include "chrome/browser/invalidation/invalidation_frontend.h" | |
| 24 #include "chrome/browser/invalidation/invalidator_storage.h" | |
| 25 #include "chrome/browser/signin/signin_global_error.h" | 23 #include "chrome/browser/signin/signin_global_error.h" |
| 26 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" | 24 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" |
| 27 #include "chrome/browser/sync/failed_datatypes_handler.h" | 25 #include "chrome/browser/sync/failed_datatypes_handler.h" |
| 28 #include "chrome/browser/sync/glue/data_type_controller.h" | 26 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 29 #include "chrome/browser/sync/glue/data_type_manager.h" | 27 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 30 #include "chrome/browser/sync/glue/data_type_manager_observer.h" | 28 #include "chrome/browser/sync/glue/data_type_manager_observer.h" |
| 31 #include "chrome/browser/sync/glue/sync_backend_host.h" | 29 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 32 #include "chrome/browser/sync/profile_sync_service_base.h" | 30 #include "chrome/browser/sync/profile_sync_service_base.h" |
| 33 #include "chrome/browser/sync/profile_sync_service_observer.h" | 31 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 34 #include "chrome/browser/sync/sync_prefs.h" | 32 #include "chrome/browser/sync/sync_prefs.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 class DeviceInfo; | 54 class DeviceInfo; |
| 57 class DataTypeManager; | 55 class DataTypeManager; |
| 58 class JsController; | 56 class JsController; |
| 59 class SessionModelAssociator; | 57 class SessionModelAssociator; |
| 60 | 58 |
| 61 namespace sessions { class SyncSessionSnapshot; } | 59 namespace sessions { class SyncSessionSnapshot; } |
| 62 } | 60 } |
| 63 | 61 |
| 64 namespace syncer { | 62 namespace syncer { |
| 65 class BaseTransaction; | 63 class BaseTransaction; |
| 66 class InvalidatorRegistrar; | |
| 67 struct SyncCredentials; | 64 struct SyncCredentials; |
| 68 struct UserShare; | 65 struct UserShare; |
| 69 } | 66 } |
| 70 | 67 |
| 71 namespace sync_pb { | 68 namespace sync_pb { |
| 72 class EncryptedData; | 69 class EncryptedData; |
| 73 } // namespace sync_pb | 70 } // namespace sync_pb |
| 74 | 71 |
| 75 // ProfileSyncService is the layer between browser subsystems like bookmarks, | 72 // ProfileSyncService is the layer between browser subsystems like bookmarks, |
| 76 // and the sync backend. Each subsystem is logically thought of as being | 73 // and the sync backend. Each subsystem is logically thought of as being |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // tell the sync engine that setup is completed and it can begin downloading | 151 // tell the sync engine that setup is completed and it can begin downloading |
| 155 // data from the sync server. | 152 // data from the sync server. |
| 156 // | 153 // |
| 157 class ProfileSyncService : public ProfileSyncServiceBase, | 154 class ProfileSyncService : public ProfileSyncServiceBase, |
| 158 public browser_sync::SyncFrontend, | 155 public browser_sync::SyncFrontend, |
| 159 public browser_sync::SyncPrefObserver, | 156 public browser_sync::SyncPrefObserver, |
| 160 public browser_sync::DataTypeManagerObserver, | 157 public browser_sync::DataTypeManagerObserver, |
| 161 public SigninGlobalError::AuthStatusProvider, | 158 public SigninGlobalError::AuthStatusProvider, |
| 162 public syncer::UnrecoverableErrorHandler, | 159 public syncer::UnrecoverableErrorHandler, |
| 163 public content::NotificationObserver, | 160 public content::NotificationObserver, |
| 164 public BrowserContextKeyedService, | 161 public BrowserContextKeyedService { |
| 165 public invalidation::InvalidationFrontend { | |
| 166 public: | 162 public: |
| 167 typedef browser_sync::SyncBackendHost::Status Status; | 163 typedef browser_sync::SyncBackendHost::Status Status; |
| 168 | 164 |
| 169 enum SyncEventCodes { | 165 enum SyncEventCodes { |
| 170 MIN_SYNC_EVENT_CODE = 0, | 166 MIN_SYNC_EVENT_CODE = 0, |
| 171 | 167 |
| 172 // Events starting the sync service. | 168 // Events starting the sync service. |
| 173 START_FROM_NTP = 1, // Sync was started from the ad in NTP | 169 START_FROM_NTP = 1, // Sync was started from the ad in NTP |
| 174 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. | 170 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. |
| 175 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. | 171 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 const std::string& client_id) const; | 272 const std::string& client_id) const; |
| 277 | 273 |
| 278 // Fills state_map with a map of current data types that are possible to | 274 // Fills state_map with a map of current data types that are possible to |
| 279 // sync, as well as their states. | 275 // sync, as well as their states. |
| 280 void GetDataTypeControllerStates( | 276 void GetDataTypeControllerStates( |
| 281 browser_sync::DataTypeController::StateMap* state_map) const; | 277 browser_sync::DataTypeController::StateMap* state_map) const; |
| 282 | 278 |
| 283 // Disables sync for user. Use ShowLoginDialog to enable. | 279 // Disables sync for user. Use ShowLoginDialog to enable. |
| 284 virtual void DisableForUser(); | 280 virtual void DisableForUser(); |
| 285 | 281 |
| 286 // syncer::InvalidationHandler implementation (via SyncFrontend). | |
| 287 virtual void OnInvalidatorStateChange( | |
| 288 syncer::InvalidatorState state) OVERRIDE; | |
| 289 virtual void OnIncomingInvalidation( | |
| 290 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | |
| 291 | |
| 292 // SyncFrontend implementation. | 282 // SyncFrontend implementation. |
| 293 virtual void OnBackendInitialized( | 283 virtual void OnBackendInitialized( |
| 294 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 284 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 295 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 285 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 296 debug_info_listener, | 286 debug_info_listener, |
| 297 bool success) OVERRIDE; | 287 bool success) OVERRIDE; |
| 298 virtual void OnSyncCycleCompleted() OVERRIDE; | 288 virtual void OnSyncCycleCompleted() OVERRIDE; |
| 299 virtual void OnSyncConfigureRetry() OVERRIDE; | 289 virtual void OnSyncConfigureRetry() OVERRIDE; |
| 300 virtual void OnConnectionStatusChange( | 290 virtual void OnConnectionStatusChange( |
| 301 syncer::ConnectionStatus status) OVERRIDE; | 291 syncer::ConnectionStatus status) OVERRIDE; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 // If true, the ProfileSyncService has detected that a new GAIA signin has | 585 // If true, the ProfileSyncService has detected that a new GAIA signin has |
| 596 // succeeded, and is waiting for initialization to complete. This is used by | 586 // succeeded, and is waiting for initialization to complete. This is used by |
| 597 // the UI to differentiate between a new auth error (encountered as part of | 587 // the UI to differentiate between a new auth error (encountered as part of |
| 598 // the initialization process) and a pre-existing auth error that just hasn't | 588 // the initialization process) and a pre-existing auth error that just hasn't |
| 599 // been cleared yet. Virtual for testing purposes. | 589 // been cleared yet. Virtual for testing purposes. |
| 600 virtual bool waiting_for_auth() const; | 590 virtual bool waiting_for_auth() const; |
| 601 | 591 |
| 602 // The set of currently enabled sync experiments. | 592 // The set of currently enabled sync experiments. |
| 603 const syncer::Experiments& current_experiments() const; | 593 const syncer::Experiments& current_experiments() const; |
| 604 | 594 |
| 605 // InvalidationFrontend implementation. It is an error to have | 595 // ProfileKeyedService implementation. This must be called exactly |
| 606 // registered handlers when Shutdown() is called. | |
| 607 virtual void RegisterInvalidationHandler( | |
| 608 syncer::InvalidationHandler* handler) OVERRIDE; | |
| 609 virtual void UpdateRegisteredInvalidationIds( | |
| 610 syncer::InvalidationHandler* handler, | |
| 611 const syncer::ObjectIdSet& ids) OVERRIDE; | |
| 612 virtual void UnregisterInvalidationHandler( | |
| 613 syncer::InvalidationHandler* handler) OVERRIDE; | |
| 614 virtual void AcknowledgeInvalidation( | |
| 615 const invalidation::ObjectId& id, | |
| 616 const syncer::AckHandle& ack_handle) OVERRIDE; | |
| 617 | |
| 618 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | |
| 619 | |
| 620 // BrowserContextKeyedService implementation. This must be called exactly | |
| 621 // once (before this object is destroyed). | 596 // once (before this object is destroyed). |
| 622 virtual void Shutdown() OVERRIDE; | 597 virtual void Shutdown() OVERRIDE; |
| 623 | 598 |
| 624 // Simulate an incoming notification for the given id and payload. | |
| 625 void EmitInvalidationForTest( | |
| 626 const invalidation::ObjectId& id, | |
| 627 const std::string& payload); | |
| 628 | |
| 629 // Called when a datatype (SyncableService) has a need for sync to start | 599 // Called when a datatype (SyncableService) has a need for sync to start |
| 630 // ASAP, presumably because a local change event has occurred but we're | 600 // ASAP, presumably because a local change event has occurred but we're |
| 631 // still in deferred start mode, meaning the SyncableService hasn't been | 601 // still in deferred start mode, meaning the SyncableService hasn't been |
| 632 // told to MergeDataAndStartSyncing yet. | 602 // told to MergeDataAndStartSyncing yet. |
| 633 void OnDataTypeRequestsSyncStartup(syncer::ModelType type); | 603 void OnDataTypeRequestsSyncStartup(syncer::ModelType type); |
| 634 | 604 |
| 635 protected: | 605 protected: |
| 636 // Used by test classes that derive from ProfileSyncService. | 606 // Used by test classes that derive from ProfileSyncService. |
| 637 virtual browser_sync::SyncBackendHost* GetBackendForTest(); | 607 virtual browser_sync::SyncBackendHost* GetBackendForTest(); |
| 638 | 608 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 private: | 659 private: |
| 690 enum UnrecoverableErrorReason { | 660 enum UnrecoverableErrorReason { |
| 691 ERROR_REASON_UNSET, | 661 ERROR_REASON_UNSET, |
| 692 ERROR_REASON_SYNCER, | 662 ERROR_REASON_SYNCER, |
| 693 ERROR_REASON_BACKEND_INIT_FAILURE, | 663 ERROR_REASON_BACKEND_INIT_FAILURE, |
| 694 ERROR_REASON_CONFIGURATION_RETRY, | 664 ERROR_REASON_CONFIGURATION_RETRY, |
| 695 ERROR_REASON_CONFIGURATION_FAILURE, | 665 ERROR_REASON_CONFIGURATION_FAILURE, |
| 696 ERROR_REASON_ACTIONABLE_ERROR, | 666 ERROR_REASON_ACTIONABLE_ERROR, |
| 697 ERROR_REASON_LIMIT | 667 ERROR_REASON_LIMIT |
| 698 }; | 668 }; |
| 699 typedef std::vector<std::pair<invalidation::ObjectId, | |
| 700 syncer::AckHandle> > AckHandleReplayQueue; | |
| 701 friend class ProfileSyncServicePasswordTest; | 669 friend class ProfileSyncServicePasswordTest; |
| 702 friend class SyncTest; | 670 friend class SyncTest; |
| 703 friend class TestProfileSyncService; | 671 friend class TestProfileSyncService; |
| 704 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); | 672 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); |
| 705 | 673 |
| 706 // Detects and attempts to recover from a previous improper datatype | 674 // Detects and attempts to recover from a previous improper datatype |
| 707 // configuration where Keep Everything Synced and the preferred types were | 675 // configuration where Keep Everything Synced and the preferred types were |
| 708 // not correctly set. | 676 // not correctly set. |
| 709 void TrySyncDatatypePrefRecovery(); | 677 void TrySyncDatatypePrefRecovery(); |
| 710 | 678 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 731 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). | 699 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). |
| 732 void InitializeBackend(bool delete_sync_data_folder); | 700 void InitializeBackend(bool delete_sync_data_folder); |
| 733 | 701 |
| 734 // Initializes the various settings from the command line. | 702 // Initializes the various settings from the command line. |
| 735 void InitSettings(); | 703 void InitSettings(); |
| 736 | 704 |
| 737 // Sets the last synced time to the current time. | 705 // Sets the last synced time to the current time. |
| 738 void UpdateLastSyncedTime(); | 706 void UpdateLastSyncedTime(); |
| 739 | 707 |
| 740 void NotifyObservers(); | 708 void NotifyObservers(); |
| 709 void NotifySyncCycleCompleted(); |
| 741 | 710 |
| 742 void ClearStaleErrors(); | 711 void ClearStaleErrors(); |
| 743 | 712 |
| 744 void ClearUnrecoverableError(); | 713 void ClearUnrecoverableError(); |
| 745 | 714 |
| 746 enum StartUpDeferredOption { | 715 enum StartUpDeferredOption { |
| 747 STARTUP_BACKEND_DEFERRED, | 716 STARTUP_BACKEND_DEFERRED, |
| 748 STARTUP_IMMEDIATE | 717 STARTUP_IMMEDIATE |
| 749 }; | 718 }; |
| 750 void StartUp(StartUpDeferredOption deferred_option); | 719 void StartUp(StartUpDeferredOption deferred_option); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 void RefreshSpareBootstrapToken(const std::string& passphrase); | 754 void RefreshSpareBootstrapToken(const std::string& passphrase); |
| 786 #endif | 755 #endif |
| 787 | 756 |
| 788 // Internal unrecoverable error handler. Used to track error reason via | 757 // Internal unrecoverable error handler. Used to track error reason via |
| 789 // Sync.UnrecoverableErrors histogram. | 758 // Sync.UnrecoverableErrors histogram. |
| 790 void OnInternalUnrecoverableError(const tracked_objects::Location& from_here, | 759 void OnInternalUnrecoverableError(const tracked_objects::Location& from_here, |
| 791 const std::string& message, | 760 const std::string& message, |
| 792 bool delete_sync_database, | 761 bool delete_sync_database, |
| 793 UnrecoverableErrorReason reason); | 762 UnrecoverableErrorReason reason); |
| 794 | 763 |
| 795 // Must be called every time |backend_initialized_| or | |
| 796 // |invalidator_state_| is changed (but only if | |
| 797 // |invalidator_registrar_| is not NULL). | |
| 798 void UpdateInvalidatorRegistrarState(); | |
| 799 | |
| 800 // Returns the username (in form of an email address) that should be used in | 764 // Returns the username (in form of an email address) that should be used in |
| 801 // the credentials. | 765 // the credentials. |
| 802 std::string GetEffectiveUsername(); | 766 std::string GetEffectiveUsername(); |
| 803 | 767 |
| 804 // Factory used to create various dependent objects. | 768 // Factory used to create various dependent objects. |
| 805 scoped_ptr<ProfileSyncComponentsFactory> factory_; | 769 scoped_ptr<ProfileSyncComponentsFactory> factory_; |
| 806 | 770 |
| 807 // The profile whose data we are synchronizing. | 771 // The profile whose data we are synchronizing. |
| 808 Profile* profile_; | 772 Profile* profile_; |
| 809 | 773 |
| 810 // The class that handles getting, setting, and persisting sync | 774 // The class that handles getting, setting, and persisting sync |
| 811 // preferences. | 775 // preferences. |
| 812 browser_sync::SyncPrefs sync_prefs_; | 776 browser_sync::SyncPrefs sync_prefs_; |
| 813 | 777 |
| 814 // TODO(tim): Move this to InvalidationService, once it exists. Bug 124137. | |
| 815 invalidation::InvalidatorStorage invalidator_storage_; | |
| 816 | |
| 817 // TODO(ncarter): Put this in a profile, once there is UI for it. | 778 // TODO(ncarter): Put this in a profile, once there is UI for it. |
| 818 // This specifies where to find the sync server. | 779 // This specifies where to find the sync server. |
| 819 GURL sync_service_url_; | 780 GURL sync_service_url_; |
| 820 | 781 |
| 821 // The last time we detected a successful transition from SYNCING state. | 782 // The last time we detected a successful transition from SYNCING state. |
| 822 // Our backend notifies us whenever we should take a new snapshot. | 783 // Our backend notifies us whenever we should take a new snapshot. |
| 823 base::Time last_synced_time_; | 784 base::Time last_synced_time_; |
| 824 | 785 |
| 825 // The time that StartUp() is called. This member is zero if StartUp() has | 786 // The time that StartUp() is called. This member is zero if StartUp() has |
| 826 // never been called, and is reset to zero once OnBackendInitialized() is | 787 // never been called, and is reset to zero once OnBackendInitialized() is |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 // If |true|, there is setup UI visible so we should not start downloading | 882 // If |true|, there is setup UI visible so we should not start downloading |
| 922 // data types. | 883 // data types. |
| 923 bool setup_in_progress_; | 884 bool setup_in_progress_; |
| 924 | 885 |
| 925 // The set of currently enabled sync experiments. | 886 // The set of currently enabled sync experiments. |
| 926 syncer::Experiments current_experiments_; | 887 syncer::Experiments current_experiments_; |
| 927 | 888 |
| 928 // Factory the backend will use to build the SyncManager. | 889 // Factory the backend will use to build the SyncManager. |
| 929 syncer::SyncManagerFactory sync_manager_factory_; | 890 syncer::SyncManagerFactory sync_manager_factory_; |
| 930 | 891 |
| 931 // Holds the current invalidator state as updated by | |
| 932 // OnInvalidatorStateChange(). Note that this is different from the | |
| 933 // state known by |invalidator_registrar_| (See | |
| 934 // UpdateInvalidatorState()). | |
| 935 syncer::InvalidatorState invalidator_state_; | |
| 936 | |
| 937 // Dispatches invalidations to handlers. Set in Initialize() and | |
| 938 // unset in Shutdown(). | |
| 939 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | |
| 940 // Queues any acknowledgements received while the backend is uninitialized. | |
| 941 AckHandleReplayQueue ack_replay_queue_; | |
| 942 | |
| 943 // Sync's internal debug info listener. Used to record datatype configuration | 892 // Sync's internal debug info listener. Used to record datatype configuration |
| 944 // and association information. | 893 // and association information. |
| 945 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; | 894 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; |
| 946 | 895 |
| 947 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 896 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
| 948 }; | 897 }; |
| 949 | 898 |
| 950 bool ShouldShowActionOnUI( | 899 bool ShouldShowActionOnUI( |
| 951 const syncer::SyncProtocolError& error); | 900 const syncer::SyncProtocolError& error); |
| 952 | 901 |
| 953 | 902 |
| 954 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 903 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| OLD | NEW |