Chromium Code Reviews| Index: chrome/browser/performance_monitor/startup_timer.h |
| diff --git a/chrome/browser/performance_monitor/startup_timer.h b/chrome/browser/performance_monitor/startup_timer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ce74d62691f9b84eb6226cea6cb0ae35d1babb50 |
| --- /dev/null |
| +++ b/chrome/browser/performance_monitor/startup_timer.h |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_STARTUP_TIMER_H_ |
| +#define CHROME_BROWSER_PERFORMANCE_MONITOR_STARTUP_TIMER_H_ |
| + |
| +#include "base/time.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| + |
| +namespace performance_monitor { |
| + |
| +// This class is responsible for recording the startup and session restore times |
| +// (if applicable) for PerformanceMonitor. This allows us to initialize this |
| +// relatively small object early in the startup process, and start the whole of |
| +// PerformanceMonitor at a later time. StartupTimer will record the times and |
| +// insert them into PerformanceMonitor's database. |
| +class StartupTimer : public content::NotificationObserver { |
| + public: |
| + StartupTimer(); |
| + virtual ~StartupTimer(); |
| + |
| + // Inform StartupTimer that the startup process has been completed; stop the |
| + // timer. Returns false if the timer has already stopped. |
| + bool SignalStartupComplete(bool normal_startup); |
|
Yoyo Zhou
2012/07/31 09:57:32
This would be more understandable as an enum, sinc
Devlin
2012/07/31 16:43:40
Done.
|
| + |
| + // Pauses the timer until Unpause is called; any time spent within a pause |
| + // does not count towards the total. |
|
Yoyo Zhou
2012/07/31 09:57:32
Please document the return values.
Devlin
2012/07/31 16:43:40
Done.
|
| + static bool PauseTimer(); |
| + static bool UnpauseTimer(); |
| + |
| + // content::NotificationObserver |
| + // We keep track of whether or not PerformanceMonitor has been started via |
| + // the PERFORMANCE_MONITOR_INITIALIZED notification; we need to know this so |
| + // we know when to insert startup data into the database. We either insert |
| + // data as we gather it (if PerformanceMonitor is started prior to data |
| + // collection) or at the notification (if PerformanceMonitor is started |
| + // later). |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + static void SetSessionRestoreTime( |
| + const base::TimeDelta& session_restore_time); |
| + |
| + private: |
| + bool PauseTimerImpl(); |
| + bool UnpauseTimerImpl(); |
| + void InsertStartupTime(); |
|
Yoyo Zhou
2012/07/31 09:57:32
These names are vaguely confusing because "time" c
Devlin
2012/07/31 16:43:40
Done.
|
| + void InsertSessionRestoreTime(); |
| + |
| + // The time at which the startup process begins (the creation of |
| + // ChromeBrowserMain). |
| + base::TimeTicks startup_begin_; |
| + |
| + // The time at which the timer was most recently paused, or null if the timer |
| + // is not currently paused. |
| + base::TimeTicks pause_started_; |
| + |
| + // The total duration for which the timer has been paused. |
| + base::TimeDelta total_pause_; |
| + |
| + // A flag of whether or not this was a "normal" startup (e.g. whether or not |
| + // this was in a testing environment, which would change the startup time |
| + // values). If it is not a normal startup, we use a different metric. |
| + bool normal_startup_; |
| + |
| + // The total duration of the startup process, minus any pauses. |
| + base::TimeDelta elapsed_startup_time_; |
| + |
| + // The total duration of the session restore, if one occurred. This is |
| + // independent of the startup time, because: |
| + // - If the user has auto-restore on, the restore is synchronous, and we pause |
| + // the startup timer during the session restore; the restore will not |
| + // interfere with startup timing. |
| + // - If Chrome crashed and the user chooses to restore the crashed session, |
| + // then the startup is already completed; the restore will not interfere |
| + // with startup timing. |
| + base::TimeDelta session_restore_time_; |
| + |
| + // Flag whether or not PerformanceMonitor has been fully started. |
| + bool performance_monitor_initialized_; |
| + |
| + content::NotificationRegistrar registrar_; |
| + |
| + // The singleton of this class. |
|
Yoyo Zhou
2012/07/31 09:57:32
Use base/memory/singleton.h for this purpose.
Devlin
2012/07/31 16:43:40
And...sorry in advance for a long comment.
Pursua
|
| + static StartupTimer* g_startup_timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(StartupTimer); |
| +}; |
| + |
| +} // namespace performance_monitor |
| + |
| +#endif // CHROME_BROWSER_PERFORMANCE_MONITOR_STARTUP_TIMER_H_ |