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

Side by Side Diff: components/sync/driver/startup_controller.h

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

Powered by Google App Engine
This is Rietveld 408576698