| Index: services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.h
|
| diff --git a/services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.h b/services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..787033a437b8b99f5b9320123ab0ebf491e13252
|
| --- /dev/null
|
| +++ b/services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.h
|
| @@ -0,0 +1,97 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_TAB_CPU_USAGE_OBSERVER_H_
|
| +#define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_TAB_CPU_USAGE_OBSERVER_H_
|
| +
|
| +#include <memory>
|
| +#include <string>
|
| +#include <unordered_map>
|
| +
|
| +#include "base/macros.h"
|
| +#include "services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h"
|
| +
|
| +namespace resource_coordinator {
|
| +
|
| +class CoordinationUnitImpl;
|
| +class TabCPUUsageObserver;
|
| +
|
| +class TabObserver {
|
| + public:
|
| + TabObserver();
|
| + ~TabObserver();
|
| +
|
| + static const unsigned int kMaxCPUUsageMeasurementTicks;
|
| +
|
| + bool IsObserving();
|
| + void AttributeCPUUsage(double cpu_usage);
|
| + void SetTabCPUUsageObserver(TabCPUUsageObserver* tab_cpu_usage_observer) {
|
| + tab_cpu_usage_observer_ = tab_cpu_usage_observer;
|
| + }
|
| +
|
| + void TabURLChanged(const CoordinationUnitImpl* tab_coordination_unit,
|
| + mojom::PropertyType tab_url_property);
|
| +
|
| + private:
|
| + unsigned int cpu_measurement_ticks_;
|
| + TabCPUUsageObserver* tab_cpu_usage_observer_;
|
| + std::string url_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TabObserver);
|
| +};
|
| +
|
| +class ProcessObserver {
|
| + public:
|
| + ProcessObserver();
|
| + ~ProcessObserver();
|
| +
|
| + void NewCPUUsageMeasurement(const CoordinationUnitImpl* coordination_unit,
|
| + mojom::PropertyType process_cpu_usage);
|
| + void RecalculateAttributableTabs(
|
| + const CoordinationUnitImpl* coordination_unit,
|
| + const CoordinationUnitImpl* frame_coordination_unit);
|
| + void SetTabCPUUsageObserver(TabCPUUsageObserver* tab_cpu_usage_observer) {
|
| + tab_cpu_usage_observer_ = tab_cpu_usage_observer;
|
| + }
|
| +
|
| + private:
|
| + std::unordered_map<CoordinationUnitID, TabObserver*> attributable_tabs_;
|
| + TabCPUUsageObserver* tab_cpu_usage_observer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ProcessObserver);
|
| +};
|
| +
|
| +class TabCPUUsageObserver : public CoordinationUnitGraphObserver {
|
| + public:
|
| + TabCPUUsageObserver();
|
| + ~TabCPUUsageObserver() override;
|
| +
|
| + std::unordered_map<CoordinationUnitID, ProcessObserver>& process_observers() {
|
| + return process_observers_;
|
| + }
|
| + std::unordered_map<CoordinationUnitID, TabObserver>& tab_observers() {
|
| + return tab_observers_;
|
| + }
|
| +
|
| + void CoordinationUnitCreated(
|
| + CoordinationUnitImpl* coordination_unit) override;
|
| +
|
| + void ProcessCoordinationUnitCreated(
|
| + CoordinationUnitImpl* process_coordination_unit);
|
| + void TabCoordinationUnitCreated(CoordinationUnitImpl* tab_coordination_unit);
|
| +
|
| + void RemoveProcessObserver(
|
| + const CoordinationUnitImpl* process_coordination_unit);
|
| + void RemoveTabObserver(const CoordinationUnitImpl* tab_coordination_unit);
|
| +
|
| + private:
|
| + std::unordered_map<CoordinationUnitID, ProcessObserver> process_observers_;
|
| + std::unordered_map<CoordinationUnitID, TabObserver> tab_observers_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TabCPUUsageObserver);
|
| +};
|
| +
|
| +} // namespace resource_coordinator
|
| +
|
| +#endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_TAB_CPU_USAGE_OBSERVER_H_
|
|
|