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

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

Issue 2159453002: [Sync] Don't start up sync when FirstSetupCompleted is false and no setup in progress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review Created 4 years, 5 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 #include "components/sync_driver/startup_controller.h" 5 #include "components/sync_driver/startup_controller.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 21 matching lines...) Expand all
32 // No data type requested sync to start and our fallback timer expired. 32 // No data type requested sync to start and our fallback timer expired.
33 TRIGGER_FALLBACK_TIMER, 33 TRIGGER_FALLBACK_TIMER,
34 MAX_TRIGGER_VALUE 34 MAX_TRIGGER_VALUE
35 }; 35 };
36 36
37 } // namespace 37 } // namespace
38 38
39 StartupController::StartupController(const sync_driver::SyncPrefs* sync_prefs, 39 StartupController::StartupController(const sync_driver::SyncPrefs* sync_prefs,
40 base::Callback<bool()> can_start, 40 base::Callback<bool()> can_start,
41 base::Closure start_backend) 41 base::Closure start_backend)
42 : received_start_request_(false), 42 : bypass_setup_complete_(false),
43 received_start_request_(false),
43 setup_in_progress_(false), 44 setup_in_progress_(false),
44 sync_prefs_(sync_prefs), 45 sync_prefs_(sync_prefs),
45 can_start_(can_start), 46 can_start_(can_start),
46 start_backend_(start_backend), 47 start_backend_(start_backend),
47 fallback_timeout_( 48 fallback_timeout_(
48 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), 49 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)),
49 weak_factory_(this) { 50 weak_factory_(this) {
50 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 51 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
51 switches::kSyncDeferredStartupTimeoutSeconds)) { 52 switches::kSyncDeferredStartupTimeoutSeconds)) {
52 int timeout = kDeferredInitFallbackSeconds; 53 int timeout = kDeferredInitFallbackSeconds;
53 if (base::StringToInt( 54 if (base::StringToInt(
54 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 55 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
55 switches::kSyncDeferredStartupTimeoutSeconds), 56 switches::kSyncDeferredStartupTimeoutSeconds),
56 &timeout)) { 57 &timeout)) {
57 DCHECK_GE(timeout, 0); 58 DCHECK_GE(timeout, 0);
58 DVLOG(2) << "Sync StartupController overriding startup timeout to " 59 DVLOG(2) << "Sync StartupController overriding startup timeout to "
59 << timeout << " seconds."; 60 << timeout << " seconds.";
60 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout); 61 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout);
61 } 62 }
62 } 63 }
63 } 64 }
64 65
65 StartupController::~StartupController() {} 66 StartupController::~StartupController() {}
66 67
67 void StartupController::Reset(const syncer::ModelTypeSet registered_types) { 68 void StartupController::Reset(const syncer::ModelTypeSet registered_types) {
68 received_start_request_ = false; 69 received_start_request_ = false;
70 bypass_setup_complete_ = false;
69 start_up_time_ = base::Time(); 71 start_up_time_ = base::Time();
70 start_backend_time_ = base::Time(); 72 start_backend_time_ = base::Time();
71 // Don't let previous timers affect us post-reset. 73 // Don't let previous timers affect us post-reset.
72 weak_factory_.InvalidateWeakPtrs(); 74 weak_factory_.InvalidateWeakPtrs();
73 registered_types_ = registered_types; 75 registered_types_ = registered_types;
74 } 76 }
75 77
76 void StartupController::SetSetupInProgress(bool setup_in_progress) { 78 void StartupController::SetSetupInProgress(bool setup_in_progress) {
77 setup_in_progress_ = setup_in_progress; 79 setup_in_progress_ = setup_in_progress;
78 if (setup_in_progress_) { 80 if (setup_in_progress_) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 116 }
115 117
116 bool StartupController::TryStart() { 118 bool StartupController::TryStart() {
117 if (!can_start_.Run()) 119 if (!can_start_.Run())
118 return false; 120 return false;
119 121
120 // For performance reasons, defer the heavy lifting for sync init unless: 122 // For performance reasons, defer the heavy lifting for sync init unless:
121 // 123 //
122 // - a datatype has requested an immediate start of sync, or 124 // - a datatype has requested an immediate start of sync, or
123 // - sync needs to start up the backend immediately to provide control state 125 // - sync needs to start up the backend immediately to provide control state
124 // and encryption information to the UI, or 126 // and encryption information to the UI.
125 // - this is the first time sync is ever starting up. 127 // Do not start up the sync backend if setup has not completed and isn't
126 if (received_start_request_ || setup_in_progress_ || 128 // in progress, unless told to otherwise.
127 !sync_prefs_->IsFirstSetupComplete()) { 129 if (setup_in_progress_) {
128 return StartUp(STARTUP_IMMEDIATE); 130 return StartUp(STARTUP_IMMEDIATE);
131 } else if (sync_prefs_->IsFirstSetupComplete() || bypass_setup_complete_) {
132 return StartUp(received_start_request_ ? STARTUP_IMMEDIATE
133 : STARTUP_BACKEND_DEFERRED);
129 } else { 134 } else {
130 return StartUp(STARTUP_BACKEND_DEFERRED); 135 return false;
131 } 136 }
132 } 137 }
133 138
139 bool StartupController::TryStartImmediately() {
140 received_start_request_ = true;
141 bypass_setup_complete_ = true;
142 return TryStart();
143 }
144
134 void StartupController::RecordTimeDeferred() { 145 void StartupController::RecordTimeDeferred() {
135 DCHECK(!start_up_time_.is_null()); 146 DCHECK(!start_up_time_.is_null());
136 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; 147 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
137 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2", 148 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2",
138 time_deferred, 149 time_deferred,
139 base::TimeDelta::FromSeconds(0), 150 base::TimeDelta::FromSeconds(0),
140 base::TimeDelta::FromMinutes(2), 151 base::TimeDelta::FromMinutes(2),
141 60); 152 60);
142 } 153 }
143 154
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 syncer::MODEL_TYPE_COUNT); 200 syncer::MODEL_TYPE_COUNT);
190 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 201 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
191 TRIGGER_DATA_TYPE_REQUEST, 202 TRIGGER_DATA_TYPE_REQUEST,
192 MAX_TRIGGER_VALUE); 203 MAX_TRIGGER_VALUE);
193 } 204 }
194 received_start_request_ = true; 205 received_start_request_ = true;
195 TryStart(); 206 TryStart();
196 } 207 }
197 208
198 } // namespace browser_sync 209 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698