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

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: override timeout 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 weak_factory_(this) {
50 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), 51
51 weak_factory_(this) {} 52 int timeout = kDeferredInitFallbackSeconds;
53 if (CommandLine::ForCurrentProcess()->HasSwitch(
54 switches::kSyncDeferredStartupTimeoutSeconds)) {
55 base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
rlarocque 2014/03/07 20:00:27 Could you check the return value? And maybe sanit
56 switches::kSyncDeferredStartupTimeoutSeconds), &timeout);
57 }
58
59 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout);
60 }
52 61
53 StartupController::~StartupController() {} 62 StartupController::~StartupController() {}
54 63
55 void StartupController::Reset(const syncer::ModelTypeSet registered_types) { 64 void StartupController::Reset(const syncer::ModelTypeSet registered_types) {
56 received_start_request_ = false; 65 received_start_request_ = false;
57 setup_in_progress_ = false; 66 setup_in_progress_ = false;
58 start_up_time_ = base::Time(); 67 start_up_time_ = base::Time();
59 start_backend_time_ = base::Time(); 68 start_backend_time_ = base::Time();
60 // Don't let previous timers affect us post-reset. 69 // Don't let previous timers affect us post-reset.
61 weak_factory_.InvalidateWeakPtrs(); 70 weak_factory_.InvalidateWeakPtrs();
62 registered_types_ = registered_types; 71 registered_types_ = registered_types;
63 } 72 }
64 73
65 void StartupController::set_setup_in_progress(bool in_progress) { 74 void StartupController::set_setup_in_progress(bool in_progress) {
66 setup_in_progress_ = in_progress; 75 setup_in_progress_ = in_progress;
67 } 76 }
68 77
69 bool StartupController::StartUp(StartUpDeferredOption deferred_option) { 78 bool StartupController::StartUp(StartUpDeferredOption deferred_option) {
70 const bool first_start = start_up_time_.is_null(); 79 const bool first_start = start_up_time_.is_null();
71 if (first_start) 80 if (first_start)
72 start_up_time_ = base::Time::Now(); 81 start_up_time_ = base::Time::Now();
73 82
74 if (deferred_option == STARTUP_BACKEND_DEFERRED && 83 if (deferred_option == STARTUP_BACKEND_DEFERRED &&
75 CommandLine::ForCurrentProcess()->HasSwitch( 84 !CommandLine::ForCurrentProcess()->HasSwitch(
76 switches::kSyncEnableDeferredStartup) && 85 switches::kSyncDisableDeferredStartup) &&
77 sync_prefs_->GetPreferredDataTypes(registered_types_) 86 sync_prefs_->GetPreferredDataTypes(registered_types_)
78 .Has(syncer::SESSIONS)) { 87 .Has(syncer::SESSIONS)) {
79 if (first_start) { 88 if (first_start) {
80 base::MessageLoop::current()->PostDelayedTask( 89 base::MessageLoop::current()->PostDelayedTask(
81 FROM_HERE, 90 FROM_HERE,
82 base::Bind(&StartupController::OnFallbackStartupTimerExpired, 91 base::Bind(&StartupController::OnFallbackStartupTimerExpired,
83 weak_factory_.GetWeakPtr()), fallback_timeout_); 92 weak_factory_.GetWeakPtr()), fallback_timeout_);
84 } 93 }
85 return false; 94 return false;
86 } 95 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } else if (setup_in_progress_ || auto_start_enabled_) { 154 } else if (setup_in_progress_ || auto_start_enabled_) {
146 // We haven't completed sync setup. Start immediately if the user explicitly 155 // We haven't completed sync setup. Start immediately if the user explicitly
147 // kicked this off or we're supposed to automatically start syncing. 156 // kicked this off or we're supposed to automatically start syncing.
148 return StartUp(STARTUP_IMMEDIATE); 157 return StartUp(STARTUP_IMMEDIATE);
149 } 158 }
150 159
151 return false; 160 return false;
152 } 161 }
153 162
154 void StartupController::OnFallbackStartupTimerExpired() { 163 void StartupController::OnFallbackStartupTimerExpired() {
155 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch( 164 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
156 switches::kSyncEnableDeferredStartup)); 165 switches::kSyncDisableDeferredStartup));
157 166
158 if (!start_backend_time_.is_null()) 167 if (!start_backend_time_.is_null())
159 return; 168 return;
160 169
161 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; 170 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend.";
162 DCHECK(!start_up_time_.is_null()); 171 DCHECK(!start_up_time_.is_null());
163 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; 172 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
164 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); 173 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred);
165 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 174 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
166 TRIGGER_FALLBACK_TIMER, 175 TRIGGER_FALLBACK_TIMER,
167 MAX_TRIGGER_VALUE); 176 MAX_TRIGGER_VALUE);
168 received_start_request_ = true; 177 received_start_request_ = true;
169 TryStart(); 178 TryStart();
170 } 179 }
171 180
172 std::string StartupController::GetBackendInitializationStateString() const { 181 std::string StartupController::GetBackendInitializationStateString() const {
173 if (!start_backend_time_.is_null()) 182 if (!start_backend_time_.is_null())
174 return "Started"; 183 return "Started";
175 else if (!start_up_time_.is_null()) 184 else if (!start_up_time_.is_null())
176 return "Deferred"; 185 return "Deferred";
177 else 186 else
178 return "Not started"; 187 return "Not started";
179 } 188 }
180 189
181 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) { 190 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) {
182 if (!CommandLine::ForCurrentProcess()->HasSwitch( 191 if (CommandLine::ForCurrentProcess()->HasSwitch(
183 switches::kSyncEnableDeferredStartup)) { 192 switches::kSyncDisableDeferredStartup)) {
184 DVLOG(2) << "Ignoring data type request for sync startup: " 193 DVLOG(2) << "Ignoring data type request for sync startup: "
185 << syncer::ModelTypeToString(type); 194 << syncer::ModelTypeToString(type);
186 return; 195 return;
187 } 196 }
188 197
189 if (!start_backend_time_.is_null()) 198 if (!start_backend_time_.is_null())
190 return; 199 return;
191 200
192 DVLOG(2) << "Data type requesting sync startup: " 201 DVLOG(2) << "Data type requesting sync startup: "
193 << syncer::ModelTypeToString(type); 202 << syncer::ModelTypeToString(type);
194 // Measure the time spent waiting for init and the type that triggered it. 203 // 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 204 // We could measure the time spent deferred on a per-datatype basis, but
196 // for now this is probably sufficient. 205 // for now this is probably sufficient.
197 if (!start_up_time_.is_null()) { 206 if (!start_up_time_.is_null()) {
198 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; 207 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
199 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); 208 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred);
200 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", 209 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit",
201 ModelTypeToHistogramInt(type), 210 ModelTypeToHistogramInt(type),
202 syncer::MODEL_TYPE_COUNT); 211 syncer::MODEL_TYPE_COUNT);
203 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 212 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
204 TRIGGER_DATA_TYPE_REQUEST, 213 TRIGGER_DATA_TYPE_REQUEST,
205 MAX_TRIGGER_VALUE); 214 MAX_TRIGGER_VALUE);
206 } 215 }
207 received_start_request_ = true; 216 received_start_request_ = true;
208 TryStart(); 217 TryStart();
209 } 218 }
210 219
211 } // namespace browser_sync 220 } // 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