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: chrome/browser/sync/startup_controller.cc

Issue 183563004: sync: reland deferred init (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review 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
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 "chrome/browser/sync/startup_controller.h" 5 #include "chrome/browser/sync/startup_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" 11 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service.h"
12 #include "chrome/browser/sync/sync_prefs.h" 13 #include "chrome/browser/sync/sync_prefs.h"
13 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
14 15
15 namespace browser_sync { 16 namespace browser_sync {
16 17
17 namespace { 18 namespace {
18 19
19 // The amount of time we'll wait to initialize sync if no data type triggers 20 // The amount of time we'll wait to initialize sync if no data type triggers
(...skipping 19 matching lines...) Expand all
39 const browser_sync::SyncPrefs* sync_prefs, 40 const browser_sync::SyncPrefs* sync_prefs,
40 const ManagedUserSigninManagerWrapper* signin, 41 const ManagedUserSigninManagerWrapper* signin,
41 base::Closure start_backend) 42 base::Closure start_backend)
42 : received_start_request_(false), 43 : received_start_request_(false),
43 setup_in_progress_(false), 44 setup_in_progress_(false),
44 auto_start_enabled_(start_behavior == AUTO_START), 45 auto_start_enabled_(start_behavior == AUTO_START),
45 sync_prefs_(sync_prefs), 46 sync_prefs_(sync_prefs),
46 token_service_(token_service), 47 token_service_(token_service),
47 signin_(signin), 48 signin_(signin),
48 start_backend_(start_backend), 49 start_backend_(start_backend),
49 fallback_timeout_( 50 fallback_timeout_(base::TimeDelta::FromSeconds(
50 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), 51 kDeferredInitFallbackSeconds)),
51 weak_factory_(this) {} 52 weak_factory_(this) {
53
54 if (CommandLine::ForCurrentProcess()->HasSwitch(
55 switches::kSyncDeferredStartupTimeoutSeconds)) {
56 int timeout = kDeferredInitFallbackSeconds;
57 if (base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
58 switches::kSyncDeferredStartupTimeoutSeconds), &timeout)) {
59 DCHECK_GE(0, timeout);
60 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout);
rlarocque 2014/03/07 20:49:22 nit: I'd recommend adding a log message here. Bec
tim (not reviewing) 2014/03/07 20:59:29 Done.
61 }
62 }
63 }
52 64
53 StartupController::~StartupController() {} 65 StartupController::~StartupController() {}
54 66
55 void StartupController::Reset(const syncer::ModelTypeSet registered_types) { 67 void StartupController::Reset(const syncer::ModelTypeSet registered_types) {
56 received_start_request_ = false; 68 received_start_request_ = false;
57 setup_in_progress_ = false; 69 setup_in_progress_ = false;
58 start_up_time_ = base::Time(); 70 start_up_time_ = base::Time();
59 start_backend_time_ = base::Time(); 71 start_backend_time_ = base::Time();
60 // Don't let previous timers affect us post-reset. 72 // Don't let previous timers affect us post-reset.
61 weak_factory_.InvalidateWeakPtrs(); 73 weak_factory_.InvalidateWeakPtrs();
62 registered_types_ = registered_types; 74 registered_types_ = registered_types;
63 } 75 }
64 76
65 void StartupController::set_setup_in_progress(bool in_progress) { 77 void StartupController::set_setup_in_progress(bool in_progress) {
66 setup_in_progress_ = in_progress; 78 setup_in_progress_ = in_progress;
67 } 79 }
68 80
69 bool StartupController::StartUp(StartUpDeferredOption deferred_option) { 81 bool StartupController::StartUp(StartUpDeferredOption deferred_option) {
70 const bool first_start = start_up_time_.is_null(); 82 const bool first_start = start_up_time_.is_null();
71 if (first_start) 83 if (first_start)
72 start_up_time_ = base::Time::Now(); 84 start_up_time_ = base::Time::Now();
73 85
74 if (deferred_option == STARTUP_BACKEND_DEFERRED && 86 if (deferred_option == STARTUP_BACKEND_DEFERRED &&
75 CommandLine::ForCurrentProcess()->HasSwitch( 87 !CommandLine::ForCurrentProcess()->HasSwitch(
76 switches::kSyncEnableDeferredStartup) && 88 switches::kSyncDisableDeferredStartup) &&
77 sync_prefs_->GetPreferredDataTypes(registered_types_) 89 sync_prefs_->GetPreferredDataTypes(registered_types_)
78 .Has(syncer::SESSIONS)) { 90 .Has(syncer::SESSIONS)) {
79 if (first_start) { 91 if (first_start) {
80 base::MessageLoop::current()->PostDelayedTask( 92 base::MessageLoop::current()->PostDelayedTask(
81 FROM_HERE, 93 FROM_HERE,
82 base::Bind(&StartupController::OnFallbackStartupTimerExpired, 94 base::Bind(&StartupController::OnFallbackStartupTimerExpired,
83 weak_factory_.GetWeakPtr()), fallback_timeout_); 95 weak_factory_.GetWeakPtr()), fallback_timeout_);
84 } 96 }
85 return false; 97 return false;
86 } 98 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } else if (setup_in_progress_ || auto_start_enabled_) { 157 } else if (setup_in_progress_ || auto_start_enabled_) {
146 // We haven't completed sync setup. Start immediately if the user explicitly 158 // We haven't completed sync setup. Start immediately if the user explicitly
147 // kicked this off or we're supposed to automatically start syncing. 159 // kicked this off or we're supposed to automatically start syncing.
148 return StartUp(STARTUP_IMMEDIATE); 160 return StartUp(STARTUP_IMMEDIATE);
149 } 161 }
150 162
151 return false; 163 return false;
152 } 164 }
153 165
154 void StartupController::OnFallbackStartupTimerExpired() { 166 void StartupController::OnFallbackStartupTimerExpired() {
155 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch( 167 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
156 switches::kSyncEnableDeferredStartup)); 168 switches::kSyncDisableDeferredStartup));
157 169
158 if (!start_backend_time_.is_null()) 170 if (!start_backend_time_.is_null())
159 return; 171 return;
160 172
161 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; 173 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend.";
162 DCHECK(!start_up_time_.is_null()); 174 DCHECK(!start_up_time_.is_null());
163 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; 175 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
164 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); 176 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred);
165 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 177 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
166 TRIGGER_FALLBACK_TIMER, 178 TRIGGER_FALLBACK_TIMER,
167 MAX_TRIGGER_VALUE); 179 MAX_TRIGGER_VALUE);
168 received_start_request_ = true; 180 received_start_request_ = true;
169 TryStart(); 181 TryStart();
170 } 182 }
171 183
172 std::string StartupController::GetBackendInitializationStateString() const { 184 std::string StartupController::GetBackendInitializationStateString() const {
173 if (!start_backend_time_.is_null()) 185 if (!start_backend_time_.is_null())
174 return "Started"; 186 return "Started";
175 else if (!start_up_time_.is_null()) 187 else if (!start_up_time_.is_null())
176 return "Deferred"; 188 return "Deferred";
177 else 189 else
178 return "Not started"; 190 return "Not started";
179 } 191 }
180 192
181 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) { 193 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) {
182 if (!CommandLine::ForCurrentProcess()->HasSwitch( 194 if (CommandLine::ForCurrentProcess()->HasSwitch(
183 switches::kSyncEnableDeferredStartup)) { 195 switches::kSyncDisableDeferredStartup)) {
184 DVLOG(2) << "Ignoring data type request for sync startup: " 196 DVLOG(2) << "Ignoring data type request for sync startup: "
185 << syncer::ModelTypeToString(type); 197 << syncer::ModelTypeToString(type);
186 return; 198 return;
187 } 199 }
188 200
189 if (!start_backend_time_.is_null()) 201 if (!start_backend_time_.is_null())
190 return; 202 return;
191 203
192 DVLOG(2) << "Data type requesting sync startup: " 204 DVLOG(2) << "Data type requesting sync startup: "
193 << syncer::ModelTypeToString(type); 205 << syncer::ModelTypeToString(type);
194 // Measure the time spent waiting for init and the type that triggered it. 206 // Measure the time spent waiting for init and the type that triggered it.
195 // We could measure the time spent deferred on a per-datatype basis, but 207 // We could measure the time spent deferred on a per-datatype basis, but
196 // for now this is probably sufficient. 208 // for now this is probably sufficient.
197 if (!start_up_time_.is_null()) { 209 if (!start_up_time_.is_null()) {
198 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; 210 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
199 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); 211 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred);
200 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", 212 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit",
201 ModelTypeToHistogramInt(type), 213 ModelTypeToHistogramInt(type),
202 syncer::MODEL_TYPE_COUNT); 214 syncer::MODEL_TYPE_COUNT);
203 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 215 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
204 TRIGGER_DATA_TYPE_REQUEST, 216 TRIGGER_DATA_TYPE_REQUEST,
205 MAX_TRIGGER_VALUE); 217 MAX_TRIGGER_VALUE);
206 } 218 }
207 received_start_request_ = true; 219 received_start_request_ = true;
208 TryStart(); 220 TryStart();
209 } 221 }
210 222
211 } // namespace browser_sync 223 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/android/host_driven_tests/SyncTest.py ('k') | chrome/browser/sync/startup_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698