Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_STARTUP_TIMER_H_ | |
| 6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_STARTUP_TIMER_H_ | |
| 7 | |
| 8 #include "base/time.h" | |
| 9 #include "content/public/browser/notification_observer.h" | |
| 10 #include "content/public/browser/notification_registrar.h" | |
| 11 | |
| 12 namespace performance_monitor { | |
| 13 | |
| 14 // This class is responsible for recording the startup and session restore times | |
| 15 // (if applicable) for PerformanceMonitor. This allows us to initialize this | |
| 16 // relatively small object early in the startup process, and start the whole of | |
| 17 // PerformanceMonitor at a later time. StartupTimer will record the times and | |
| 18 // insert them into PerformanceMonitor's database. | |
| 19 class StartupTimer : public content::NotificationObserver { | |
| 20 public: | |
| 21 StartupTimer(); | |
| 22 virtual ~StartupTimer(); | |
| 23 | |
| 24 // Inform StartupTimer that the startup process has been completed; stop the | |
| 25 // timer. Returns false if the timer has already stopped. | |
| 26 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.
| |
| 27 | |
| 28 // Pauses the timer until Unpause is called; any time spent within a pause | |
| 29 // 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.
| |
| 30 static bool PauseTimer(); | |
| 31 static bool UnpauseTimer(); | |
| 32 | |
| 33 // content::NotificationObserver | |
| 34 // We keep track of whether or not PerformanceMonitor has been started via | |
| 35 // the PERFORMANCE_MONITOR_INITIALIZED notification; we need to know this so | |
| 36 // we know when to insert startup data into the database. We either insert | |
| 37 // data as we gather it (if PerformanceMonitor is started prior to data | |
| 38 // collection) or at the notification (if PerformanceMonitor is started | |
| 39 // later). | |
| 40 virtual void Observe(int type, | |
| 41 const content::NotificationSource& source, | |
| 42 const content::NotificationDetails& details) OVERRIDE; | |
| 43 | |
| 44 static void SetSessionRestoreTime( | |
| 45 const base::TimeDelta& session_restore_time); | |
| 46 | |
| 47 private: | |
| 48 bool PauseTimerImpl(); | |
| 49 bool UnpauseTimerImpl(); | |
| 50 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.
| |
| 51 void InsertSessionRestoreTime(); | |
| 52 | |
| 53 // The time at which the startup process begins (the creation of | |
| 54 // ChromeBrowserMain). | |
| 55 base::TimeTicks startup_begin_; | |
| 56 | |
| 57 // The time at which the timer was most recently paused, or null if the timer | |
| 58 // is not currently paused. | |
| 59 base::TimeTicks pause_started_; | |
| 60 | |
| 61 // The total duration for which the timer has been paused. | |
| 62 base::TimeDelta total_pause_; | |
| 63 | |
| 64 // A flag of whether or not this was a "normal" startup (e.g. whether or not | |
| 65 // this was in a testing environment, which would change the startup time | |
| 66 // values). If it is not a normal startup, we use a different metric. | |
| 67 bool normal_startup_; | |
| 68 | |
| 69 // The total duration of the startup process, minus any pauses. | |
| 70 base::TimeDelta elapsed_startup_time_; | |
| 71 | |
| 72 // The total duration of the session restore, if one occurred. This is | |
| 73 // independent of the startup time, because: | |
| 74 // - If the user has auto-restore on, the restore is synchronous, and we pause | |
| 75 // the startup timer during the session restore; the restore will not | |
| 76 // interfere with startup timing. | |
| 77 // - If Chrome crashed and the user chooses to restore the crashed session, | |
| 78 // then the startup is already completed; the restore will not interfere | |
| 79 // with startup timing. | |
| 80 base::TimeDelta session_restore_time_; | |
| 81 | |
| 82 // Flag whether or not PerformanceMonitor has been fully started. | |
| 83 bool performance_monitor_initialized_; | |
| 84 | |
| 85 content::NotificationRegistrar registrar_; | |
| 86 | |
| 87 // 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
| |
| 88 static StartupTimer* g_startup_timer_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(StartupTimer); | |
| 91 }; | |
| 92 | |
| 93 } // namespace performance_monitor | |
| 94 | |
| 95 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_STARTUP_TIMER_H_ | |
| OLD | NEW |