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

Side by Side Diff: chrome/browser/shell_integration.cc

Issue 1426663005: Make the histograms for setting the default browser consistent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 /////////////////////////////////////////////////////////////////////////////// 170 ///////////////////////////////////////////////////////////////////////////////
171 // ShellIntegration::DefaultWebClientWorker 171 // ShellIntegration::DefaultWebClientWorker
172 // 172 //
173 173
174 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( 174 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker(
175 DefaultWebClientObserver* observer) 175 DefaultWebClientObserver* observer)
176 : observer_(observer) {} 176 : observer_(observer) {}
177 177
178 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { 178 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() {
179 if (observer_) { 179 if (observer_) {
grt (UTC plus 2) 2015/11/03 21:12:21 nit: omit braces
Patrick Monette 2015/11/10 19:22:47 Done.
180 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); 180 observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
181 BrowserThread::PostTask(
182 BrowserThread::FILE, FROM_HERE,
183 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this));
184 } 181 }
182 BrowserThread::PostTask(
183 BrowserThread::FILE, FROM_HERE,
184 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this));
185 } 185 }
186 186
187 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { 187 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() {
188 // Cancel the already running process if another start is requested. 188 // Cancel the already running process if another start is requested.
189 if (set_as_default_in_progress_) { 189 if (set_as_default_in_progress_) {
190 if (set_as_default_initialized_) { 190 if (set_as_default_initialized_) {
191 FinalizeSetAsDefault(); 191 FinalizeSetAsDefault();
192 set_as_default_initialized_ = false; 192 set_as_default_initialized_ = false;
193 } 193 }
194 194
195 ReportAttemptResult(AttemptResult::RETRY); 195 ReportAttemptResult(AttemptResult::RETRY);
196 } 196 }
197 197
198 set_as_default_in_progress_ = true; 198 set_as_default_in_progress_ = true;
199 bool interactive_permitted = false; 199 bool interactive_permitted = true;
200 if (observer_) { 200 if (observer_) {
201 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); 201 observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
202 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); 202 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted();
203 }
203 204
204 // The initialization is only useful when there is an observer. 205 set_as_default_initialized_ = InitializeSetAsDefault();
205 set_as_default_initialized_ = InitializeSetAsDefault();
206 }
207 206
208 // Remember the start time. 207 // Remember the start time.
209 start_time_ = base::TimeTicks::Now(); 208 start_time_ = base::TimeTicks::Now();
210 209
211 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 210 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
212 base::Bind(&DefaultWebClientWorker::SetAsDefault, 211 base::Bind(&DefaultWebClientWorker::SetAsDefault,
213 this, interactive_permitted)); 212 this, interactive_permitted));
214 } 213 }
215 214
216 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { 215 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() {
(...skipping 13 matching lines...) Expand all
230 229
231 /////////////////////////////////////////////////////////////////////////////// 230 ///////////////////////////////////////////////////////////////////////////////
232 // DefaultWebClientWorker, private: 231 // DefaultWebClientWorker, private:
233 232
234 ShellIntegration::DefaultWebClientWorker::~DefaultWebClientWorker() {} 233 ShellIntegration::DefaultWebClientWorker::~DefaultWebClientWorker() {}
235 234
236 void ShellIntegration::DefaultWebClientWorker::OnCheckIsDefaultComplete( 235 void ShellIntegration::DefaultWebClientWorker::OnCheckIsDefaultComplete(
237 DefaultWebClientState state) { 236 DefaultWebClientState state) {
238 DCHECK_CURRENTLY_ON(BrowserThread::UI); 237 DCHECK_CURRENTLY_ON(BrowserThread::UI);
239 UpdateUI(state); 238 UpdateUI(state);
239
240 #if defined(OS_WIN)
grt (UTC plus 2) 2015/11/03 21:12:21 how about doing this for all platforms?
Patrick Monette 2015/11/10 19:22:47 Done.
241 if (check_default_should_report_success_) {
242 check_default_should_report_success_ = false;
243
244 ReportAttemptResult(state == DefaultWebClientState::IS_DEFAULT
245 ? AttemptResult::SUCCESS
246 : AttemptResult::NO_ERRORS_NOT_DEFAULT);
247 }
248 #endif // defined(OS_WIN)
249
240 // The worker has finished everything it needs to do, so free the observer 250 // The worker has finished everything it needs to do, so free the observer
241 // if we own it. 251 // if we own it.
242 if (observer_ && observer_->IsOwnedByWorker()) { 252 if (observer_ && observer_->IsOwnedByWorker()) {
243 delete observer_; 253 delete observer_;
244 observer_ = nullptr; 254 observer_ = nullptr;
245 } 255 }
246 } 256 }
247 257
248 void ShellIntegration::DefaultWebClientWorker::OnSetAsDefaultAttemptComplete( 258 void ShellIntegration::DefaultWebClientWorker::OnSetAsDefaultAttemptComplete(
249 AttemptResult result) { 259 AttemptResult result) {
(...skipping 10 matching lines...) Expand all
260 if (set_as_default_initialized_) { 270 if (set_as_default_initialized_) {
261 FinalizeSetAsDefault(); 271 FinalizeSetAsDefault();
262 set_as_default_initialized_ = false; 272 set_as_default_initialized_ = false;
263 } 273 }
264 if (observer_) { 274 if (observer_) {
265 bool succeeded = result == AttemptResult::SUCCESS || 275 bool succeeded = result == AttemptResult::SUCCESS ||
266 result == AttemptResult::ALREADY_DEFAULT; 276 result == AttemptResult::ALREADY_DEFAULT;
267 observer_->OnSetAsDefaultConcluded(succeeded); 277 observer_->OnSetAsDefaultConcluded(succeeded);
268 } 278 }
269 279
270 ReportAttemptResult(result); 280 // We don't report a success yet because we have to make sure Chrome is the
grt (UTC plus 2) 2015/11/03 21:12:21 nit: avoid "we" in comments. how about "Report fai
Patrick Monette 2015/11/10 19:22:47 Done.
281 // default browser first.
282 check_default_should_report_success_ = result == AttemptResult::SUCCESS;
283 if (!check_default_should_report_success_) {
grt (UTC plus 2) 2015/11/03 21:12:21 nit: omit braces
Patrick Monette 2015/11/10 19:22:47 Done.
284 ReportAttemptResult(result);
285 }
271 286
272 // Start the default browser check which will notify the observer as to 287 // Start the default browser check which will notify the observer as to
273 // whether Chrome is really the default browser. This is needed because 288 // whether Chrome is really the default browser. This is needed because
274 // detecting that the process was successful is not 100% sure. 289 // detecting that the process was successful is not 100% sure.
275 // For example, on Windows 10+, the user might have unchecked the "Always 290 // For example, on Windows 10+, the user might have unchecked the "Always
276 // use this app" checkbox which can't be detected. 291 // use this app" checkbox which can't be detected.
277 StartCheckIsDefault(); 292 StartCheckIsDefault();
278 } 293 }
279 } 294 }
280 295
281 void ShellIntegration::DefaultWebClientWorker::ReportAttemptResult( 296 void ShellIntegration::DefaultWebClientWorker::ReportAttemptResult(
grt (UTC plus 2) 2015/11/03 21:12:22 this records results for both DefaultBrowserWorker
Patrick Monette 2015/11/10 19:22:47 Done.
282 AttemptResult result) { 297 AttemptResult result) {
283 if (!ShouldReportAttemptResults()) 298 if (!ShouldReportAttemptResults())
284 return; 299 return;
285 300
286 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.AsyncSetAsDefault.Result", result, 301 UMA_HISTOGRAM_ENUMERATION("SetDefaultBrowser.Result", result,
grt (UTC plus 2) 2015/11/03 21:12:21 how about recording this for all platforms? is the
Patrick Monette 2015/11/10 19:22:47 Done.
287 AttemptResult::NUM_ATTEMPT_RESULT_TYPES); 302 AttemptResult::NUM_ATTEMPT_RESULT_TYPES);
288 303
289 switch (result) { 304 if (IsSetAsDefaultAsynchronous()) {
290 case SUCCESS: 305 switch (result) {
grt (UTC plus 2) 2015/11/03 21:12:21 const base::TimeTicks delta = base::TimeTicks::Now
Patrick Monette 2015/11/10 19:22:47 Done.
291 UMA_HISTOGRAM_MEDIUM_TIMES( 306 case SUCCESS:
292 "DefaultBrowser.AsyncSetAsDefault.Duration_Success", 307 UMA_HISTOGRAM_MEDIUM_TIMES("SetDefaultBrowser.AsyncDuration_Success",
293 base::TimeTicks::Now() - start_time_); 308 base::TimeTicks::Now() - start_time_);
grt (UTC plus 2) 2015/11/03 21:12:21 delta
Patrick Monette 2015/11/10 19:22:47 Done.
294 break; 309 break;
295 case FAILURE: 310 case FAILURE:
296 UMA_HISTOGRAM_MEDIUM_TIMES( 311 UMA_HISTOGRAM_MEDIUM_TIMES("SetDefaultBrowser.AsyncDuration_Failure",
297 "DefaultBrowser.AsyncSetAsDefault.Duration_Failure", 312 base::TimeTicks::Now() - start_time_);
298 base::TimeTicks::Now() - start_time_); 313 break;
299 break; 314 case ABANDONED:
300 case ABANDONED: 315 UMA_HISTOGRAM_MEDIUM_TIMES("SetDefaultBrowser.AsyncDuration_Abandoned",
301 UMA_HISTOGRAM_MEDIUM_TIMES( 316 base::TimeTicks::Now() - start_time_);
302 "DefaultBrowser.AsyncSetAsDefault.Duration_Abandoned", 317 break;
303 base::TimeTicks::Now() - start_time_); 318 case RETRY:
304 break; 319 UMA_HISTOGRAM_MEDIUM_TIMES("SetDefaultBrowser.AsyncDuration_Retry",
305 case RETRY: 320 base::TimeTicks::Now() - start_time_);
306 UMA_HISTOGRAM_MEDIUM_TIMES( 321 break;
307 "DefaultBrowser.AsyncSetAsDefault.Duration_Retry", 322 case NO_ERRORS_NOT_DEFAULT:
308 base::TimeTicks::Now() - start_time_); 323 UMA_HISTOGRAM_MEDIUM_TIMES(
309 break; 324 "SetDefaultBrowser.AsyncDuration_NoErrorsNotDefault",
310 default: 325 base::TimeTicks::Now() - start_time_);
311 break; 326 break;
327 default:
328 break;
329 }
312 } 330 }
313 } 331 }
314 332
315 bool ShellIntegration::DefaultWebClientWorker::InitializeSetAsDefault() { 333 bool ShellIntegration::DefaultWebClientWorker::InitializeSetAsDefault() {
316 return true; 334 return true;
317 } 335 }
318 336
319 void ShellIntegration::DefaultWebClientWorker::FinalizeSetAsDefault() {} 337 void ShellIntegration::DefaultWebClientWorker::FinalizeSetAsDefault() {}
320 338
321 #if !defined(OS_WIN)
322 // static 339 // static
323 bool ShellIntegration::DefaultWebClientWorker::ShouldReportAttemptResults() { 340 bool ShellIntegration::DefaultWebClientWorker::ShouldReportAttemptResults() {
341 #if defined(OS_WIN)
342 return true;
343 #else // !defined(OS_WIN)
324 return false; 344 return false;
345 #endif
325 } 346 }
326 #endif // !defined(OS_WIN)
327 347
328 void ShellIntegration::DefaultWebClientWorker::UpdateUI( 348 void ShellIntegration::DefaultWebClientWorker::UpdateUI(
329 DefaultWebClientState state) { 349 DefaultWebClientState state) {
330 if (observer_) { 350 if (observer_) {
331 switch (state) { 351 switch (state) {
332 case NOT_DEFAULT: 352 case NOT_DEFAULT:
333 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); 353 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT);
334 break; 354 break;
335 case IS_DEFAULT: 355 case IS_DEFAULT:
336 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT); 356 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 break; 470 break;
451 case SET_DEFAULT_ASYNCHRONOUS: 471 case SET_DEFAULT_ASYNCHRONOUS:
452 NOTREACHED(); 472 NOTREACHED();
453 break; 473 break;
454 } 474 }
455 BrowserThread::PostTask( 475 BrowserThread::PostTask(
456 BrowserThread::UI, FROM_HERE, 476 BrowserThread::UI, FROM_HERE,
457 base::Bind(&DefaultProtocolClientWorker::OnSetAsDefaultAttemptComplete, 477 base::Bind(&DefaultProtocolClientWorker::OnSetAsDefaultAttemptComplete,
458 this, result)); 478 this, result));
459 } 479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698