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

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: fix test leak Created 6 years, 10 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 void TryStart();
45
46 // Called when a datatype (SyncableService) has a need for sync to start
47 // ASAP, presumably because a local change event has occurred but we're
48 // still in deferred start mode, meaning the SyncableService hasn't been
49 // told to MergeDataAndStartSyncing yet.
50 void OnDataTypeRequestsSyncStartup(syncer::ModelType type);
51
52 // Prepares this object for a new attempt to start sync, forgetting
53 // whether or not preconditions were previously met.
54 void Reset();
55
56 void set_setup_in_progress(bool in_progress);
57 bool setup_in_progress() const { return setup_in_progress_; }
58 bool auto_start_enabled() const { return auto_start_enabled_; }
59 base::Time start_backend_time() const { return start_backend_time_; }
60 std::string GetBackendInitializationStateString() const;
61
62 void OverrideFallbackTimeoutForTest(const base::TimeDelta& timeout);
63 private:
64 enum StartUpDeferredOption {
65 STARTUP_BACKEND_DEFERRED,
66 STARTUP_IMMEDIATE
67 };
68 void StartUp(StartUpDeferredOption deferred_option);
69 void OnFallbackStartupTimerExpired();
70
71 // True if we should start sync ASAP because either a SyncableService has
72 // requested it, or we're done waiting for a sign and decided to go ahead.
73 bool received_start_request_;
74
75 // The time that StartUp() is called. This is used to calculate time spent
76 // in the deferred state; that is, after StartUp and before invoking the
77 // start_backend_ callback.
78 base::Time start_up_time_;
79
80 // If |true|, there is setup UI visible so we should not start downloading
81 // data types.
82 bool setup_in_progress_;
83
84 // If true, we want to automatically start sync signin whenever we have
85 // credentials (user doesn't need to go through the startup flow). This is
86 // typically enabled on platforms (like ChromeOS) that have their own
87 // distinct signin flow.
88 const bool auto_start_enabled_;
89
90 const browser_sync::SyncPrefs* sync_prefs_;
91
92 ProfileOAuth2TokenService* token_service_;
93
94 const ManagedUserSigninManagerWrapper* signin_;
95
96 // The callback we invoke when it's time to call expensive
97 // startup routines for the sync backend.
98 base::Closure start_backend_;
99
100 // The time at which we invoked the start_backend_ callback.
101 base::Time start_backend_time_;
102
103 base::TimeDelta fallback_timeout_;
104
105 base::WeakPtrFactory<StartupController> weak_factory_;
106 };
107
108 } // namespace browser_sync
109
110 #endif // CHROME_BROWSER_SYNC_STARTUP_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698