| Index: services/resource_coordinator/coordination_unit/process_coordination_unit_impl.cc
|
| diff --git a/services/resource_coordinator/coordination_unit/process_coordination_unit_impl.cc b/services/resource_coordinator/coordination_unit/process_coordination_unit_impl.cc
|
| index b66777f4b659a5529bc8e5469b496c92625e7fcf..fd4b2c9e92ebaaa503ce2a000c1c4c670d9267b5 100644
|
| --- a/services/resource_coordinator/coordination_unit/process_coordination_unit_impl.cc
|
| +++ b/services/resource_coordinator/coordination_unit/process_coordination_unit_impl.cc
|
| @@ -6,59 +6,16 @@
|
|
|
| #include <utility>
|
|
|
| -#include "base/process/process.h"
|
| -#include "base/process/process_handle.h"
|
| -#include "base/process/process_metrics.h"
|
| -#include "base/time/time.h"
|
| #include "base/values.h"
|
|
|
| -#if defined(OS_MACOSX)
|
| -#include "services/service_manager/public/cpp/standalone_service/mach_broker.h"
|
| -#endif
|
| -
|
| -#if defined(OS_WIN)
|
| -#include <windows.h>
|
| -#endif
|
| -
|
| -namespace service_manager {
|
| -class ServiceContextRef;
|
| -}
|
| -
|
| namespace resource_coordinator {
|
|
|
| struct CoordinationUnitID;
|
|
|
| -namespace {
|
| -
|
| -const int kCPUProfilingIntervalInSeconds = 5;
|
| -
|
| -} // namespace
|
| -
|
| ProcessCoordinationUnitImpl::ProcessCoordinationUnitImpl(
|
| const CoordinationUnitID& id,
|
| std::unique_ptr<service_manager::ServiceContextRef> service_ref)
|
| - : CoordinationUnitImpl(id, std::move(service_ref)) {
|
| - // ProcessCoordinationUnit ids should correspond to its pid
|
| - base::ProcessId pid = id.id;
|
| -#if defined(OS_WIN)
|
| - base::Process process =
|
| - base::Process::OpenWithAccess(pid, PROCESS_QUERY_INFORMATION);
|
| -#else
|
| - base::Process process = base::Process::Open(pid);
|
| -#endif
|
| - base::ProcessHandle process_handle = process.Handle();
|
| -
|
| -#if defined(OS_MACOSX)
|
| - process_metrics_ = base::ProcessMetrics::CreateProcessMetrics(
|
| - process_handle,
|
| - service_manager::MachBroker::GetInstance()->port_provider());
|
| -#else
|
| - process_metrics_ = base::ProcessMetrics::CreateProcessMetrics(process_handle);
|
| -#endif
|
| -
|
| - repeating_timer_.Start(FROM_HERE, base::TimeDelta(), this,
|
| - &ProcessCoordinationUnitImpl::MeasureProcessCPUUsage);
|
| -}
|
| + : CoordinationUnitImpl(id, std::move(service_ref)) {}
|
|
|
| ProcessCoordinationUnitImpl::~ProcessCoordinationUnitImpl() = default;
|
|
|
| @@ -92,21 +49,15 @@ ProcessCoordinationUnitImpl::GetAssociatedCoordinationUnitsOfType(
|
| }
|
| }
|
|
|
| -void ProcessCoordinationUnitImpl::MeasureProcessCPUUsage() {
|
| - double cpu_usage = process_metrics_->GetPlatformIndependentCPUUsage();
|
| - SetProperty(mojom::PropertyType::kCPUUsage, base::Value(cpu_usage));
|
| -
|
| - // Trigger tab coordination units to recalculate their CPU usage.
|
| - // TODO(matthalp): Move propagation functionality into a separate,
|
| - // more generalized method to support other property changes.
|
| - for (auto* tab : GetAssociatedCoordinationUnitsOfType(
|
| - CoordinationUnitType::kWebContents)) {
|
| - tab->RecalculateProperty(mojom::PropertyType::kCPUUsage);
|
| +void ProcessCoordinationUnitImpl::PropagateProperty(
|
| + mojom::PropertyType property) {
|
| + if (property == mojom::PropertyType::kCPUUsage) {
|
| + for (auto* tab_coordination_unit : GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kWebContents)) {
|
| + tab_coordination_unit->RecalculateProperty(
|
| + mojom::PropertyType::kCPUUsage);
|
| + }
|
| }
|
| -
|
| - repeating_timer_.Start(
|
| - FROM_HERE, base::TimeDelta::FromSeconds(kCPUProfilingIntervalInSeconds),
|
| - this, &ProcessCoordinationUnitImpl::MeasureProcessCPUUsage);
|
| }
|
|
|
| } // namespace resource_coordinator
|
|
|