#include "chrome/browser/metrics/power/process_monitor.h"
#include <stddef.h>
#include <utility>
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/observer_list.h"
#include "base/process/process_handle.h"
#include "base/process/process_metrics.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "chrome/browser/metrics/power/power_metrics_constants.h"
#include "content/public/browser/browser_child_process_host.h"
#include "content/public/browser/browser_child_process_host_iterator.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_constants.h"
#include "extensions/buildflags/buildflags.h"
#include "services/network/public/mojom/network_service.mojom.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_map.h"
#include "extensions/common/manifest_handlers/background_info.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "sandbox/policy/mojom/sandbox.mojom-shared.h"
#endif
BrowserThread;
namespace {
std::unique_ptr<base::ProcessMetrics> CreateProcessMetrics(
base::ProcessHandle process_handle) { … }
ProcessMonitor::Metrics SampleMetrics(base::ProcessMetrics& process_metrics) { … }
void ScaleMetrics(ProcessMonitor::Metrics* metrics, double factor) { … }
ProcessMonitor::Metrics GetLastIntervalMetrics(
base::ProcessMetrics& process_metrics,
base::TimeDelta cumulative_cpu_usage) { … }
MonitoredProcessType GetMonitoredProcessTypeForRenderProcess(
content::RenderProcessHost* host) { … }
MonitoredProcessType GetMonitoredProcessTypeForNonRendererChildProcess(
const content::ChildProcessData& data) { … }
ProcessMonitor::Metrics& operator+=(ProcessMonitor::Metrics& lhs,
const ProcessMonitor::Metrics& rhs) { … }
}
MonitoredProcessType
GetMonitoredProcessTypeForNonRendererChildProcessForTesting(
const content::ChildProcessData& data) { … }
ProcessInfo::ProcessInfo(MonitoredProcessType type,
std::unique_ptr<base::ProcessMetrics> process_metrics)
: … { … }
ProcessInfo::~ProcessInfo() = default;
ProcessMonitor::Metrics::Metrics() = default;
ProcessMonitor::Metrics::Metrics(const ProcessMonitor::Metrics& other) =
default;
ProcessMonitor::Metrics& ProcessMonitor::Metrics::operator=(
const ProcessMonitor::Metrics& other) = default;
ProcessMonitor::Metrics::~Metrics() = default;
ProcessMonitor::ProcessMonitor()
: … { … }
ProcessMonitor::~ProcessMonitor() { … }
void ProcessMonitor::SampleAllProcesses(Observer* observer) { … }
void ProcessMonitor::OnRenderProcessHostCreated(
content::RenderProcessHost* render_process_host) { … }
void ProcessMonitor::RenderProcessReady(
content::RenderProcessHost* render_process_host) { … }
void ProcessMonitor::RenderProcessExited(
content::RenderProcessHost* render_process_host,
const content::ChildProcessTerminationInfo& info) { … }
void ProcessMonitor::RenderProcessHostDestroyed(
content::RenderProcessHost* render_process_host) { … }
void ProcessMonitor::BrowserChildProcessLaunchedAndConnected(
const content::ChildProcessData& data) { … }
void ProcessMonitor::BrowserChildProcessHostDisconnected(
const content::ChildProcessData& data) { … }
void ProcessMonitor::BrowserChildProcessCrashed(
const content::ChildProcessData& data,
const content::ChildProcessTerminationInfo& info) { … }
void ProcessMonitor::BrowserChildProcessKilled(
const content::ChildProcessData& data,
const content::ChildProcessTerminationInfo& info) { … }
void ProcessMonitor::BrowserChildProcessExitedNormally(
const content::ChildProcessData& data,
const content::ChildProcessTerminationInfo& info) { … }
void ProcessMonitor::OnBrowserChildProcessExited(
const content::ChildProcessData& data,
const content::ChildProcessTerminationInfo& info) { … }