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

Side by Side Diff: chrome/browser/chromeos/boot_times_recorder.cc

Issue 2200703002: chromeos: Try to avoid shutdown crash in BootTimesRecorder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromeos/boot_times_recorder.h" 5 #include "chrome/browser/chromeos/boot_times_recorder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 (is_user_new ? kUmaLoginNewUser : kUmaLogin), 349 (is_user_new ? kUmaLoginNewUser : kUmaLogin),
350 kUmaLoginPrefix, 350 kUmaLoginPrefix,
351 login_time_markers_), 351 login_time_markers_),
352 base::TimeDelta::FromMilliseconds(kLoginTimeWriteDelayMs)); 352 base::TimeDelta::FromMilliseconds(kLoginTimeWriteDelayMs));
353 } 353 }
354 354
355 void BootTimesRecorder::WriteLogoutTimes() { 355 void BootTimesRecorder::WriteLogoutTimes() {
356 // Either we're on the browser thread, or (more likely) Chrome is in the 356 // Either we're on the browser thread, or (more likely) Chrome is in the
357 // process of shutting down and we're on the main thread but the message loop 357 // process of shutting down and we're on the main thread but the message loop
358 // has already been terminated. 358 // has already been terminated.
359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 359 DCHECK(!BrowserThread::IsMessageLoopValid(BrowserThread::UI) ||
360 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); 360 BrowserThread::CurrentlyOn(BrowserThread::UI));
361 361
362 WriteTimes(kLogoutTimes, 362 WriteTimes(kLogoutTimes,
363 (restart_requested_ ? kUmaRestart : kUmaLogout), 363 (restart_requested_ ? kUmaRestart : kUmaLogout),
364 kUmaLogoutPrefix, 364 kUmaLogoutPrefix,
365 logout_time_markers_); 365 logout_time_markers_);
366 } 366 }
367 367
368 // static 368 // static
369 void BootTimesRecorder::ClearLogoutStartedLastPreference() { 369 void BootTimesRecorder::ClearLogoutStartedLastPreference() {
370 PrefService* local_state = g_browser_process->local_state(); 370 PrefService* local_state = g_browser_process->local_state();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 bool send_to_uma) { 455 bool send_to_uma) {
456 AddMarker(&logout_time_markers_, TimeMarker(marker_name, send_to_uma)); 456 AddMarker(&logout_time_markers_, TimeMarker(marker_name, send_to_uma));
457 } 457 }
458 458
459 // static 459 // static
460 void BootTimesRecorder::AddMarker(std::vector<TimeMarker>* vector, 460 void BootTimesRecorder::AddMarker(std::vector<TimeMarker>* vector,
461 TimeMarker marker) { 461 TimeMarker marker) {
462 // The marker vectors can only be safely manipulated on the main thread. 462 // The marker vectors can only be safely manipulated on the main thread.
463 // If we're late in the process of shutting down (eg. as can be the case at 463 // If we're late in the process of shutting down (eg. as can be the case at
464 // logout), then we have to assume we're on the main thread already. 464 // logout), then we have to assume we're on the main thread already.
465 if (BrowserThread::CurrentlyOn(BrowserThread::UI) || 465 if (!BrowserThread::IsMessageLoopValid(BrowserThread::UI) ||
466 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)) { 466 BrowserThread::CurrentlyOn(BrowserThread::UI)) {
467 vector->push_back(marker); 467 vector->push_back(marker);
468 } else { 468 } else {
469 // Add the marker on the UI thread. 469 // Add the marker on the UI thread.
470 // Note that it's safe to use an unretained pointer to the vector because 470 // Note that it's safe to use an unretained pointer to the vector because
471 // BootTimesRecorder's lifetime exceeds that of the UI thread message loop. 471 // BootTimesRecorder's lifetime exceeds that of the UI thread message loop.
472 BrowserThread::PostTask( 472 BrowserThread::PostTask(
473 BrowserThread::UI, FROM_HERE, 473 BrowserThread::UI, FROM_HERE,
474 base::Bind(&BootTimesRecorder::AddMarker, 474 base::Bind(&BootTimesRecorder::AddMarker,
475 base::Unretained(vector), 475 base::Unretained(vector),
476 marker)); 476 marker));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 GetRenderWidgetHost(&web_contents->GetController()); 524 GetRenderWidgetHost(&web_contents->GetController());
525 render_widget_hosts_loading_.erase(render_widget_host); 525 render_widget_hosts_loading_.erase(render_widget_host);
526 break; 526 break;
527 } 527 }
528 default: 528 default:
529 break; 529 break;
530 } 530 }
531 } 531 }
532 532
533 } // namespace chromeos 533 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698