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