OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_POWER_PROCESS_POWER_COLLECTOR_H_ | 5 #ifndef CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ |
6 #define CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ | 6 #define CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/linked_ptr.h" | |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "base/process/process_metrics.h" | 13 #include "base/process/process_metrics.h" |
14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "components/power/origin_power_map_factory.h" | 16 #include "components/power/origin_power_map_factory.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
20 #include "chromeos/dbus/power_manager_client.h" | 20 #include "chromeos/dbus/power_manager_client.h" |
21 #endif | 21 #endif |
(...skipping 20 matching lines...) Expand all Loading... |
42 class PerProcessData { | 42 class PerProcessData { |
43 public: | 43 public: |
44 PerProcessData(std::unique_ptr<base::ProcessMetrics> metrics, | 44 PerProcessData(std::unique_ptr<base::ProcessMetrics> metrics, |
45 const GURL& origin, | 45 const GURL& origin, |
46 Profile* profile); | 46 Profile* profile); |
47 PerProcessData(); | 47 PerProcessData(); |
48 ~PerProcessData(); | 48 ~PerProcessData(); |
49 | 49 |
50 base::ProcessMetrics* metrics() const { return metrics_.get(); } | 50 base::ProcessMetrics* metrics() const { return metrics_.get(); } |
51 Profile* profile() const { return profile_; } | 51 Profile* profile() const { return profile_; } |
52 GURL last_origin() const { return last_origin_; } | 52 const GURL& last_origin() const { return last_origin_; } |
53 int last_cpu_percent() const { return last_cpu_percent_; } | 53 int last_cpu_percent() const { return last_cpu_percent_; } |
54 bool seen_this_cycle() const { return seen_this_cycle_; } | 54 bool seen_this_cycle() const { return seen_this_cycle_; } |
55 void set_last_cpu_percent(double new_cpu) { last_cpu_percent_ = new_cpu; } | 55 void set_last_cpu_percent(double new_cpu) { last_cpu_percent_ = new_cpu; } |
56 void set_seen_this_cycle(bool seen) { seen_this_cycle_ = seen; } | 56 void set_seen_this_cycle(bool seen) { seen_this_cycle_ = seen; } |
57 | 57 |
58 private: | 58 private: |
59 // |metrics_| holds the ProcessMetrics information for the given process. | 59 // |metrics_| holds the ProcessMetrics information for the given process. |
60 std::unique_ptr<base::ProcessMetrics> metrics_; | 60 std::unique_ptr<base::ProcessMetrics> metrics_; |
61 | 61 |
62 // |profile| is the profile that is visiting the |last_origin_|. | 62 // |profile| is the profile that is visiting the |last_origin_|. |
63 // It is not owned by PerProcessData. | 63 // It is not owned by PerProcessData. |
64 Profile* profile_; | 64 Profile* profile_; |
65 | 65 |
66 // |last_origin_| is the last origin visited by the process. | 66 // |last_origin_| is the last origin visited by the process. |
67 GURL last_origin_; | 67 GURL last_origin_; |
68 | 68 |
69 // |last_cpu_percent_| is the proportion of the CPU used since the last | 69 // |last_cpu_percent_| is the proportion of the CPU used since the last |
70 // query. | 70 // query. |
71 double last_cpu_percent_; | 71 double last_cpu_percent_; |
72 | 72 |
73 // |seen_this_cycle| represents if the process still exists in this cycle. | 73 // |seen_this_cycle| represents if the process still exists in this cycle. |
74 // If it doesn't, we erase the PerProcessData. | 74 // If it doesn't, we erase the PerProcessData. |
75 bool seen_this_cycle_; | 75 bool seen_this_cycle_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(PerProcessData); | 77 DISALLOW_COPY_AND_ASSIGN(PerProcessData); |
78 }; | 78 }; |
79 | 79 |
80 // A map from all process handles to a metric. | 80 // A map from all process handles to a metric. |
81 typedef std::map<base::ProcessHandle, linked_ptr<PerProcessData> > | 81 using ProcessMetricsMap = |
82 ProcessMetricsMap; | 82 std::map<base::ProcessHandle, std::unique_ptr<PerProcessData>>; |
| 83 |
83 // A callback used to define mock CPU usage for testing. | 84 // A callback used to define mock CPU usage for testing. |
84 typedef base::Callback<double(base::ProcessHandle)> CpuUsageCallback; | 85 using CpuUsageCallback = base::Callback<double(base::ProcessHandle)>; |
85 | 86 |
86 // On Chrome OS, can only be initialized after the DBusThreadManager has been | 87 // On Chrome OS, can only be initialized after the DBusThreadManager has been |
87 // initialized. | 88 // initialized. |
88 ProcessPowerCollector(); | 89 ProcessPowerCollector(); |
89 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
90 // On Chrome OS, can only be destroyed before DBusThreadManager is. | 91 // On Chrome OS, can only be destroyed before DBusThreadManager is. |
91 ~ProcessPowerCollector() override; | 92 ~ProcessPowerCollector() override; |
92 #else | 93 #else |
93 virtual ~ProcessPowerCollector(); | 94 virtual ~ProcessPowerCollector(); |
94 #endif | 95 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Callback to use to get CPU usage if set. | 143 // Callback to use to get CPU usage if set. |
143 CpuUsageCallback cpu_usage_callback_; | 144 CpuUsageCallback cpu_usage_callback_; |
144 | 145 |
145 // The factor to scale the CPU usage by. | 146 // The factor to scale the CPU usage by. |
146 double scale_factor_; | 147 double scale_factor_; |
147 | 148 |
148 DISALLOW_COPY_AND_ASSIGN(ProcessPowerCollector); | 149 DISALLOW_COPY_AND_ASSIGN(ProcessPowerCollector); |
149 }; | 150 }; |
150 | 151 |
151 #endif // CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ | 152 #endif // CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ |
OLD | NEW |