Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor.h

Issue 10703078: Add Unclean Exit Watching to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_crash_event_watching
Patch Set: Requested changes made Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
23 class PerformanceMonitor : public content::NotificationObserver { 24 class PerformanceMonitor : public content::NotificationObserver {
24 public: 25 public:
25 typedef base::Callback<void(const std::string&)> StateValueCallback; 26 typedef base::Callback<void(const std::string&)> StateValueCallback;
Yoyo Zhou 2012/07/12 18:13:44 Nice, this makes things more readable.
26 27
27 // Set the path which the PerformanceMonitor should use for the database files 28 // Set the path which the PerformanceMonitor should use for the database files
28 // constructed. This must be done prior to the initialization of the 29 // constructed. This must be done prior to the initialization of the
29 // PerformanceMonitor. Returns true on success, false on failure (failure 30 // PerformanceMonitor. Returns true on success, false on failure (failure
30 // likely indicates that PerformanceMonitor has already been started at the 31 // likely indicates that PerformanceMonitor has already been started at the
31 // time of the call). 32 // time of the call).
32 bool SetDatabasePath(const FilePath& path); 33 bool SetDatabasePath(const FilePath& path);
33 34
34 // Returns the current PerformanceMonitor instance if one exists; otherwise 35 // Returns the current PerformanceMonitor instance if one exists; otherwise
35 // constructs a new PerformanceMonitor. 36 // constructs a new PerformanceMonitor.
(...skipping 12 matching lines...) Expand all
48 // occurance. 49 // occurance.
49 virtual void Observe(int type, 50 virtual void Observe(int type,
50 const content::NotificationSource& source, 51 const content::NotificationSource& source,
51 const content::NotificationDetails& details) OVERRIDE; 52 const content::NotificationDetails& details) OVERRIDE;
52 53
53 Database* database() { return database_.get(); } 54 Database* database() { return database_.get(); }
54 FilePath database_path() { return database_path_; } 55 FilePath database_path() { return database_path_; }
55 56
56 private: 57 private:
57 friend struct DefaultSingletonTraits<PerformanceMonitor>; 58 friend struct DefaultSingletonTraits<PerformanceMonitor>;
59 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
60 OneProfileUncleanExit);
61 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
62 TwoProfileUncleanExit);
58 63
59 PerformanceMonitor(); 64 PerformanceMonitor();
60 virtual ~PerformanceMonitor(); 65 virtual ~PerformanceMonitor();
61 66
62 // Perform any additional initialization which must be performed on a 67 // Perform any additional initialization which must be performed on a
63 // background thread (e.g. constructing the database). 68 // background thread (e.g. constructing the database).
64 void InitOnBackgroundThread(); 69 void InitOnBackgroundThread();
65 70
66 void FinishInit(); 71 void FinishInit();
67 72
68 // Register for the appropriate notifications as a NotificationObserver. 73 // Register for the appropriate notifications as a NotificationObserver.
69 void RegisterForNotifications(); 74 void RegisterForNotifications();
70 75
76 // Checks for whether the previous profiles closed uncleanly; this method
77 // should only be called once per run in order to avoid duplication of events
78 // (exceptions made for testing purposes where we construct the environment).
79 void CheckForUncleanExits();
80
81 // Find the last active time for the profile and insert the event into the
82 // database.
83 void AddUncleanExitEvent(std::string profile_name);
Yoyo Zhou 2012/07/12 18:13:44 Just noticed this one should also be a const std::
84
71 // Gets the corresponding value of |key| from the database, and then runs 85 // Gets the corresponding value of |key| from the database, and then runs
72 // |callback| with that value as a parameter. 86 // |callback| with that value as a parameter.
73 void GetStateValueOnBackgroundThread( 87 void GetStateValueOnBackgroundThread(
74 const std::string& key, 88 const std::string& key,
75 const StateValueCallback& callback); 89 const StateValueCallback& callback);
76 90
77 void CheckForVersionUpdateHelper(const std::string& previous_version); 91 void CheckForVersionUpdateHelper(const std::string& previous_version);
78 92
79 // Wrapper function for inserting events into the database. 93 // Wrapper function for inserting events into the database.
80 void AddEvent(scoped_ptr<Event> event); 94 void AddEvent(scoped_ptr<Event> event);
81 95
82 void AddEventOnBackgroundThread(scoped_ptr<Event> event); 96 void AddEventOnBackgroundThread(scoped_ptr<Event> event);
83 97
98 // Update the database record of the last time the active profiles were
99 // running; this is used in determining when an unclean exit occurred.
100 void UpdateLiveProfiles();
101 void UpdateLiveProfilesHelper(
102 scoped_ptr<std::set<std::string> > active_profiles, std::string time);
103
104 // Perform any collections that are done on a timed basis.
105 void DoTimedCollections();
106
84 // The location at which the database files are stored; if empty, the database 107 // The location at which the database files are stored; if empty, the database
85 // will default to '<user_data_dir>/performance_monitor_dbs'. 108 // will default to '<user_data_dir>/performance_monitor_dbs'.
86 FilePath database_path_; 109 FilePath database_path_;
87 110
88 scoped_ptr<Database> database_; 111 scoped_ptr<Database> database_;
89 112
90 content::NotificationRegistrar registrar_; 113 content::NotificationRegistrar registrar_;
91 114
115 base::RepeatingTimer<PerformanceMonitor> timer_;
116
92 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); 117 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
93 }; 118 };
94 119
95 } // namespace performance_monitor 120 } // namespace performance_monitor
96 121
97 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ 122 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/performance_monitor/events.json ('k') | chrome/browser/performance_monitor/performance_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698