#ifndef CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_
#define CHROME_BROWSER_CHROMEOS_BOOT_TIMES_LOADER_H_
#include <set>
#include <string>
#include "base/atomic_sequence_num.h"
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/render_widget_host.h"
namespace chromeos {
class BootTimesLoader : public content::NotificationObserver {
public:
BootTimesLoader();
virtual ~BootTimesLoader();
static BootTimesLoader* Get();
void AddLoginTimeMarker(const std::string& marker_name, bool send_to_uma);
void AddLogoutTimeMarker(const std::string& marker_name, bool send_to_uma);
void RecordCurrentStats(const std::string& name);
void SaveChromeMainStats();
void RecordChromeMainStats();
void RecordLoginAttempted();
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void WriteLogoutTimes();
private:
class Backend : public base::RefCountedThreadSafe<Backend> {
public:
Backend() {}
private:
friend class base::RefCountedThreadSafe<Backend>;
~Backend() {}
DISALLOW_COPY_AND_ASSIGN(Backend);
};
class TimeMarker {
public:
TimeMarker(const std::string& name, bool send_to_uma)
: name_(name),
time_(base::Time::NowFromSystemTime()),
send_to_uma_(send_to_uma) {}
std::string name() const { return name_; }
base::Time time() const { return time_; }
bool send_to_uma() const { return send_to_uma_; }
bool operator<(const TimeMarker& other) const {
return time_ < other.time_;
}
private:
friend class std::vector<TimeMarker>;
std::string name_;
base::Time time_;
bool send_to_uma_;
};
struct Stats {
public:
std::string uptime;
std::string disk;
};
static void RecordStats(
const std::string& name, const Stats& stats);
static Stats GetCurrentStats();
static void WriteTimes(const std::string base_name,
const std::string uma_name,
const std::string uma_prefix,
std::vector<TimeMarker> login_times);
static void AddMarker(std::vector<TimeMarker>* vector, TimeMarker marker);
void LoginDone();
Stats chrome_main_stats_;
scoped_refptr<Backend> backend_;
content::NotificationRegistrar registrar_;
base::AtomicSequenceNumber num_tabs_;
bool have_registered_;
std::vector<TimeMarker> login_time_markers_;
std::vector<TimeMarker> logout_time_markers_;
std::set<content::RenderWidgetHost*> render_widget_hosts_loading_;
DISALLOW_COPY_AND_ASSIGN(BootTimesLoader);
};
}
#endif