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

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

Issue 162443004: sync: final pieces to sync deferred initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 6 years, 9 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 | Annotate | Revision Log
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 CHROME_BROWSER_SYNC_STARTUP_CONTROLLER_H_
6 #define CHROME_BROWSER_SYNC_STARTUP_CONTROLLER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h"
11 #include "sync/internal_api/public/base/model_type.h"
12
13 class ManagedUserSigninManagerWrapper;
14 class ProfileOAuth2TokenService;
15
16 namespace browser_sync {
17
18 class SyncPrefs;
19
20 // Defines the type of behavior the sync engine should use. If configured for
21 // AUTO_START, the sync engine will automatically call SetSyncSetupCompleted()
22 // and start downloading data types as soon as sync credentials are available.
23 // If configured for MANUAL_START, sync will not start until the user
24 // completes sync setup, at which point the UI makes an explicit call to
25 // complete sync setup.
26 enum ProfileSyncServiceStartBehavior {
27 AUTO_START,
28 MANUAL_START,
29 };
30
31 // This class is used by ProfileSyncService to manage all logic and state
32 // pertaining to initialization of the SyncBackendHost (colloquially referred
33 // to as "the backend").
34 class StartupController {
35 public:
36 StartupController(ProfileSyncServiceStartBehavior start_behavior,
37 ProfileOAuth2TokenService* token_service,
38 const browser_sync::SyncPrefs* sync_prefs,
39 const ManagedUserSigninManagerWrapper* signin,
40 base::Closure start_backend);
41 ~StartupController();
42
43 // Starts up sync if it is not suppressed and preconditions are met.
44 // Returns true if these preconditions are met, although does not imply
45 // the backend was started.
46 bool TryStart();
47
48 // Called when a datatype (SyncableService) has a need for sync to start
49 // ASAP, presumably because a local change event has occurred but we're
50 // still in deferred start mode, meaning the SyncableService hasn't been
51 // told to MergeDataAndStartSyncing yet.
52 // It is expected that |type| is a currently active datatype.
53 void OnDataTypeRequestsSyncStartup(syncer::ModelType type);
54
55 // Prepares this object for a new attempt to start sync, forgetting
56 // whether or not preconditions were previously met.
57 void Reset();
58
59 void set_setup_in_progress(bool in_progress);
60 bool setup_in_progress() const { return setup_in_progress_; }
61 bool auto_start_enabled() const { return auto_start_enabled_; }
62 base::Time start_backend_time() const { return start_backend_time_; }
63 std::string GetBackendInitializationStateString() const;
64
65 void OverrideFallbackTimeoutForTest(const base::TimeDelta& timeout);
66 private:
67 enum StartUpDeferredOption {
68 STARTUP_BACKEND_DEFERRED,
69 STARTUP_IMMEDIATE
70 };
71 // Returns true if all conditions to start the backend are met.
72 bool StartUp(StartUpDeferredOption deferred_option);
73 void OnFallbackStartupTimerExpired();
74
75 // True if we should start sync ASAP because either a SyncableService has
76 // requested it, or we're done waiting for a sign and decided to go ahead.
77 bool received_start_request_;
78
79 // The time that StartUp() is called. This is used to calculate time spent
80 // in the deferred state; that is, after StartUp and before invoking the
81 // start_backend_ callback.
82 base::Time start_up_time_;
83
84 // If |true|, there is setup UI visible so we should not start downloading
85 // data types.
86 bool setup_in_progress_;
87
88 // If true, we want to automatically start sync signin whenever we have
89 // credentials (user doesn't need to go through the startup flow). This is
90 // typically enabled on platforms (like ChromeOS) that have their own
91 // distinct signin flow.
92 const bool auto_start_enabled_;
93
94 const browser_sync::SyncPrefs* sync_prefs_;
95
96 ProfileOAuth2TokenService* token_service_;
97
98 const ManagedUserSigninManagerWrapper* signin_;
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 base::WeakPtrFactory<StartupController> weak_factory_;
110 };
111
112 } // namespace browser_sync
113
114 #endif // CHROME_BROWSER_SYNC_STARTUP_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_unittest.cc ('k') | chrome/browser/sync/startup_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698