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_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/file_path.h" | 11 #include "base/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/timer.h" |
12 #include "chrome/browser/performance_monitor/database.h" | 15 #include "chrome/browser/performance_monitor/database.h" |
13 #include "chrome/browser/performance_monitor/event.h" | 16 #include "chrome/browser/performance_monitor/event.h" |
14 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
18 | 21 |
19 namespace performance_monitor { | 22 namespace performance_monitor { |
20 class Database; | 23 class Database; |
21 | 24 |
(...skipping 22 matching lines...) Expand all Loading... |
44 virtual void Observe(int type, | 47 virtual void Observe(int type, |
45 const content::NotificationSource& source, | 48 const content::NotificationSource& source, |
46 const content::NotificationDetails& details) OVERRIDE; | 49 const content::NotificationDetails& details) OVERRIDE; |
47 | 50 |
48 Database* database() { return database_.get(); } | 51 Database* database() { return database_.get(); } |
49 FilePath database_path() { return database_path_; } | 52 FilePath database_path() { return database_path_; } |
50 | 53 |
51 private: | 54 private: |
52 friend struct DefaultSingletonTraits<PerformanceMonitor>; | 55 friend struct DefaultSingletonTraits<PerformanceMonitor>; |
53 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorBrowserTest, NewVersionEvent); | 56 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorBrowserTest, NewVersionEvent); |
| 57 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, |
| 58 OneProfileUncleanExit); |
| 59 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, |
| 60 TwoProfileUncleanExit); |
54 | 61 |
55 PerformanceMonitor(); | 62 PerformanceMonitor(); |
56 virtual ~PerformanceMonitor(); | 63 virtual ~PerformanceMonitor(); |
57 | 64 |
58 // Perform any additional initialization which must be performed on a | 65 // Perform any additional initialization which must be performed on a |
59 // background thread (e.g. constructing the database). | 66 // background thread (e.g. constructing the database). |
60 void InitOnBackgroundThread(); | 67 void InitOnBackgroundThread(); |
61 | 68 |
62 void FinishInit(); | 69 void FinishInit(); |
63 | 70 |
64 // Register for the appropriate notifications as a NotificationObserver. | 71 // Register for the appropriate notifications as a NotificationObserver. |
65 void RegisterForNotifications(); | 72 void RegisterForNotifications(); |
66 | 73 |
| 74 // Checks for whether the previous profiles closed uncleanly; this method |
| 75 // should only be called once per run in order to avoid duplication of events |
| 76 // (exceptions made for testing purposes where we construct the environment). |
| 77 void CheckForUncleanExits(); |
| 78 |
| 79 // Find the last active time for the profile and insert the event into the |
| 80 // database. |
| 81 void AddUncleanExitEvent(const std::string& profile_name); |
| 82 |
67 // Check the previous Chrome version from the Database and determine if | 83 // Check the previous Chrome version from the Database and determine if |
68 // it has been updated. If it has, insert an event in the database. | 84 // it has been updated. If it has, insert an event in the database. |
69 void CheckForVersionUpdateOnBackgroundThread(); | 85 void CheckForVersionUpdateOnBackgroundThread(); |
70 | 86 |
71 // Wrapper function for inserting events into the database. | 87 // Wrapper function for inserting events into the database. |
72 void AddEvent(scoped_ptr<Event> event); | 88 void AddEvent(scoped_ptr<Event> event); |
73 | 89 |
74 void AddEventOnBackgroundThread(scoped_ptr<Event> event); | 90 void AddEventOnBackgroundThread(scoped_ptr<Event> event); |
75 | 91 |
76 // Gets the corresponding value of |key| from the database, and then runs | 92 // Gets the corresponding value of |key| from the database, and then runs |
77 // |callback| on the UI thread with that value as a parameter. | 93 // |callback| on the UI thread with that value as a parameter. |
78 void GetStateValueOnBackgroundThread( | 94 void GetStateValueOnBackgroundThread( |
79 const std::string& key, | 95 const std::string& key, |
80 const StateValueCallback& callback); | 96 const StateValueCallback& callback); |
81 | 97 |
82 // Notify any listeners that PerformanceMonitor has finished the initializing. | 98 // Notify any listeners that PerformanceMonitor has finished the initializing. |
83 void NotifyInitialized(); | 99 void NotifyInitialized(); |
84 | 100 |
| 101 // Update the database record of the last time the active profiles were |
| 102 // running; this is used in determining when an unclean exit occurred. |
| 103 void UpdateLiveProfiles(); |
| 104 void UpdateLiveProfilesHelper( |
| 105 scoped_ptr<std::set<std::string> > active_profiles, std::string time); |
| 106 |
| 107 // Perform any collections that are done on a timed basis. |
| 108 void DoTimedCollections(); |
| 109 |
85 // The location at which the database files are stored; if empty, the database | 110 // The location at which the database files are stored; if empty, the database |
86 // will default to '<user_data_dir>/performance_monitor_dbs'. | 111 // will default to '<user_data_dir>/performance_monitor_dbs'. |
87 FilePath database_path_; | 112 FilePath database_path_; |
88 | 113 |
89 scoped_ptr<Database> database_; | 114 scoped_ptr<Database> database_; |
90 | 115 |
91 content::NotificationRegistrar registrar_; | 116 content::NotificationRegistrar registrar_; |
92 | 117 |
| 118 base::RepeatingTimer<PerformanceMonitor> timer_; |
| 119 |
93 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); | 120 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); |
94 }; | 121 }; |
95 | 122 |
96 } // namespace performance_monitor | 123 } // namespace performance_monitor |
97 | 124 |
98 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 125 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
OLD | NEW |