| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_loader.h" | 5 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 15 #include "base/singleton.h" | |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/thread.h" | 19 #include "base/thread.h" |
| 20 #include "base/thread_restrictions.h" | 20 #include "base/thread_restrictions.h" |
| 21 #include "base/time.h" | 21 #include "base/time.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/browser_thread.h" | 23 #include "chrome/browser/browser_thread.h" |
| 24 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | 24 #include "chrome/browser/chromeos/login/authentication_notification_details.h" |
| 25 #include "chrome/browser/chromeos/login/user_manager.h" | 25 #include "chrome/browser/chromeos/login/user_manager.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 55 static const char kUmaLoginPrefix[] = "BootTime."; | 55 static const char kUmaLoginPrefix[] = "BootTime."; |
| 56 static const char kUmaLogout[] = "ShutdownTime.Logout"; | 56 static const char kUmaLogout[] = "ShutdownTime.Logout"; |
| 57 static const char kUmaLogoutPrefix[] = "ShutdownTime."; | 57 static const char kUmaLogoutPrefix[] = "ShutdownTime."; |
| 58 | 58 |
| 59 // Name of file collecting login times. | 59 // Name of file collecting login times. |
| 60 static const FilePath::CharType kLoginTimes[] = FPL("login-times-sent"); | 60 static const FilePath::CharType kLoginTimes[] = FPL("login-times-sent"); |
| 61 | 61 |
| 62 // Name of file collecting logout times. | 62 // Name of file collecting logout times. |
| 63 static const char kLogoutTimes[] = "logout-times-sent"; | 63 static const char kLogoutTimes[] = "logout-times-sent"; |
| 64 | 64 |
| 65 static base::LazyInstance<BootTimesLoader> g_boot_times_loader( |
| 66 base::LINKER_INITIALIZED); |
| 67 |
| 65 BootTimesLoader::BootTimesLoader() | 68 BootTimesLoader::BootTimesLoader() |
| 66 : backend_(new Backend()), | 69 : backend_(new Backend()), |
| 67 have_registered_(false) { | 70 have_registered_(false) { |
| 68 login_time_markers_.reserve(30); | 71 login_time_markers_.reserve(30); |
| 69 logout_time_markers_.reserve(30); | 72 logout_time_markers_.reserve(30); |
| 70 } | 73 } |
| 71 | 74 |
| 72 // static | 75 // static |
| 73 BootTimesLoader* BootTimesLoader::Get() { | 76 BootTimesLoader* BootTimesLoader::Get() { |
| 74 return Singleton<BootTimesLoader>::get(); | 77 return g_boot_times_loader.Pointer(); |
| 75 } | 78 } |
| 76 | 79 |
| 77 BootTimesLoader::Handle BootTimesLoader::GetBootTimes( | 80 BootTimesLoader::Handle BootTimesLoader::GetBootTimes( |
| 78 CancelableRequestConsumerBase* consumer, | 81 CancelableRequestConsumerBase* consumer, |
| 79 BootTimesLoader::GetBootTimesCallback* callback) { | 82 BootTimesLoader::GetBootTimesCallback* callback) { |
| 80 if (!g_browser_process->file_thread()) { | 83 if (!g_browser_process->file_thread()) { |
| 81 // This should only happen if Chrome is shutting down, so we don't do | 84 // This should only happen if Chrome is shutting down, so we don't do |
| 82 // anything. | 85 // anything. |
| 83 return 0; | 86 return 0; |
| 84 } | 87 } |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 registrar_.Remove(this, NotificationType::LOGIN_AUTHENTICATION, | 369 registrar_.Remove(this, NotificationType::LOGIN_AUTHENTICATION, |
| 367 NotificationService::AllSources()); | 370 NotificationService::AllSources()); |
| 368 } | 371 } |
| 369 } else if (type == NotificationType::LOAD_START) { | 372 } else if (type == NotificationType::LOAD_START) { |
| 370 // Make sure it's not some page load initiated by OOBE/login screen. | 373 // Make sure it's not some page load initiated by OOBE/login screen. |
| 371 if (!UserManager::Get()->user_is_logged_in()) | 374 if (!UserManager::Get()->user_is_logged_in()) |
| 372 return; | 375 return; |
| 373 // Only log for first tab to render. Make sure this is only done once. | 376 // Only log for first tab to render. Make sure this is only done once. |
| 374 // If the network isn't connected we'll get a second LOAD_START once it is | 377 // If the network isn't connected we'll get a second LOAD_START once it is |
| 375 // and the page is reloaded. | 378 // and the page is reloaded. |
| 376 if (NetworkStateNotifier::Get()->is_connected()) { | 379 if (NetworkStateNotifier::GetInstance()->is_connected()) { |
| 377 // Post difference between first tab and login success time. | 380 // Post difference between first tab and login success time. |
| 378 AddLoginTimeMarker("LoginDone", true); | 381 AddLoginTimeMarker("LoginDone", true); |
| 379 RecordCurrentStats(kChromeFirstRender); | 382 RecordCurrentStats(kChromeFirstRender); |
| 380 // Post chrome first render stat. | 383 // Post chrome first render stat. |
| 381 registrar_.Remove(this, NotificationType::LOAD_START, | 384 registrar_.Remove(this, NotificationType::LOAD_START, |
| 382 NotificationService::AllSources()); | 385 NotificationService::AllSources()); |
| 383 // Don't swamp the FILE thread right away. | 386 // Don't swamp the FILE thread right away. |
| 384 BrowserThread::PostDelayedTask( | 387 BrowserThread::PostDelayedTask( |
| 385 BrowserThread::FILE, FROM_HERE, | 388 BrowserThread::FILE, FROM_HERE, |
| 386 // This doesn't compile without std::string(...), as | 389 // This doesn't compile without std::string(...), as |
| 387 // NewRunnableFunction doesn't accept arrays. | 390 // NewRunnableFunction doesn't accept arrays. |
| 388 NewRunnableFunction(WriteTimes, | 391 NewRunnableFunction(WriteTimes, |
| 389 std::string(kLoginTimes), | 392 std::string(kLoginTimes), |
| 390 std::string(kUmaLogin), | 393 std::string(kUmaLogin), |
| 391 std::string(kUmaLoginPrefix), | 394 std::string(kUmaLoginPrefix), |
| 392 login_time_markers_), | 395 login_time_markers_), |
| 393 kLoginTimeWriteDelayMs); | 396 kLoginTimeWriteDelayMs); |
| 394 have_registered_ = false; | 397 have_registered_ = false; |
| 395 } else { | 398 } else { |
| 396 AddLoginTimeMarker("LoginRenderNoNetwork", false); | 399 AddLoginTimeMarker("LoginRenderNoNetwork", false); |
| 397 } | 400 } |
| 398 } | 401 } |
| 399 } | 402 } |
| 400 | 403 |
| 401 } // namespace chromeos | 404 } // namespace chromeos |
| OLD | NEW |