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

Side by Side Diff: chrome/browser/chromeos/boot_times_loader.h

Issue 303233004: Write "logout-started" event on next boot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 6 years, 6 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
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 #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
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 // This is called on Chrome process startup to write saved logout stats.
88 void OnBoot();
stevenjb 2014/05/30 16:20:23 "Boot" is rather unspecific, could you give this a
Alexander Alekseev 2014/05/30 21:12:45 There are many different OnProfileCreated events.
89
90 // This saves logout-started metric to Local State.
91 void OnLogoutStarted(PrefService* state);
92
85 private: 93 private:
86 // BootTimesLoader calls into the Backend on the file thread to load 94 // BootTimesLoader calls into the Backend on the file thread to load
87 // the boot times. 95 // the boot times.
88 class Backend : public base::RefCountedThreadSafe<Backend> { 96 class Backend : public base::RefCountedThreadSafe<Backend> {
89 public: 97 public:
90 Backend() {} 98 Backend() {}
91 99
92 private: 100 private:
93 friend class base::RefCountedThreadSafe<Backend>; 101 friend class base::RefCountedThreadSafe<Backend>;
94 102
(...skipping 19 matching lines...) Expand all
114 122
115 private: 123 private:
116 friend class std::vector<TimeMarker>; 124 friend class std::vector<TimeMarker>;
117 std::string name_; 125 std::string name_;
118 base::Time time_; 126 base::Time time_;
119 bool send_to_uma_; 127 bool send_to_uma_;
120 }; 128 };
121 129
122 struct Stats { 130 struct Stats {
123 public: 131 public:
132 std::string SerializeToString() const;
133 static Stats DeserializeFromString(const std::string& value);
134
124 std::string uptime; 135 std::string uptime;
125 std::string disk; 136 std::string disk;
126 }; 137 };
127 138
128 static void RecordStats( 139 static void RecordStats(
129 const std::string& name, const Stats& stats); 140 const std::string& name, const Stats& stats);
141 void RecordStatsWithCallback(const std::string& name,
142 const Stats& stats,
143 const base::Closure& callback);
130 static Stats GetCurrentStats(); 144 static Stats GetCurrentStats();
145 static std::string GetUptimeSeconds(const Stats& stats);
131 static void WriteTimes(const std::string base_name, 146 static void WriteTimes(const std::string base_name,
132 const std::string uma_name, 147 const std::string uma_name,
133 const std::string uma_prefix, 148 const std::string uma_prefix,
134 std::vector<TimeMarker> login_times); 149 std::vector<TimeMarker> login_times);
135 static void AddMarker(std::vector<TimeMarker>* vector, TimeMarker marker); 150 static void AddMarker(std::vector<TimeMarker>* vector, TimeMarker marker);
136 151
152 // Clear saved logout-started metric in Local State.
153 // This method is called when logout-state was writen to file.
154 static void ClearLogoutStartedLastPreference();
155
137 // Used to hold the stats at main(). 156 // Used to hold the stats at main().
138 Stats chrome_main_stats_; 157 Stats chrome_main_stats_;
139 scoped_refptr<Backend> backend_; 158 scoped_refptr<Backend> backend_;
140 159
141 // Used to track notifications for login. 160 // Used to track notifications for login.
142 content::NotificationRegistrar registrar_; 161 content::NotificationRegistrar registrar_;
143 base::AtomicSequenceNumber num_tabs_; 162 base::AtomicSequenceNumber num_tabs_;
144 bool have_registered_; 163 bool have_registered_;
145 164
146 std::vector<TimeMarker> login_time_markers_; 165 std::vector<TimeMarker> login_time_markers_;
147 std::vector<TimeMarker> logout_time_markers_; 166 std::vector<TimeMarker> logout_time_markers_;
148 std::set<content::RenderWidgetHost*> render_widget_hosts_loading_; 167 std::set<content::RenderWidgetHost*> render_widget_hosts_loading_;
149 168
150 bool login_done_; 169 bool login_done_;
151 170
152 bool restart_requested_; 171 bool restart_requested_;
153 172
154 DISALLOW_COPY_AND_ASSIGN(BootTimesLoader); 173 DISALLOW_COPY_AND_ASSIGN(BootTimesLoader);
155 }; 174 };
156 175
157 } // namespace chromeos 176 } // namespace chromeos
158 177
159 #endif // CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_ 178 #endif // CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/boot_times_loader.cc » ('j') | chrome/browser/chromeos/boot_times_loader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698