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" |
11 #include "components/sync/base/model_type.h" | 11 #include "components/sync/base/model_type.h" |
12 | 12 |
13 namespace syncer { | 13 namespace sync_driver { |
| 14 class SyncPrefs; |
| 15 } |
14 | 16 |
15 class SyncPrefs; | 17 namespace browser_sync { |
16 | 18 |
17 // This class is used by ProfileSyncService to manage all logic and state | 19 // This class is used by ProfileSyncService to manage all logic and state |
18 // pertaining to initialization of the SyncBackendHost (colloquially referred | 20 // pertaining to initialization of the SyncBackendHost (colloquially referred |
19 // to as "the backend"). | 21 // to as "the backend"). |
20 class StartupController { | 22 class StartupController { |
21 public: | 23 public: |
22 StartupController(const SyncPrefs* sync_prefs, | 24 StartupController(const sync_driver::SyncPrefs* sync_prefs, |
23 base::Callback<bool()> can_start, | 25 base::Callback<bool()> can_start, |
24 base::Closure start_backend); | 26 base::Closure start_backend); |
25 ~StartupController(); | 27 ~StartupController(); |
26 | 28 |
27 // Starts up sync if it is requested by the user and preconditions are met. | 29 // Starts up sync if it is requested by the user and preconditions are met. |
28 // Returns true if these preconditions are met, although does not imply | 30 // Returns true if these preconditions are met, although does not imply |
29 // the backend was started. | 31 // the backend was started. |
30 bool TryStart(); | 32 bool TryStart(); |
31 | 33 |
32 // Same as TryStart() above, but bypasses deferred startup and the first setup | 34 // Same as TryStart() above, but bypasses deferred startup and the first setup |
33 // complete check. | 35 // complete check. |
34 bool TryStartImmediately(); | 36 bool TryStartImmediately(); |
35 | 37 |
36 // Called when a datatype (SyncableService) has a need for sync to start | 38 // Called when a datatype (SyncableService) has a need for sync to start |
37 // ASAP, presumably because a local change event has occurred but we're | 39 // ASAP, presumably because a local change event has occurred but we're |
38 // still in deferred start mode, meaning the SyncableService hasn't been | 40 // still in deferred start mode, meaning the SyncableService hasn't been |
39 // told to MergeDataAndStartSyncing yet. | 41 // told to MergeDataAndStartSyncing yet. |
40 // It is expected that |type| is a currently active datatype. | 42 // It is expected that |type| is a currently active datatype. |
41 void OnDataTypeRequestsSyncStartup(ModelType type); | 43 void OnDataTypeRequestsSyncStartup(syncer::ModelType type); |
42 | 44 |
43 // Prepares this object for a new attempt to start sync, forgetting | 45 // Prepares this object for a new attempt to start sync, forgetting |
44 // whether or not preconditions were previously met. | 46 // whether or not preconditions were previously met. |
45 // NOTE: This resets internal state managed by this class, but does not | 47 // NOTE: This resets internal state managed by this class, but does not |
46 // touch values that are explicitly set and reset by higher layers to | 48 // touch values that are explicitly set and reset by higher layers to |
47 // tell this class whether a setup UI dialog is being shown to the user. | 49 // tell this class whether a setup UI dialog is being shown to the user. |
48 // See setup_in_progress_. | 50 // See setup_in_progress_. |
49 void Reset(const ModelTypeSet registered_types); | 51 void Reset(const syncer::ModelTypeSet registered_types); |
50 | 52 |
51 // Sets the setup in progress flag and tries to start sync if it's true. | 53 // Sets the setup in progress flag and tries to start sync if it's true. |
52 void SetSetupInProgress(bool setup_in_progress); | 54 void SetSetupInProgress(bool setup_in_progress); |
53 | 55 |
54 bool IsSetupInProgress() const { return setup_in_progress_; } | 56 bool IsSetupInProgress() const { return setup_in_progress_; } |
55 base::Time start_backend_time() const { return start_backend_time_; } | 57 base::Time start_backend_time() const { return start_backend_time_; } |
56 std::string GetBackendInitializationStateString() const; | 58 std::string GetBackendInitializationStateString() const; |
57 | 59 |
58 void OverrideFallbackTimeoutForTest(const base::TimeDelta& timeout); | 60 void OverrideFallbackTimeoutForTest(const base::TimeDelta& timeout); |
59 | 61 |
(...skipping 19 matching lines...) Expand all Loading... |
79 // start_backend_ callback. | 81 // start_backend_ callback. |
80 base::Time start_up_time_; | 82 base::Time start_up_time_; |
81 | 83 |
82 // If |true|, there is setup UI visible so we should not start downloading | 84 // If |true|, there is setup UI visible so we should not start downloading |
83 // data types. | 85 // data types. |
84 // Note: this is explicitly controlled by higher layers (UI) and is meant to | 86 // Note: this is explicitly controlled by higher layers (UI) and is meant to |
85 // reflect what the UI claims the setup state to be. Therefore, only set this | 87 // reflect what the UI claims the setup state to be. Therefore, only set this |
86 // due to explicit requests to do so via SetSetupInProgress. | 88 // due to explicit requests to do so via SetSetupInProgress. |
87 bool setup_in_progress_; | 89 bool setup_in_progress_; |
88 | 90 |
89 const SyncPrefs* sync_prefs_; | 91 const sync_driver::SyncPrefs* sync_prefs_; |
90 | 92 |
91 // A function that can be invoked repeatedly to determine whether sync can be | 93 // A function that can be invoked repeatedly to determine whether sync can be |
92 // started. |start_backend_| should not be invoked unless this returns true. | 94 // started. |start_backend_| should not be invoked unless this returns true. |
93 base::Callback<bool()> can_start_; | 95 base::Callback<bool()> can_start_; |
94 | 96 |
95 // The callback we invoke when it's time to call expensive | 97 // The callback we invoke when it's time to call expensive |
96 // startup routines for the sync backend. | 98 // startup routines for the sync backend. |
97 base::Closure start_backend_; | 99 base::Closure start_backend_; |
98 | 100 |
99 // The time at which we invoked the start_backend_ callback. | 101 // The time at which we invoked the start_backend_ callback. |
100 base::Time start_backend_time_; | 102 base::Time start_backend_time_; |
101 | 103 |
102 base::TimeDelta fallback_timeout_; | 104 base::TimeDelta fallback_timeout_; |
103 | 105 |
104 // Used to compute preferred_types from SyncPrefs as-needed. | 106 // Used to compute preferred_types from SyncPrefs as-needed. |
105 ModelTypeSet registered_types_; | 107 syncer::ModelTypeSet registered_types_; |
106 | 108 |
107 base::WeakPtrFactory<StartupController> weak_factory_; | 109 base::WeakPtrFactory<StartupController> weak_factory_; |
108 }; | 110 }; |
109 | 111 |
110 } // namespace syncer | 112 } // namespace browser_sync |
111 | 113 |
112 #endif // COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ | 114 #endif // COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_ |
OLD | NEW |