OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 #ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_TAB_CPU_USAGE_OBSERVER_H
_ |
| 6 #define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_TAB_CPU_USAGE_OBSERVER_H
_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <unordered_map> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "services/resource_coordinator/coordination_unit/coordination_unit_grap
h_observer.h" |
| 14 |
| 15 namespace resource_coordinator { |
| 16 |
| 17 class CoordinationUnitImpl; |
| 18 class TabCPUUsageObserver; |
| 19 |
| 20 class TabObserver { |
| 21 public: |
| 22 TabObserver(); |
| 23 ~TabObserver(); |
| 24 |
| 25 static const unsigned int kMaxCPUUsageMeasurementTicks; |
| 26 |
| 27 bool IsObserving(); |
| 28 void AttributeCPUUsage(double cpu_usage); |
| 29 void SetTabCPUUsageObserver(TabCPUUsageObserver* tab_cpu_usage_observer) { |
| 30 tab_cpu_usage_observer_ = tab_cpu_usage_observer; |
| 31 } |
| 32 |
| 33 void TabURLChanged(const CoordinationUnitImpl* tab_coordination_unit, |
| 34 mojom::PropertyType tab_url_property); |
| 35 |
| 36 private: |
| 37 unsigned int cpu_measurement_ticks_; |
| 38 TabCPUUsageObserver* tab_cpu_usage_observer_; |
| 39 std::string url_; |
| 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(TabObserver); |
| 42 }; |
| 43 |
| 44 class ProcessObserver { |
| 45 public: |
| 46 ProcessObserver(); |
| 47 ~ProcessObserver(); |
| 48 |
| 49 void NewCPUUsageMeasurement(const CoordinationUnitImpl* coordination_unit, |
| 50 mojom::PropertyType process_cpu_usage); |
| 51 void RecalculateAttributableTabs( |
| 52 const CoordinationUnitImpl* coordination_unit, |
| 53 const CoordinationUnitImpl* frame_coordination_unit); |
| 54 void SetTabCPUUsageObserver(TabCPUUsageObserver* tab_cpu_usage_observer) { |
| 55 tab_cpu_usage_observer_ = tab_cpu_usage_observer; |
| 56 } |
| 57 |
| 58 private: |
| 59 std::unordered_map<CoordinationUnitID, TabObserver*> attributable_tabs_; |
| 60 TabCPUUsageObserver* tab_cpu_usage_observer_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ProcessObserver); |
| 63 }; |
| 64 |
| 65 class TabCPUUsageObserver : public CoordinationUnitGraphObserver { |
| 66 public: |
| 67 TabCPUUsageObserver(); |
| 68 ~TabCPUUsageObserver() override; |
| 69 |
| 70 std::unordered_map<CoordinationUnitID, ProcessObserver>& process_observers() { |
| 71 return process_observers_; |
| 72 } |
| 73 std::unordered_map<CoordinationUnitID, TabObserver>& tab_observers() { |
| 74 return tab_observers_; |
| 75 } |
| 76 |
| 77 void CoordinationUnitCreated( |
| 78 CoordinationUnitImpl* coordination_unit) override; |
| 79 |
| 80 void ProcessCoordinationUnitCreated( |
| 81 CoordinationUnitImpl* process_coordination_unit); |
| 82 void TabCoordinationUnitCreated(CoordinationUnitImpl* tab_coordination_unit); |
| 83 |
| 84 void RemoveProcessObserver( |
| 85 const CoordinationUnitImpl* process_coordination_unit); |
| 86 void RemoveTabObserver(const CoordinationUnitImpl* tab_coordination_unit); |
| 87 |
| 88 private: |
| 89 std::unordered_map<CoordinationUnitID, ProcessObserver> process_observers_; |
| 90 std::unordered_map<CoordinationUnitID, TabObserver> tab_observers_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(TabCPUUsageObserver); |
| 93 }; |
| 94 |
| 95 } // namespace resource_coordinator |
| 96 |
| 97 #endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_TAB_CPU_USAGE_OBSERVE
R_H_ |
OLD | NEW |