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> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "base/timer.h" | 22 #include "base/timer.h" |
23 #include "chrome/browser/profiles/profile_keyed_service.h" | 23 #include "chrome/browser/profiles/profile_keyed_service.h" |
24 #include "chrome/browser/signin/signin_global_error.h" | 24 #include "chrome/browser/signin/signin_global_error.h" |
25 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" | 25 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" |
26 #include "chrome/browser/sync/failed_datatypes_handler.h" | 26 #include "chrome/browser/sync/failed_datatypes_handler.h" |
27 #include "chrome/browser/sync/glue/data_type_controller.h" | 27 #include "chrome/browser/sync/glue/data_type_controller.h" |
28 #include "chrome/browser/sync/glue/data_type_manager.h" | 28 #include "chrome/browser/sync/glue/data_type_manager.h" |
29 #include "chrome/browser/sync/glue/data_type_manager_observer.h" | 29 #include "chrome/browser/sync/glue/data_type_manager_observer.h" |
30 #include "chrome/browser/sync/glue/sync_backend_host.h" | 30 #include "chrome/browser/sync/glue/sync_backend_host.h" |
31 #include "chrome/browser/sync/invalidation_frontend.h" | |
32 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | |
33 #include "chrome/browser/sync/profile_sync_service_base.h" | 31 #include "chrome/browser/sync/profile_sync_service_base.h" |
34 #include "chrome/browser/sync/profile_sync_service_observer.h" | 32 #include "chrome/browser/sync/profile_sync_service_observer.h" |
35 #include "chrome/browser/sync/sync_prefs.h" | 33 #include "chrome/browser/sync/sync_prefs.h" |
36 #include "content/public/browser/notification_observer.h" | 34 #include "content/public/browser/notification_observer.h" |
37 #include "content/public/browser/notification_registrar.h" | 35 #include "content/public/browser/notification_registrar.h" |
38 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
39 #include "google_apis/gaia/google_service_auth_error.h" | 37 #include "google_apis/gaia/google_service_auth_error.h" |
40 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
41 #include "sync/internal_api/public/base/model_type.h" | 39 #include "sync/internal_api/public/base/model_type.h" |
42 #include "sync/internal_api/public/engine/model_safe_worker.h" | 40 #include "sync/internal_api/public/engine/model_safe_worker.h" |
(...skipping 13 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 ProfileKeyedService, | 161 public ProfileKeyedService { |
165 public 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo() const; | 265 virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo() const; |
270 | 266 |
271 // Fills state_map with a map of current data types that are possible to | 267 // Fills state_map with a map of current data types that are possible to |
272 // sync, as well as their states. | 268 // sync, as well as their states. |
273 void GetDataTypeControllerStates( | 269 void GetDataTypeControllerStates( |
274 browser_sync::DataTypeController::StateMap* state_map) const; | 270 browser_sync::DataTypeController::StateMap* state_map) const; |
275 | 271 |
276 // Disables sync for user. Use ShowLoginDialog to enable. | 272 // Disables sync for user. Use ShowLoginDialog to enable. |
277 virtual void DisableForUser(); | 273 virtual void DisableForUser(); |
278 | 274 |
279 // syncer::InvalidationHandler implementation (via SyncFrontend). | |
280 virtual void OnInvalidatorStateChange( | |
281 syncer::InvalidatorState state) OVERRIDE; | |
282 virtual void OnIncomingInvalidation( | |
283 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | |
284 | |
285 // SyncFrontend implementation. | 275 // SyncFrontend implementation. |
286 virtual void OnBackendInitialized( | 276 virtual void OnBackendInitialized( |
287 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 277 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
288 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 278 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
289 debug_info_listener, | 279 debug_info_listener, |
290 bool success) OVERRIDE; | 280 bool success) OVERRIDE; |
291 virtual void OnSyncCycleCompleted() OVERRIDE; | 281 virtual void OnSyncCycleCompleted() OVERRIDE; |
292 virtual void OnSyncConfigureRetry() OVERRIDE; | 282 virtual void OnSyncConfigureRetry() OVERRIDE; |
293 virtual void OnConnectionStatusChange( | 283 virtual void OnConnectionStatusChange( |
294 syncer::ConnectionStatus status) OVERRIDE; | 284 syncer::ConnectionStatus status) OVERRIDE; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // If true, the ProfileSyncService has detected that a new GAIA signin has | 578 // If true, the ProfileSyncService has detected that a new GAIA signin has |
589 // succeeded, and is waiting for initialization to complete. This is used by | 579 // succeeded, and is waiting for initialization to complete. This is used by |
590 // the UI to differentiate between a new auth error (encountered as part of | 580 // the UI to differentiate between a new auth error (encountered as part of |
591 // the initialization process) and a pre-existing auth error that just hasn't | 581 // the initialization process) and a pre-existing auth error that just hasn't |
592 // been cleared yet. Virtual for testing purposes. | 582 // been cleared yet. Virtual for testing purposes. |
593 virtual bool waiting_for_auth() const; | 583 virtual bool waiting_for_auth() const; |
594 | 584 |
595 // The set of currently enabled sync experiments. | 585 // The set of currently enabled sync experiments. |
596 const syncer::Experiments& current_experiments() const; | 586 const syncer::Experiments& current_experiments() const; |
597 | 587 |
598 // InvalidationFrontend implementation. It is an error to have | |
599 // registered handlers when Shutdown() is called. | |
600 virtual void RegisterInvalidationHandler( | |
601 syncer::InvalidationHandler* handler) OVERRIDE; | |
602 virtual void UpdateRegisteredInvalidationIds( | |
603 syncer::InvalidationHandler* handler, | |
604 const syncer::ObjectIdSet& ids) OVERRIDE; | |
605 virtual void UnregisterInvalidationHandler( | |
606 syncer::InvalidationHandler* handler) OVERRIDE; | |
607 virtual void AcknowledgeInvalidation( | |
608 const invalidation::ObjectId& id, | |
609 const syncer::AckHandle& ack_handle) OVERRIDE; | |
610 | |
611 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | |
612 | |
613 // ProfileKeyedService implementation. This must be called exactly | 588 // ProfileKeyedService implementation. This must be called exactly |
614 // once (before this object is destroyed). | 589 // once (before this object is destroyed). |
615 virtual void Shutdown() OVERRIDE; | 590 virtual void Shutdown() OVERRIDE; |
616 | 591 |
617 // Simulate an incoming notification for the given id and payload. | |
618 void EmitInvalidationForTest( | |
619 const invalidation::ObjectId& id, | |
620 const std::string& payload); | |
621 | |
622 protected: | 592 protected: |
623 // Used by test classes that derive from ProfileSyncService. | 593 // Used by test classes that derive from ProfileSyncService. |
624 virtual browser_sync::SyncBackendHost* GetBackendForTest(); | 594 virtual browser_sync::SyncBackendHost* GetBackendForTest(); |
625 | 595 |
626 // Helper to configure the priority data types. | 596 // Helper to configure the priority data types. |
627 void ConfigurePriorityDataTypes(); | 597 void ConfigurePriorityDataTypes(); |
628 | 598 |
629 // Helper to install and configure a data type manager. | 599 // Helper to install and configure a data type manager. |
630 void ConfigureDataTypeManager(); | 600 void ConfigureDataTypeManager(); |
631 | 601 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 private: | 646 private: |
677 enum UnrecoverableErrorReason { | 647 enum UnrecoverableErrorReason { |
678 ERROR_REASON_UNSET, | 648 ERROR_REASON_UNSET, |
679 ERROR_REASON_SYNCER, | 649 ERROR_REASON_SYNCER, |
680 ERROR_REASON_BACKEND_INIT_FAILURE, | 650 ERROR_REASON_BACKEND_INIT_FAILURE, |
681 ERROR_REASON_CONFIGURATION_RETRY, | 651 ERROR_REASON_CONFIGURATION_RETRY, |
682 ERROR_REASON_CONFIGURATION_FAILURE, | 652 ERROR_REASON_CONFIGURATION_FAILURE, |
683 ERROR_REASON_ACTIONABLE_ERROR, | 653 ERROR_REASON_ACTIONABLE_ERROR, |
684 ERROR_REASON_LIMIT | 654 ERROR_REASON_LIMIT |
685 }; | 655 }; |
686 typedef std::vector<std::pair<invalidation::ObjectId, | |
687 syncer::AckHandle> > AckHandleReplayQueue; | |
688 friend class ProfileSyncServicePasswordTest; | 656 friend class ProfileSyncServicePasswordTest; |
689 friend class SyncTest; | 657 friend class SyncTest; |
690 friend class TestProfileSyncService; | 658 friend class TestProfileSyncService; |
691 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); | 659 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); |
692 | 660 |
693 // Detects and attempts to recover from a previous improper datatype | 661 // Detects and attempts to recover from a previous improper datatype |
694 // configuration where Keep Everything Synced and the preferred types were | 662 // configuration where Keep Everything Synced and the preferred types were |
695 // not correctly set. | 663 // not correctly set. |
696 void TrySyncDatatypePrefRecovery(); | 664 void TrySyncDatatypePrefRecovery(); |
697 | 665 |
(...skipping 20 matching lines...) Expand all Loading... |
718 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). | 686 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). |
719 void InitializeBackend(bool delete_sync_data_folder); | 687 void InitializeBackend(bool delete_sync_data_folder); |
720 | 688 |
721 // Initializes the various settings from the command line. | 689 // Initializes the various settings from the command line. |
722 void InitSettings(); | 690 void InitSettings(); |
723 | 691 |
724 // Sets the last synced time to the current time. | 692 // Sets the last synced time to the current time. |
725 void UpdateLastSyncedTime(); | 693 void UpdateLastSyncedTime(); |
726 | 694 |
727 void NotifyObservers(); | 695 void NotifyObservers(); |
| 696 void NotifySyncCycleCompleted(); |
728 | 697 |
729 void ClearStaleErrors(); | 698 void ClearStaleErrors(); |
730 | 699 |
731 void ClearUnrecoverableError(); | 700 void ClearUnrecoverableError(); |
732 | 701 |
733 enum StartUpDeferredOption { | 702 enum StartUpDeferredOption { |
734 STARTUP_BACKEND_DEFERRED, | 703 STARTUP_BACKEND_DEFERRED, |
735 STARTUP_IMMEDIATE | 704 STARTUP_IMMEDIATE |
736 }; | 705 }; |
737 void StartUp(StartUpDeferredOption deferred_option); | 706 void StartUp(StartUpDeferredOption deferred_option); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 void RefreshSpareBootstrapToken(const std::string& passphrase); | 743 void RefreshSpareBootstrapToken(const std::string& passphrase); |
775 #endif | 744 #endif |
776 | 745 |
777 // Internal unrecoverable error handler. Used to track error reason via | 746 // Internal unrecoverable error handler. Used to track error reason via |
778 // Sync.UnrecoverableErrors histogram. | 747 // Sync.UnrecoverableErrors histogram. |
779 void OnInternalUnrecoverableError(const tracked_objects::Location& from_here, | 748 void OnInternalUnrecoverableError(const tracked_objects::Location& from_here, |
780 const std::string& message, | 749 const std::string& message, |
781 bool delete_sync_database, | 750 bool delete_sync_database, |
782 UnrecoverableErrorReason reason); | 751 UnrecoverableErrorReason reason); |
783 | 752 |
784 // Must be called every time |backend_initialized_| or | |
785 // |invalidator_state_| is changed (but only if | |
786 // |invalidator_registrar_| is not NULL). | |
787 void UpdateInvalidatorRegistrarState(); | |
788 | |
789 // Destroys / recreates an instance of ProfileSyncService. Used exclusively by | 753 // Destroys / recreates an instance of ProfileSyncService. Used exclusively by |
790 // the sync integration tests so they can restart sync from scratch without | 754 // the sync integration tests so they can restart sync from scratch without |
791 // tearing down and recreating the browser process. Needed because simply | 755 // tearing down and recreating the browser process. Needed because simply |
792 // calling Shutdown() and Initialize() will not recreate other internal | 756 // calling Shutdown() and Initialize() will not recreate other internal |
793 // objects like SyncBackendHost, SyncManager, etc. | 757 // objects like SyncBackendHost, SyncManager, etc. |
794 void ResetForTest(); | 758 void ResetForTest(); |
795 | 759 |
796 // Factory used to create various dependent objects. | 760 // Factory used to create various dependent objects. |
797 scoped_ptr<ProfileSyncComponentsFactory> factory_; | 761 scoped_ptr<ProfileSyncComponentsFactory> factory_; |
798 | 762 |
799 // The profile whose data we are synchronizing. | 763 // The profile whose data we are synchronizing. |
800 Profile* profile_; | 764 Profile* profile_; |
801 | 765 |
802 // The class that handles getting, setting, and persisting sync | 766 // The class that handles getting, setting, and persisting sync |
803 // preferences. | 767 // preferences. |
804 browser_sync::SyncPrefs sync_prefs_; | 768 browser_sync::SyncPrefs sync_prefs_; |
805 | 769 |
806 // TODO(tim): Move this to InvalidationService, once it exists. Bug 124137. | |
807 browser_sync::InvalidatorStorage invalidator_storage_; | |
808 | |
809 // TODO(ncarter): Put this in a profile, once there is UI for it. | 770 // TODO(ncarter): Put this in a profile, once there is UI for it. |
810 // This specifies where to find the sync server. | 771 // This specifies where to find the sync server. |
811 GURL sync_service_url_; | 772 GURL sync_service_url_; |
812 | 773 |
813 // The last time we detected a successful transition from SYNCING state. | 774 // The last time we detected a successful transition from SYNCING state. |
814 // Our backend notifies us whenever we should take a new snapshot. | 775 // Our backend notifies us whenever we should take a new snapshot. |
815 base::Time last_synced_time_; | 776 base::Time last_synced_time_; |
816 | 777 |
817 // The time that StartUp() is called. This member is zero if StartUp() has | 778 // The time that StartUp() is called. This member is zero if StartUp() has |
818 // never been called, and is reset to zero once OnBackendInitialized() is | 779 // never been called, and is reset to zero once OnBackendInitialized() is |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 // If |true|, there is setup UI visible so we should not start downloading | 868 // If |true|, there is setup UI visible so we should not start downloading |
908 // data types. | 869 // data types. |
909 bool setup_in_progress_; | 870 bool setup_in_progress_; |
910 | 871 |
911 // The set of currently enabled sync experiments. | 872 // The set of currently enabled sync experiments. |
912 syncer::Experiments current_experiments_; | 873 syncer::Experiments current_experiments_; |
913 | 874 |
914 // Factory the backend will use to build the SyncManager. | 875 // Factory the backend will use to build the SyncManager. |
915 syncer::SyncManagerFactory sync_manager_factory_; | 876 syncer::SyncManagerFactory sync_manager_factory_; |
916 | 877 |
917 // Holds the current invalidator state as updated by | |
918 // OnInvalidatorStateChange(). Note that this is different from the | |
919 // state known by |invalidator_registrar_| (See | |
920 // UpdateInvalidatorState()). | |
921 syncer::InvalidatorState invalidator_state_; | |
922 | |
923 // Dispatches invalidations to handlers. Set in Initialize() and | |
924 // unset in Shutdown(). | |
925 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | |
926 // Queues any acknowledgements received while the backend is uninitialized. | |
927 AckHandleReplayQueue ack_replay_queue_; | |
928 | |
929 // Sync's internal debug info listener. Used to record datatype configuration | 878 // Sync's internal debug info listener. Used to record datatype configuration |
930 // and association information. | 879 // and association information. |
931 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; | 880 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; |
932 | 881 |
933 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 882 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
934 }; | 883 }; |
935 | 884 |
936 bool ShouldShowActionOnUI( | 885 bool ShouldShowActionOnUI( |
937 const syncer::SyncProtocolError& error); | 886 const syncer::SyncProtocolError& error); |
938 | 887 |
939 | 888 |
940 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 889 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
OLD | NEW |