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

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

Issue 816403003: Make callers of CommandLine use it via the base:: namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years 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 "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 "base/strings/string_number_conversions.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 setup_in_progress_(false), 44 setup_in_progress_(false),
45 auto_start_enabled_(start_behavior == AUTO_START), 45 auto_start_enabled_(start_behavior == AUTO_START),
46 sync_prefs_(sync_prefs), 46 sync_prefs_(sync_prefs),
47 token_service_(token_service), 47 token_service_(token_service),
48 signin_(signin), 48 signin_(signin),
49 start_backend_(start_backend), 49 start_backend_(start_backend),
50 fallback_timeout_( 50 fallback_timeout_(
51 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), 51 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)),
52 first_start_(true), 52 first_start_(true),
53 weak_factory_(this) { 53 weak_factory_(this) {
54 54 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
55 if (CommandLine::ForCurrentProcess()->HasSwitch(
56 switches::kSyncDeferredStartupTimeoutSeconds)) { 55 switches::kSyncDeferredStartupTimeoutSeconds)) {
57 int timeout = kDeferredInitFallbackSeconds; 56 int timeout = kDeferredInitFallbackSeconds;
58 if (base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 57 if (base::StringToInt(
59 switches::kSyncDeferredStartupTimeoutSeconds), &timeout)) { 58 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
59 switches::kSyncDeferredStartupTimeoutSeconds),
60 &timeout)) {
60 DCHECK_GE(timeout, 0); 61 DCHECK_GE(timeout, 0);
61 DVLOG(2) << "Sync StartupController overriding startup timeout to " 62 DVLOG(2) << "Sync StartupController overriding startup timeout to "
62 << timeout << " seconds."; 63 << timeout << " seconds.";
63 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout); 64 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout);
64 } 65 }
65 } 66 }
66 } 67 }
67 68
68 StartupController::~StartupController() {} 69 StartupController::~StartupController() {}
69 70
70 void StartupController::Reset(const syncer::ModelTypeSet registered_types) { 71 void StartupController::Reset(const syncer::ModelTypeSet registered_types) {
71 received_start_request_ = false; 72 received_start_request_ = false;
72 start_up_time_ = base::Time(); 73 start_up_time_ = base::Time();
73 start_backend_time_ = base::Time(); 74 start_backend_time_ = base::Time();
74 // Don't let previous timers affect us post-reset. 75 // Don't let previous timers affect us post-reset.
75 weak_factory_.InvalidateWeakPtrs(); 76 weak_factory_.InvalidateWeakPtrs();
76 registered_types_ = registered_types; 77 registered_types_ = registered_types;
77 } 78 }
78 79
79 void StartupController::set_setup_in_progress(bool in_progress) { 80 void StartupController::set_setup_in_progress(bool in_progress) {
80 setup_in_progress_ = in_progress; 81 setup_in_progress_ = in_progress;
81 } 82 }
82 83
83 bool StartupController::StartUp(StartUpDeferredOption deferred_option) { 84 bool StartupController::StartUp(StartUpDeferredOption deferred_option) {
84 const bool first_start = start_up_time_.is_null(); 85 const bool first_start = start_up_time_.is_null();
85 if (first_start) 86 if (first_start)
86 start_up_time_ = base::Time::Now(); 87 start_up_time_ = base::Time::Now();
87 88
88 if (deferred_option == STARTUP_BACKEND_DEFERRED && 89 if (deferred_option == STARTUP_BACKEND_DEFERRED &&
89 !CommandLine::ForCurrentProcess()->HasSwitch( 90 !base::CommandLine::ForCurrentProcess()->HasSwitch(
90 switches::kSyncDisableDeferredStartup) && 91 switches::kSyncDisableDeferredStartup) &&
91 sync_prefs_->GetPreferredDataTypes(registered_types_) 92 sync_prefs_->GetPreferredDataTypes(registered_types_)
92 .Has(syncer::SESSIONS)) { 93 .Has(syncer::SESSIONS)) {
93 if (first_start) { 94 if (first_start) {
94 base::MessageLoop::current()->PostDelayedTask( 95 base::MessageLoop::current()->PostDelayedTask(
95 FROM_HERE, 96 FROM_HERE,
96 base::Bind(&StartupController::OnFallbackStartupTimerExpired, 97 base::Bind(&StartupController::OnFallbackStartupTimerExpired,
97 weak_factory_.GetWeakPtr()), fallback_timeout_); 98 weak_factory_.GetWeakPtr()), fallback_timeout_);
98 } 99 }
99 return false; 100 return false;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 DCHECK(!start_up_time_.is_null()); 176 DCHECK(!start_up_time_.is_null());
176 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; 177 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
177 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2", 178 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2",
178 time_deferred, 179 time_deferred,
179 base::TimeDelta::FromSeconds(0), 180 base::TimeDelta::FromSeconds(0),
180 base::TimeDelta::FromMinutes(2), 181 base::TimeDelta::FromMinutes(2),
181 60); 182 60);
182 } 183 }
183 184
184 void StartupController::OnFallbackStartupTimerExpired() { 185 void StartupController::OnFallbackStartupTimerExpired() {
185 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( 186 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
186 switches::kSyncDisableDeferredStartup)); 187 switches::kSyncDisableDeferredStartup));
187 188
188 if (!start_backend_time_.is_null()) 189 if (!start_backend_time_.is_null())
189 return; 190 return;
190 191
191 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; 192 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend.";
192 RecordTimeDeferred(); 193 RecordTimeDeferred();
193 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 194 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
194 TRIGGER_FALLBACK_TIMER, 195 TRIGGER_FALLBACK_TIMER,
195 MAX_TRIGGER_VALUE); 196 MAX_TRIGGER_VALUE);
196 received_start_request_ = true; 197 received_start_request_ = true;
197 TryStart(); 198 TryStart();
198 } 199 }
199 200
200 std::string StartupController::GetBackendInitializationStateString() const { 201 std::string StartupController::GetBackendInitializationStateString() const {
201 if (!start_backend_time_.is_null()) 202 if (!start_backend_time_.is_null())
202 return "Started"; 203 return "Started";
203 else if (!start_up_time_.is_null()) 204 else if (!start_up_time_.is_null())
204 return "Deferred"; 205 return "Deferred";
205 else 206 else
206 return "Not started"; 207 return "Not started";
207 } 208 }
208 209
209 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) { 210 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) {
210 if (CommandLine::ForCurrentProcess()->HasSwitch( 211 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
211 switches::kSyncDisableDeferredStartup)) { 212 switches::kSyncDisableDeferredStartup)) {
212 DVLOG(2) << "Ignoring data type request for sync startup: " 213 DVLOG(2) << "Ignoring data type request for sync startup: "
213 << syncer::ModelTypeToString(type); 214 << syncer::ModelTypeToString(type);
214 return; 215 return;
215 } 216 }
216 217
217 if (!start_backend_time_.is_null()) 218 if (!start_backend_time_.is_null())
218 return; 219 return;
219 220
220 DVLOG(2) << "Data type requesting sync startup: " 221 DVLOG(2) << "Data type requesting sync startup: "
221 << syncer::ModelTypeToString(type); 222 << syncer::ModelTypeToString(type);
222 // Measure the time spent waiting for init and the type that triggered it. 223 // Measure the time spent waiting for init and the type that triggered it.
223 // We could measure the time spent deferred on a per-datatype basis, but 224 // We could measure the time spent deferred on a per-datatype basis, but
224 // for now this is probably sufficient. 225 // for now this is probably sufficient.
225 if (!start_up_time_.is_null()) { 226 if (!start_up_time_.is_null()) {
226 RecordTimeDeferred(); 227 RecordTimeDeferred();
227 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", 228 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit",
228 ModelTypeToHistogramInt(type), 229 ModelTypeToHistogramInt(type),
229 syncer::MODEL_TYPE_COUNT); 230 syncer::MODEL_TYPE_COUNT);
230 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 231 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
231 TRIGGER_DATA_TYPE_REQUEST, 232 TRIGGER_DATA_TYPE_REQUEST,
232 MAX_TRIGGER_VALUE); 233 MAX_TRIGGER_VALUE);
233 } 234 }
234 received_start_request_ = true; 235 received_start_request_ = true;
235 TryStart(); 236 TryStart();
236 } 237 }
237 238
238 } // namespace browser_sync 239 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_unittest.cc ('k') | chrome/browser/sync/startup_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698