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/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.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 class PrefService; | |
21 | |
20 namespace chromeos { | 22 namespace chromeos { |
21 | 23 |
22 // BootTimesLoader loads the bootimes of Chrome OS from the file system. | 24 // BootTimesLoader loads the bootimes of Chrome OS from the file system. |
23 // Loading is done asynchronously on the file thread. Once loaded, | 25 // Loading is done asynchronously on the file thread. Once loaded, |
24 // BootTimesLoader calls back to a method of your choice with the boot times. | 26 // BootTimesLoader calls back to a method of your choice with the boot times. |
25 // To use BootTimesLoader, do the following: | 27 // To use BootTimesLoader, do the following: |
26 // | 28 // |
27 // . In your class define a member field of type chromeos::BootTimesLoader and | 29 // . In your class define a member field of type chromeos::BootTimesLoader and |
28 // base::CancelableTaskTracker. | 30 // base::CancelableTaskTracker. |
29 // . Define the callback method, something like: | 31 // . Define the callback method, something like: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 void LoginDone(bool is_user_new); | 77 void LoginDone(bool is_user_new); |
76 | 78 |
77 // Writes the logout times to a /tmp/logout-times-sent. Unlike login | 79 // Writes the logout times to a /tmp/logout-times-sent. Unlike login |
78 // times, we manually call this function for logout times, as we cannot | 80 // times, we manually call this function for logout times, as we cannot |
79 // rely on notification service to tell when the logout is done. | 81 // rely on notification service to tell when the logout is done. |
80 void WriteLogoutTimes(); | 82 void WriteLogoutTimes(); |
81 | 83 |
82 // Mark that WriteLogoutTimes should handle restart. | 84 // Mark that WriteLogoutTimes should handle restart. |
83 void set_restart_requested() { restart_requested_ = true; } | 85 void set_restart_requested() { restart_requested_ = true; } |
84 | 86 |
87 void OnBoot(); | |
Nikita (slow)
2014/05/30 07:07:03
nit: Comment is missing.
Alexander Alekseev
2014/05/30 18:44:54
Done.
| |
88 | |
89 void OnLogoutStarted(PrefService* state); | |
Nikita (slow)
2014/05/30 07:07:03
nit: Comment is missing.
Alexander Alekseev
2014/05/30 18:44:54
Done.
| |
90 | |
85 private: | 91 private: |
86 // BootTimesLoader calls into the Backend on the file thread to load | 92 // BootTimesLoader calls into the Backend on the file thread to load |
87 // the boot times. | 93 // the boot times. |
88 class Backend : public base::RefCountedThreadSafe<Backend> { | 94 class Backend : public base::RefCountedThreadSafe<Backend> { |
89 public: | 95 public: |
90 Backend() {} | 96 Backend() {} |
91 | 97 |
92 private: | 98 private: |
93 friend class base::RefCountedThreadSafe<Backend>; | 99 friend class base::RefCountedThreadSafe<Backend>; |
94 | 100 |
(...skipping 19 matching lines...) Expand all Loading... | |
114 | 120 |
115 private: | 121 private: |
116 friend class std::vector<TimeMarker>; | 122 friend class std::vector<TimeMarker>; |
117 std::string name_; | 123 std::string name_; |
118 base::Time time_; | 124 base::Time time_; |
119 bool send_to_uma_; | 125 bool send_to_uma_; |
120 }; | 126 }; |
121 | 127 |
122 struct Stats { | 128 struct Stats { |
123 public: | 129 public: |
130 std::string SerializeToString() const; | |
131 static Stats DeserializeFromString(const std::string& value); | |
132 | |
124 std::string uptime; | 133 std::string uptime; |
125 std::string disk; | 134 std::string disk; |
126 }; | 135 }; |
127 | 136 |
128 static void RecordStats( | 137 static void RecordStats( |
129 const std::string& name, const Stats& stats); | 138 const std::string& name, const Stats& stats); |
139 void RecordStatsWithCallback(const std::string& name, | |
140 const Stats& stats, | |
141 const base::Closure& callback); | |
130 static Stats GetCurrentStats(); | 142 static Stats GetCurrentStats(); |
143 static std::string GetUptimeSeconds(const Stats& stats); | |
131 static void WriteTimes(const std::string base_name, | 144 static void WriteTimes(const std::string base_name, |
132 const std::string uma_name, | 145 const std::string uma_name, |
133 const std::string uma_prefix, | 146 const std::string uma_prefix, |
134 std::vector<TimeMarker> login_times); | 147 std::vector<TimeMarker> login_times); |
135 static void AddMarker(std::vector<TimeMarker>* vector, TimeMarker marker); | 148 static void AddMarker(std::vector<TimeMarker>* vector, TimeMarker marker); |
136 | 149 |
150 static void ClearLogoutStartedLastPreference(); | |
Nikita (slow)
2014/05/30 07:07:03
nit: Comment is missing.
Alexander Alekseev
2014/05/30 18:44:54
Done.
| |
151 | |
137 // Used to hold the stats at main(). | 152 // Used to hold the stats at main(). |
138 Stats chrome_main_stats_; | 153 Stats chrome_main_stats_; |
139 scoped_refptr<Backend> backend_; | 154 scoped_refptr<Backend> backend_; |
140 | 155 |
141 // Used to track notifications for login. | 156 // Used to track notifications for login. |
142 content::NotificationRegistrar registrar_; | 157 content::NotificationRegistrar registrar_; |
143 base::AtomicSequenceNumber num_tabs_; | 158 base::AtomicSequenceNumber num_tabs_; |
144 bool have_registered_; | 159 bool have_registered_; |
145 | 160 |
146 std::vector<TimeMarker> login_time_markers_; | 161 std::vector<TimeMarker> login_time_markers_; |
147 std::vector<TimeMarker> logout_time_markers_; | 162 std::vector<TimeMarker> logout_time_markers_; |
148 std::set<content::RenderWidgetHost*> render_widget_hosts_loading_; | 163 std::set<content::RenderWidgetHost*> render_widget_hosts_loading_; |
149 | 164 |
150 bool login_done_; | 165 bool login_done_; |
151 | 166 |
152 bool restart_requested_; | 167 bool restart_requested_; |
153 | 168 |
154 DISALLOW_COPY_AND_ASSIGN(BootTimesLoader); | 169 DISALLOW_COPY_AND_ASSIGN(BootTimesLoader); |
155 }; | 170 }; |
156 | 171 |
157 } // namespace chromeos | 172 } // namespace chromeos |
158 | 173 |
159 #endif // CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ | 174 #endif // CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ |
OLD | NEW |