| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ | 6 #define COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 enum ProfileSyncServiceStartBehavior { | 28 enum ProfileSyncServiceStartBehavior { |
| 29 AUTO_START, | 29 AUTO_START, |
| 30 MANUAL_START, | 30 MANUAL_START, |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // This class is used by ProfileSyncService to manage all logic and state | 33 // This class is used by ProfileSyncService to manage all logic and state |
| 34 // pertaining to initialization of the SyncBackendHost (colloquially referred | 34 // pertaining to initialization of the SyncBackendHost (colloquially referred |
| 35 // to as "the backend"). | 35 // to as "the backend"). |
| 36 class StartupController { | 36 class StartupController { |
| 37 public: | 37 public: |
| 38 StartupController(ProfileSyncServiceStartBehavior start_behavior, | 38 StartupController(const ProfileOAuth2TokenService* token_service, |
| 39 const ProfileOAuth2TokenService* token_service, | |
| 40 const sync_driver::SyncPrefs* sync_prefs, | 39 const sync_driver::SyncPrefs* sync_prefs, |
| 41 const SigninManagerWrapper* signin, | 40 const SigninManagerWrapper* signin, |
| 42 base::Closure start_backend); | 41 base::Closure start_backend); |
| 43 ~StartupController(); | 42 ~StartupController(); |
| 44 | 43 |
| 45 // Starts up sync if it is requested by the user and preconditions are met. | 44 // Starts up sync if it is requested by the user and preconditions are met. |
| 46 // Returns true if these preconditions are met, although does not imply | 45 // Returns true if these preconditions are met, although does not imply |
| 47 // the backend was started. | 46 // the backend was started. |
| 48 bool TryStart(); | 47 bool TryStart(); |
| 49 | 48 |
| 50 // Called when a datatype (SyncableService) has a need for sync to start | 49 // Called when a datatype (SyncableService) has a need for sync to start |
| 51 // ASAP, presumably because a local change event has occurred but we're | 50 // ASAP, presumably because a local change event has occurred but we're |
| 52 // still in deferred start mode, meaning the SyncableService hasn't been | 51 // still in deferred start mode, meaning the SyncableService hasn't been |
| 53 // told to MergeDataAndStartSyncing yet. | 52 // told to MergeDataAndStartSyncing yet. |
| 54 // It is expected that |type| is a currently active datatype. | 53 // It is expected that |type| is a currently active datatype. |
| 55 void OnDataTypeRequestsSyncStartup(syncer::ModelType type); | 54 void OnDataTypeRequestsSyncStartup(syncer::ModelType type); |
| 56 | 55 |
| 57 // Prepares this object for a new attempt to start sync, forgetting | 56 // Prepares this object for a new attempt to start sync, forgetting |
| 58 // whether or not preconditions were previously met. | 57 // whether or not preconditions were previously met. |
| 59 // NOTE: This resets internal state managed by this class, but does not | 58 // NOTE: This resets internal state managed by this class, but does not |
| 60 // touch values that are explicitly set and reset by higher layers to | 59 // touch values that are explicitly set and reset by higher layers to |
| 61 // tell this class whether a setup UI dialog is being shown to the user. | 60 // tell this class whether a setup UI dialog is being shown to the user. |
| 62 // See setup_in_progress_. | 61 // See setup_in_progress_. |
| 63 void Reset(const syncer::ModelTypeSet registered_types); | 62 void Reset(const syncer::ModelTypeSet registered_types); |
| 64 | 63 |
| 65 void set_setup_in_progress(bool in_progress); | 64 void set_setup_in_progress(bool in_progress); |
| 66 bool IsSetupInProgress() const { return setup_in_progress_; } | 65 bool IsSetupInProgress() const { return setup_in_progress_; } |
| 67 bool auto_start_enabled() const { return auto_start_enabled_; } | |
| 68 base::Time start_backend_time() const { return start_backend_time_; } | 66 base::Time start_backend_time() const { return start_backend_time_; } |
| 69 std::string GetBackendInitializationStateString() const; | 67 std::string GetBackendInitializationStateString() const; |
| 70 | 68 |
| 71 void OverrideFallbackTimeoutForTest(const base::TimeDelta& timeout); | 69 void OverrideFallbackTimeoutForTest(const base::TimeDelta& timeout); |
| 72 | 70 |
| 73 private: | 71 private: |
| 74 enum StartUpDeferredOption { | 72 enum StartUpDeferredOption { |
| 75 STARTUP_BACKEND_DEFERRED, | 73 STARTUP_BACKEND_DEFERRED, |
| 76 STARTUP_IMMEDIATE | 74 STARTUP_IMMEDIATE |
| 77 }; | 75 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 91 // start_backend_ callback. | 89 // start_backend_ callback. |
| 92 base::Time start_up_time_; | 90 base::Time start_up_time_; |
| 93 | 91 |
| 94 // If |true|, there is setup UI visible so we should not start downloading | 92 // If |true|, there is setup UI visible so we should not start downloading |
| 95 // data types. | 93 // data types. |
| 96 // Note: this is explicitly controlled by higher layers (UI) and is meant to | 94 // Note: this is explicitly controlled by higher layers (UI) and is meant to |
| 97 // reflect what the UI claims the setup state to be. Therefore, only set this | 95 // reflect what the UI claims the setup state to be. Therefore, only set this |
| 98 // due to explicit requests to do so via set_setup_in_progress. | 96 // due to explicit requests to do so via set_setup_in_progress. |
| 99 bool setup_in_progress_; | 97 bool setup_in_progress_; |
| 100 | 98 |
| 101 // If true, we want to automatically start sync signin whenever we have | |
| 102 // credentials (user doesn't need to go through the startup flow). This is | |
| 103 // typically enabled on platforms (like ChromeOS) that have their own | |
| 104 // distinct signin flow. | |
| 105 const bool auto_start_enabled_; | |
| 106 | |
| 107 const sync_driver::SyncPrefs* sync_prefs_; | 99 const sync_driver::SyncPrefs* sync_prefs_; |
| 108 | 100 |
| 109 const ProfileOAuth2TokenService* token_service_; | 101 const ProfileOAuth2TokenService* token_service_; |
| 110 | 102 |
| 111 const SigninManagerWrapper* signin_; | 103 const SigninManagerWrapper* signin_; |
| 112 | 104 |
| 113 // The callback we invoke when it's time to call expensive | 105 // The callback we invoke when it's time to call expensive |
| 114 // startup routines for the sync backend. | 106 // startup routines for the sync backend. |
| 115 base::Closure start_backend_; | 107 base::Closure start_backend_; |
| 116 | 108 |
| 117 // The time at which we invoked the start_backend_ callback. | 109 // The time at which we invoked the start_backend_ callback. |
| 118 base::Time start_backend_time_; | 110 base::Time start_backend_time_; |
| 119 | 111 |
| 120 base::TimeDelta fallback_timeout_; | 112 base::TimeDelta fallback_timeout_; |
| 121 | 113 |
| 122 // Used to compute preferred_types from SyncPrefs as-needed. | 114 // Used to compute preferred_types from SyncPrefs as-needed. |
| 123 syncer::ModelTypeSet registered_types_; | 115 syncer::ModelTypeSet registered_types_; |
| 124 | 116 |
| 125 // True before calling |start_backend_| for the first time. False after that. | |
| 126 bool first_start_; | |
| 127 | |
| 128 base::WeakPtrFactory<StartupController> weak_factory_; | 117 base::WeakPtrFactory<StartupController> weak_factory_; |
| 129 }; | 118 }; |
| 130 | 119 |
| 131 } // namespace browser_sync | 120 } // namespace browser_sync |
| 132 | 121 |
| 133 #endif // COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ | 122 #endif // COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ |
| OLD | NEW |