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

Side by Side Diff: components/sync_driver/startup_controller.h

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_
6 #define COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h"
11 #include "components/sync/base/model_type.h"
12
13 namespace sync_driver {
14 class SyncPrefs;
15 }
16
17 namespace browser_sync {
18
19 // This class is used by ProfileSyncService to manage all logic and state
20 // pertaining to initialization of the SyncBackendHost (colloquially referred
21 // to as "the backend").
22 class StartupController {
23 public:
24 StartupController(const sync_driver::SyncPrefs* sync_prefs,
25 base::Callback<bool()> can_start,
26 base::Closure start_backend);
27 ~StartupController();
28
29 // 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
31 // the backend was started.
32 bool TryStart();
33
34 // Same as TryStart() above, but bypasses deferred startup and the first setup
35 // complete check.
36 bool TryStartImmediately();
37
38 // 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
40 // still in deferred start mode, meaning the SyncableService hasn't been
41 // told to MergeDataAndStartSyncing yet.
42 // It is expected that |type| is a currently active datatype.
43 void OnDataTypeRequestsSyncStartup(syncer::ModelType type);
44
45 // Prepares this object for a new attempt to start sync, forgetting
46 // whether or not preconditions were previously met.
47 // 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
49 // tell this class whether a setup UI dialog is being shown to the user.
50 // See setup_in_progress_.
51 void Reset(const syncer::ModelTypeSet registered_types);
52
53 // Sets the setup in progress flag and tries to start sync if it's true.
54 void SetSetupInProgress(bool setup_in_progress);
55
56 bool IsSetupInProgress() const { return setup_in_progress_; }
57 base::Time start_backend_time() const { return start_backend_time_; }
58 std::string GetBackendInitializationStateString() const;
59
60 void OverrideFallbackTimeoutForTest(const base::TimeDelta& timeout);
61
62 private:
63 enum StartUpDeferredOption {
64 STARTUP_BACKEND_DEFERRED,
65 STARTUP_IMMEDIATE
66 };
67 // Returns true if all conditions to start the backend are met.
68 bool StartUp(StartUpDeferredOption deferred_option);
69 void OnFallbackStartupTimerExpired();
70
71 // Records time spent in deferred state with UMA histograms.
72 void RecordTimeDeferred();
73
74 // If true, will bypass the FirstSetupComplete check when triggering sync
75 // startup.
76 bool bypass_setup_complete_;
77
78 // True if we should start sync ASAP because either a SyncableService has
79 // requested it, or we're done waiting for a sign and decided to go ahead.
80 bool received_start_request_;
81
82 // The time that StartUp() is called. This is used to calculate time spent
83 // in the deferred state; that is, after StartUp and before invoking the
84 // start_backend_ callback.
85 base::Time start_up_time_;
86
87 // If |true|, there is setup UI visible so we should not start downloading
88 // data types.
89 // Note: this is explicitly controlled by higher layers (UI) and is meant to
90 // reflect what the UI claims the setup state to be. Therefore, only set this
91 // due to explicit requests to do so via SetSetupInProgress.
92 bool setup_in_progress_;
93
94 const sync_driver::SyncPrefs* sync_prefs_;
95
96 // A function that can be invoked repeatedly to determine whether sync can be
97 // started. |start_backend_| should not be invoked unless this returns true.
98 base::Callback<bool()> can_start_;
99
100 // The callback we invoke when it's time to call expensive
101 // startup routines for the sync backend.
102 base::Closure start_backend_;
103
104 // The time at which we invoked the start_backend_ callback.
105 base::Time start_backend_time_;
106
107 base::TimeDelta fallback_timeout_;
108
109 // Used to compute preferred_types from SyncPrefs as-needed.
110 syncer::ModelTypeSet registered_types_;
111
112 base::WeakPtrFactory<StartupController> weak_factory_;
113 };
114
115 } // namespace browser_sync
116
117 #endif // COMPONENTS_SYNC_DRIVER_STARTUP_CONTROLLER_H_
OLDNEW
« no previous file with comments | « components/sync_driver/signin_manager_wrapper.cc ('k') | components/sync_driver/startup_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698