| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser_notification_observers.h" | 5 #include "chrome/browser/chromeos/browser_notification_observers.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 11 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | 12 #include "chrome/browser/chromeos/login/authentication_notification_details.h" |
| 12 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 13 | 14 |
| 14 namespace { | |
| 15 | |
| 16 // Static function that records uptime in /proc/uptime to tmp for metrics use. | |
| 17 void RecordUptime(const std::string& filename) { | |
| 18 std::string uptime; | |
| 19 const FilePath proc_uptime = FilePath("/proc/uptime"); | |
| 20 const FilePath uptime_output = FilePath(filename); | |
| 21 | |
| 22 if (file_util::ReadFileToString(proc_uptime, &uptime)) | |
| 23 file_util::WriteFile(uptime_output, uptime.data(), uptime.size()); | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 namespace chromeos { | 15 namespace chromeos { |
| 29 | 16 |
| 30 InitialTabNotificationObserver::InitialTabNotificationObserver() { | 17 InitialTabNotificationObserver::InitialTabNotificationObserver() { |
| 31 registrar_.Add(this, NotificationType::LOAD_START, | 18 registrar_.Add(this, NotificationType::LOAD_START, |
| 32 NotificationService::AllSources()); | 19 NotificationService::AllSources()); |
| 33 } | 20 } |
| 34 | 21 |
| 35 InitialTabNotificationObserver::~InitialTabNotificationObserver() { | 22 InitialTabNotificationObserver::~InitialTabNotificationObserver() { |
| 36 } | 23 } |
| 37 | 24 |
| 38 void InitialTabNotificationObserver::Observe( | 25 void InitialTabNotificationObserver::Observe( |
| 39 NotificationType type, | 26 NotificationType type, |
| 40 const NotificationSource& source, | 27 const NotificationSource& source, |
| 41 const NotificationDetails& details) { | 28 const NotificationDetails& details) { |
| 42 // Only log for first tab to render. Make sure this is only done once. | 29 // Only log for first tab to render. Make sure this is only done once. |
| 43 if (type == NotificationType::LOAD_START && | 30 if (type == NotificationType::LOAD_START && num_tabs_.GetNext() == 0) { |
| 44 num_tabs_.GetNext() == 0) { | |
| 45 // If we can't post it, it doesn't matter. | 31 // If we can't post it, it doesn't matter. |
| 46 ChromeThread::PostTask( | 32 BootTimesLoader::RecordCurrentStats("chrome-first-render"); |
| 47 ChromeThread::FILE, FROM_HERE, | |
| 48 NewRunnableFunction(RecordUptime, | |
| 49 std::string("/tmp/uptime-chrome-first-render"))); | |
| 50 registrar_.Remove(this, NotificationType::LOAD_START, | 33 registrar_.Remove(this, NotificationType::LOAD_START, |
| 51 NotificationService::AllSources()); | 34 NotificationService::AllSources()); |
| 52 } | 35 } |
| 53 } | 36 } |
| 54 | 37 |
| 55 LogLoginSuccessObserver::LogLoginSuccessObserver() { | 38 LogLoginSuccessObserver::LogLoginSuccessObserver() { |
| 56 registrar_.Add(this, NotificationType::LOGIN_AUTHENTICATION, | 39 registrar_.Add(this, NotificationType::LOGIN_AUTHENTICATION, |
| 57 NotificationService::AllSources()); | 40 NotificationService::AllSources()); |
| 58 } | 41 } |
| 59 | 42 |
| 60 LogLoginSuccessObserver::~LogLoginSuccessObserver() { | 43 LogLoginSuccessObserver::~LogLoginSuccessObserver() { |
| 61 } | 44 } |
| 62 | 45 |
| 63 void LogLoginSuccessObserver::Observe(NotificationType type, | 46 void LogLoginSuccessObserver::Observe(NotificationType type, |
| 64 const NotificationSource& source, | 47 const NotificationSource& source, |
| 65 const NotificationDetails& details) { | 48 const NotificationDetails& details) { |
| 66 DCHECK(type == NotificationType::LOGIN_AUTHENTICATION); | 49 DCHECK(type == NotificationType::LOGIN_AUTHENTICATION); |
| 67 Details<AuthenticationNotificationDetails> auth_details(details); | 50 Details<AuthenticationNotificationDetails> auth_details(details); |
| 68 if (auth_details->success()) { | 51 if (auth_details->success()) { |
| 69 // If we can't post it, it doesn't matter. | 52 // If we can't post it, it doesn't matter. |
| 70 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, | 53 BootTimesLoader::RecordCurrentStats("login-successful"); |
| 71 NewRunnableFunction(RecordUptime, | |
| 72 std::string("/tmp/uptime-login-successful"))); | |
| 73 registrar_.Remove(this, NotificationType::LOGIN_AUTHENTICATION, | 54 registrar_.Remove(this, NotificationType::LOGIN_AUTHENTICATION, |
| 74 NotificationService::AllSources()); | 55 NotificationService::AllSources()); |
| 75 } | 56 } |
| 76 } | 57 } |
| 77 | 58 |
| 78 } // namespace chromeos | 59 } // namespace chromeos |
| OLD | NEW |