| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "chrome/browser/common/cancelable_request.h" | 15 #include "chrome/common/cancelable_task_tracker.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_widget_host.h" |
| 19 | 19 |
| 20 namespace chromeos { | 20 namespace chromeos { |
| 21 | 21 |
| 22 // BootTimesLoader loads the bootimes of Chrome OS from the file system. | 22 // BootTimesLoader loads the bootimes of Chrome OS from the file system. |
| 23 // Loading is done asynchronously on the file thread. Once loaded, | 23 // Loading is done asynchronously on the file thread. Once loaded, |
| 24 // BootTimesLoader calls back to a method of your choice with the boot times. | 24 // BootTimesLoader calls back to a method of your choice with the boot times. |
| 25 // To use BootTimesLoader do the following: | 25 // To use BootTimesLoader, do the following: |
| 26 // | 26 // |
| 27 // . In your class define a member field of type chromeos::BootTimesLoader and | 27 // . In your class define a member field of type chromeos::BootTimesLoader and |
| 28 // CancelableRequestConsumerBase. | 28 // CancelableTaskTracker. |
| 29 // . Define the callback method, something like: | 29 // . Define the callback method, something like: |
| 30 // void OnBootTimesLoader(chromeos::BootTimesLoader::Handle, | 30 // void OnBootTimesLoaded(const BootTimesLoader::BootTimes& boot_times); |
| 31 // BootTimesLoader::BootTimes boot_times); | 31 // . When you want the version invoke: loader.GetBootTimes(callback, &tracker_); |
| 32 // . When you want the version invoke: loader.GetBootTimes(&consumer, callback); | 32 class BootTimesLoader : public content::NotificationObserver { |
| 33 class BootTimesLoader | |
| 34 : public CancelableRequestProvider, | |
| 35 public content::NotificationObserver { | |
| 36 public: | 33 public: |
| 37 BootTimesLoader(); | 34 BootTimesLoader(); |
| 38 virtual ~BootTimesLoader(); | 35 virtual ~BootTimesLoader(); |
| 39 | 36 |
| 40 // All fields are 0.0 if they couldn't be found. | 37 // All fields are 0.0 if they couldn't be found. |
| 41 typedef struct BootTimes { | 38 typedef struct BootTimes { |
| 42 double firmware; // Time from power button to kernel being loaded. | 39 double firmware; // Time from power button to kernel being loaded. |
| 43 double pre_startup; // Time from kernel to system code being called. | 40 double pre_startup; // Time from kernel to system code being called. |
| 44 double x_started; // Time X server is ready to be connected to. | 41 double x_started; // Time X server is ready to be connected to. |
| 45 double chrome_exec; // Time session manager executed Chrome. | 42 double chrome_exec; // Time session manager executed Chrome. |
| 46 double chrome_main; // Time chrome's main() was called. | 43 double chrome_main; // Time chrome's main() was called. |
| 47 double login_prompt_ready; // Time login (or OOB) panel is displayed. | 44 double login_prompt_ready; // Time login (or OOB) panel is displayed. |
| 48 double system; // Time system took to start chrome. | 45 double system; // Time system took to start chrome. |
| 49 double chrome; // Time chrome took to display login panel. | 46 double chrome; // Time chrome took to display login panel. |
| 50 double total; // Time from power button to login panel. | 47 double total; // Time from power button to login panel. |
| 51 | 48 |
| 52 BootTimes() : firmware(0), | 49 BootTimes() : firmware(0), |
| 53 pre_startup(0), | 50 pre_startup(0), |
| 54 x_started(0), | 51 x_started(0), |
| 55 chrome_exec(0), | 52 chrome_exec(0), |
| 56 chrome_main(0), | 53 chrome_main(0), |
| 57 login_prompt_ready(0), | 54 login_prompt_ready(0), |
| 58 system(0), | 55 system(0), |
| 59 chrome(0), | 56 chrome(0), |
| 60 total(0) {} | 57 total(0) {} |
| 61 } BootTimes; | 58 } BootTimes; |
| 62 | 59 |
| 63 // Signature | |
| 64 typedef base::Callback<void(Handle, BootTimes)> GetBootTimesCallback; | |
| 65 | |
| 66 typedef CancelableRequest<GetBootTimesCallback> GetBootTimesRequest; | |
| 67 | |
| 68 static BootTimesLoader* Get(); | 60 static BootTimesLoader* Get(); |
| 69 | 61 |
| 62 typedef base::Callback<void(const BootTimes&)> GetBootTimesCallback; |
| 63 |
| 70 // Asynchronously requests the info. | 64 // Asynchronously requests the info. |
| 71 Handle GetBootTimes( | 65 CancelableTaskTracker::TaskId GetBootTimes( |
| 72 CancelableRequestConsumerBase* consumer, | 66 const GetBootTimesCallback& callback, |
| 73 const GetBootTimesCallback& callback); | 67 CancelableTaskTracker* tracker); |
| 74 | 68 |
| 75 // Add a time marker for login. A timeline will be dumped to | 69 // Add a time marker for login. A timeline will be dumped to |
| 76 // /tmp/login-times-sent after login is done. If |send_to_uma| is true | 70 // /tmp/login-times-sent after login is done. If |send_to_uma| is true |
| 77 // the time between this marker and the last will be sent to UMA with | 71 // the time between this marker and the last will be sent to UMA with |
| 78 // the identifier BootTime.|marker_name|. | 72 // the identifier BootTime.|marker_name|. |
| 79 void AddLoginTimeMarker(const std::string& marker_name, bool send_to_uma); | 73 void AddLoginTimeMarker(const std::string& marker_name, bool send_to_uma); |
| 80 | 74 |
| 81 // Add a time marker for logout. A timeline will be dumped to | 75 // Add a time marker for logout. A timeline will be dumped to |
| 82 // /tmp/logout-times-sent after logout is done. If |send_to_uma| is true | 76 // /tmp/logout-times-sent after logout is done. If |send_to_uma| is true |
| 83 // the time between this marker and the last will be sent to UMA with | 77 // the time between this marker and the last will be sent to UMA with |
| (...skipping 28 matching lines...) Expand all Loading... |
| 112 // rely on notification service to tell when the logout is done. | 106 // rely on notification service to tell when the logout is done. |
| 113 void WriteLogoutTimes(); | 107 void WriteLogoutTimes(); |
| 114 | 108 |
| 115 private: | 109 private: |
| 116 // BootTimesLoader calls into the Backend on the file thread to load | 110 // BootTimesLoader calls into the Backend on the file thread to load |
| 117 // the boot times. | 111 // the boot times. |
| 118 class Backend : public base::RefCountedThreadSafe<Backend> { | 112 class Backend : public base::RefCountedThreadSafe<Backend> { |
| 119 public: | 113 public: |
| 120 Backend() {} | 114 Backend() {} |
| 121 | 115 |
| 122 void GetBootTimes(const scoped_refptr<GetBootTimesRequest>& request); | 116 void GetBootTimesAndRunCallback( |
| 117 const CancelableTaskTracker::IsCanceledCallback& is_canceled_cb, |
| 118 const GetBootTimesCallback& callback); |
| 123 | 119 |
| 124 private: | 120 private: |
| 125 friend class base::RefCountedThreadSafe<Backend>; | 121 friend class base::RefCountedThreadSafe<Backend>; |
| 126 | 122 |
| 127 ~Backend() {} | 123 ~Backend() {} |
| 128 | 124 |
| 129 DISALLOW_COPY_AND_ASSIGN(Backend); | 125 DISALLOW_COPY_AND_ASSIGN(Backend); |
| 130 }; | 126 }; |
| 131 | 127 |
| 132 class TimeMarker { | 128 class TimeMarker { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 std::vector<TimeMarker> login_time_markers_; | 176 std::vector<TimeMarker> login_time_markers_; |
| 181 std::vector<TimeMarker> logout_time_markers_; | 177 std::vector<TimeMarker> logout_time_markers_; |
| 182 std::set<content::RenderWidgetHost*> render_widget_hosts_loading_; | 178 std::set<content::RenderWidgetHost*> render_widget_hosts_loading_; |
| 183 | 179 |
| 184 DISALLOW_COPY_AND_ASSIGN(BootTimesLoader); | 180 DISALLOW_COPY_AND_ASSIGN(BootTimesLoader); |
| 185 }; | 181 }; |
| 186 | 182 |
| 187 } // namespace chromeos | 183 } // namespace chromeos |
| 188 | 184 |
| 189 #endif // CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ | 185 #endif // CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ |
| OLD | NEW |