Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/browser/sync/profile_sync_service.h

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

Powered by Google App Engine
This is Rietveld 408576698