Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / performance_monitor / performance_monitor.h
blob7e1b20f659adcb50b73a3b1acf49dcd0f36ea8eb
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.
5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
8 #include <map>
9 #include <vector>
11 #include "base/process/process_handle.h"
12 #include "base/timer/timer.h"
13 #include "chrome/browser/performance_monitor/process_metrics_history.h"
15 namespace base {
16 template <typename Type>
17 struct DefaultSingletonTraits;
18 } // namespace base
20 namespace content {
21 struct ChildProcessData;
24 namespace performance_monitor {
26 // PerformanceMonitor is a tool which periodically monitors performance metrics
27 // for histogram logging and possibly taking action upon noticing serious
28 // performance degradation.
29 class PerformanceMonitor {
30 public:
31 // Returns the current PerformanceMonitor instance if one exists; otherwise
32 // constructs a new PerformanceMonitor.
33 static PerformanceMonitor* GetInstance();
35 // Start the cycle of metrics gathering.
36 void StartGatherCycle();
38 private:
39 typedef std::map<base::ProcessHandle, ProcessMetricsHistory> MetricsMap;
41 friend struct base::DefaultSingletonTraits<PerformanceMonitor>;
43 PerformanceMonitor();
44 virtual ~PerformanceMonitor();
46 // Perform any collections that are done on a timed basis.
47 void DoTimedCollections();
49 // Mark the given process as alive in the current update iteration.
50 // This means adding an entry to the map of watched processes if it's not
51 // already present.
52 void MarkProcessAsAlive(const ProcessMetricsMetadata& process_data,
53 int current_update_sequence);
54 void MarkProcessesAsAliveOnUIThread(
55 scoped_ptr<std::vector<ProcessMetricsMetadata>> process_data_list,
56 int current_update_sequence);
58 // Updates the ProcessMetrics map with the current list of processes and
59 // gathers metrics from each entry.
60 void GatherMetricsMapOnUIThread();
61 void GatherMetricsMapOnIOThread(int current_update_sequence);
63 void UpdateMetricsOnIOThread(int current_update_sequence);
64 void RunTriggersUIThread();
66 // A map of currently running ProcessHandles to ProcessMetrics.
67 MetricsMap metrics_map_;
69 // The timer to signal PerformanceMonitor to perform its timed collections.
70 base::OneShotTimer<PerformanceMonitor> repeating_timer_;
72 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
75 } // namespace performance_monitor
77 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_