Exchange performance scenarios and perfetto tracks with all children
This expands 2 PerformanceManager features that are currently only initialized in renderer processes to all child processes: performance scenario shared memory regions (shared browser to child), and perfetto process track ID's (shared child to browser). Adds a ChildProcessCoordinationUnit interface that's connected to all child processes, including renderers. Moves RequestSharedPerformanceScenarioRegions() to the new interface and renames it InitializeChildProcessCoordination() since it exchanges several bits of data at process startup. Moves the child process ScopedReadOnlyScenarioMemory holders from RenderResourceCoordinatorImpl to a new ChildPerformanceCoordinator class (owned by ChildThreadImpl), which exists in every child process and sends InitializeChildProcessCoordination() on startup. Bug: 378879528,365586676 Change-Id: Iaa5ed4b4cef1a1a0b0110667e0cc3cf0fb343592 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6018369 Commit-Queue: Nasko Oskov <nasko@chromium.org> Reviewed-by: Nasko Oskov <nasko@chromium.org> Auto-Submit: Joe Mason <joenotcharles@google.com> Cr-Commit-Position: refs/heads/main@{#1383864}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
e52ffea684
commit
3771e132c8
chrome/browser/performance_manager
components/performance_manager
content
DEPS
child
BUILD.gnchild_performance_coordinator.ccchild_performance_coordinator.hchild_performance_coordinator_unittest.ccchild_thread_impl.ccchild_thread_impl.h
shell
test
third_party/blink/renderer/controller/performance_manager
@ -25,3 +25,12 @@ void ChromeContentBrowserClientPerformanceManagerPart::
|
||||
registry, render_process_host);
|
||||
}
|
||||
}
|
||||
|
||||
void ChromeContentBrowserClientPerformanceManagerPart::ExposeInterfacesToChild(
|
||||
mojo::BinderMapWithContext<content::BrowserChildProcessHost*>* map) {
|
||||
auto* pm_registry =
|
||||
performance_manager::PerformanceManagerRegistry::GetInstance();
|
||||
if (pm_registry) {
|
||||
pm_registry->GetBinders().ExposeInterfacesToBrowserChildProcess(map);
|
||||
}
|
||||
}
|
||||
|
3
chrome/browser/performance_manager/public/chrome_content_browser_client_performance_manager_part.h
3
chrome/browser/performance_manager/public/chrome_content_browser_client_performance_manager_part.h
@ -26,6 +26,9 @@ class ChromeContentBrowserClientPerformanceManagerPart
|
||||
service_manager::BinderRegistry* registry,
|
||||
blink::AssociatedInterfaceRegistry* associated_registry,
|
||||
content::RenderProcessHost* render_process_host) override;
|
||||
void ExposeInterfacesToChild(
|
||||
mojo::BinderMapWithContext<content::BrowserChildProcessHost*>* map)
|
||||
override;
|
||||
};
|
||||
|
||||
#endif // CHROME_BROWSER_PERFORMANCE_MANAGER_PUBLIC_CHROME_CONTENT_BROWSER_CLIENT_PERFORMANCE_MANAGER_PART_H_
|
||||
|
@ -8,12 +8,15 @@
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "components/performance_manager/graph/process_node_impl.h"
|
||||
#include "components/performance_manager/performance_manager_impl.h"
|
||||
#include "components/performance_manager/performance_manager_tab_helper.h"
|
||||
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
|
||||
#include "components/performance_manager/render_process_user_data.h"
|
||||
#include "content/public/browser/browser_child_process_host.h"
|
||||
#include "content/public/browser/child_process_data.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
@ -23,7 +26,7 @@ namespace performance_manager {
|
||||
|
||||
namespace {
|
||||
|
||||
void BindProcessCoordinationUnit(
|
||||
void BindRenderProcessCoordinationUnit(
|
||||
int render_process_host_id,
|
||||
mojo::PendingReceiver<mojom::ProcessCoordinationUnit> receiver) {
|
||||
content::RenderProcessHost* render_process_host =
|
||||
@ -36,9 +39,45 @@ void BindProcessCoordinationUnit(
|
||||
|
||||
DCHECK(PerformanceManagerImpl::IsAvailable());
|
||||
PerformanceManagerImpl::CallOnGraphImpl(
|
||||
FROM_HERE, base::BindOnce(&ProcessNodeImpl::Bind,
|
||||
base::Unretained(user_data->process_node()),
|
||||
std::move(receiver)));
|
||||
FROM_HERE,
|
||||
base::BindOnce(&ProcessNodeImpl::BindRenderProcessCoordinationUnit,
|
||||
base::Unretained(user_data->process_node()),
|
||||
std::move(receiver)));
|
||||
}
|
||||
|
||||
void BindChildProcessCoordinationUnitOnPMSequence(
|
||||
base::WeakPtr<ProcessNode> process_node,
|
||||
mojo::PendingReceiver<mojom::ChildProcessCoordinationUnit> receiver) {
|
||||
if (process_node) {
|
||||
ProcessNodeImpl::FromNode(process_node.get())
|
||||
->BindChildProcessCoordinationUnit(std::move(receiver));
|
||||
}
|
||||
}
|
||||
|
||||
void BindChildProcessCoordinationUnitForRenderProcessHost(
|
||||
int render_process_host_id,
|
||||
mojo::PendingReceiver<mojom::ChildProcessCoordinationUnit> receiver) {
|
||||
DCHECK(PerformanceManagerImpl::IsAvailable());
|
||||
PerformanceManagerImpl::CallOnGraph(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
&BindChildProcessCoordinationUnitOnPMSequence,
|
||||
PerformanceManagerImpl::GetProcessNodeForRenderProcessHostId(
|
||||
RenderProcessHostId(render_process_host_id)),
|
||||
std::move(receiver)));
|
||||
}
|
||||
|
||||
void BindChildProcessCoordinationUnitForBrowserChildProcessHost(
|
||||
content::BrowserChildProcessHost* host,
|
||||
mojo::PendingReceiver<mojom::ChildProcessCoordinationUnit> receiver) {
|
||||
DCHECK(PerformanceManagerImpl::IsAvailable());
|
||||
PerformanceManagerImpl::CallOnGraph(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
&BindChildProcessCoordinationUnitOnPMSequence,
|
||||
PerformanceManagerImpl::GetProcessNodeForBrowserChildProcessHost(
|
||||
host),
|
||||
std::move(receiver)));
|
||||
}
|
||||
|
||||
void BindDocumentCoordinationUnit(
|
||||
@ -62,8 +101,18 @@ void Binders::ExposeInterfacesToRendererProcess(
|
||||
service_manager::BinderRegistry* registry,
|
||||
content::RenderProcessHost* host) {
|
||||
registry->AddInterface(
|
||||
base::BindRepeating(&BindProcessCoordinationUnit, host->GetID()),
|
||||
base::BindRepeating(&BindRenderProcessCoordinationUnit, host->GetID()),
|
||||
base::SequencedTaskRunner::GetCurrentDefault());
|
||||
registry->AddInterface(
|
||||
base::BindRepeating(&BindChildProcessCoordinationUnitForRenderProcessHost,
|
||||
host->GetID()),
|
||||
base::SequencedTaskRunner::GetCurrentDefault());
|
||||
}
|
||||
|
||||
void Binders::ExposeInterfacesToBrowserChildProcess(
|
||||
mojo::BinderMapWithContext<content::BrowserChildProcessHost*>* map) {
|
||||
map->Add<mojom::ChildProcessCoordinationUnit>(base::BindRepeating(
|
||||
&BindChildProcessCoordinationUnitForBrowserChildProcessHost));
|
||||
}
|
||||
|
||||
void Binders::ExposeInterfacesToRenderFrame(
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "services/service_manager/public/cpp/binder_registry.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserChildProcessHost;
|
||||
class RenderFrameHost;
|
||||
class RenderProcessHost;
|
||||
} // namespace content
|
||||
@ -35,6 +36,12 @@ class Binders {
|
||||
service_manager::BinderRegistry* registry,
|
||||
content::RenderProcessHost* host);
|
||||
|
||||
// Allows the remote non-renderer child process to bind to the corresponding
|
||||
// ProcessNode in the graph. Typically wired up via
|
||||
// ContentBrowserClient::ExposeInterfacesToBrowserChild().
|
||||
void ExposeInterfacesToBrowserChildProcess(
|
||||
mojo::BinderMapWithContext<content::BrowserChildProcessHost*>* map);
|
||||
|
||||
// Allows the remote renderer frame to bind to its corresponding FrameNode in
|
||||
// the graph. Typically wired up via
|
||||
// ContentBrowserClient::RegisterBrowserInterfaceBindersForFrame().
|
||||
|
@ -97,13 +97,22 @@ ProcessNodeImpl::~ProcessNodeImpl() {
|
||||
CHECK(worker_nodes_.empty());
|
||||
}
|
||||
|
||||
void ProcessNodeImpl::Bind(
|
||||
void ProcessNodeImpl::BindRenderProcessCoordinationUnit(
|
||||
mojo::PendingReceiver<mojom::ProcessCoordinationUnit> receiver) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
// A RenderProcessHost can be reused if the backing process suddenly dies, in
|
||||
// which case we will receive a new receiver from the newly spawned process.
|
||||
receiver_.reset();
|
||||
receiver_.Bind(std::move(receiver));
|
||||
render_process_receiver_.reset();
|
||||
render_process_receiver_.Bind(std::move(receiver));
|
||||
}
|
||||
|
||||
void ProcessNodeImpl::BindChildProcessCoordinationUnit(
|
||||
mojo::PendingReceiver<mojom::ChildProcessCoordinationUnit> receiver) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
// A RenderProcessHost can be reused if the backing process suddenly dies, in
|
||||
// which case we will receive a new receiver from the newly spawned process.
|
||||
child_process_receiver_.reset();
|
||||
child_process_receiver_.Bind(std::move(receiver));
|
||||
}
|
||||
|
||||
void ProcessNodeImpl::SetMainThreadTaskLoadIsLow(
|
||||
@ -181,16 +190,14 @@ void ProcessNodeImpl::OnRemoteIframeDetached(
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessNodeImpl::RequestSharedPerformanceScenarioRegions(
|
||||
void ProcessNodeImpl::InitializeChildProcessCoordination(
|
||||
uint64_t process_track_id,
|
||||
RequestSharedPerformanceScenarioRegionsCallback callback) {
|
||||
InitializeChildProcessCoordinationCallback callback) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
// Should not be called for the Browser process, which already has a track.
|
||||
// Otherwise, it's ok to overwrite `tracing_track_`, since processes can be
|
||||
// re-initialized for the same ProcessNode (eg. after a crash).
|
||||
// TODO(crbug.com/374302723): Rename the Mojo message that sets this, since
|
||||
// the track ID is used for more than PerformanceScenarios now.
|
||||
CHECK_NE(process_type_, content::PROCESS_TYPE_BROWSER);
|
||||
tracing_track_.emplace(perfetto::Track::Global(process_track_id));
|
||||
|
||||
@ -322,7 +329,8 @@ void ProcessNodeImpl::SetProcessExitStatus(int32_t exit_status) {
|
||||
process_.SetAndNotify(this, base::Process());
|
||||
|
||||
// No more message should be received from this process.
|
||||
receiver_.reset();
|
||||
render_process_receiver_.reset();
|
||||
child_process_receiver_.reset();
|
||||
}
|
||||
|
||||
void ProcessNodeImpl::SetProcessMetricsName(const std::string& metrics_name) {
|
||||
|
@ -59,6 +59,7 @@ class ProcessNodeImpl
|
||||
: public PublicNodeImpl<ProcessNodeImpl, ProcessNode>,
|
||||
public TypedNodeBase<ProcessNodeImpl, ProcessNode, ProcessNodeObserver>,
|
||||
public mojom::ProcessCoordinationUnit,
|
||||
public mojom::ChildProcessCoordinationUnit,
|
||||
public SupportsNodeInlineData<ProcessPriorityAggregatorData,
|
||||
FrozenData,
|
||||
PerformanceScenarioMemoryData,
|
||||
@ -87,7 +88,10 @@ class ProcessNodeImpl
|
||||
|
||||
~ProcessNodeImpl() override;
|
||||
|
||||
void Bind(mojo::PendingReceiver<mojom::ProcessCoordinationUnit> receiver);
|
||||
void BindRenderProcessCoordinationUnit(
|
||||
mojo::PendingReceiver<mojom::ProcessCoordinationUnit> receiver);
|
||||
void BindChildProcessCoordinationUnit(
|
||||
mojo::PendingReceiver<mojom::ChildProcessCoordinationUnit> receiver);
|
||||
|
||||
// mojom::ProcessCoordinationUnit implementation:
|
||||
void SetMainThreadTaskLoadIsLow(bool main_thread_task_load_is_low) override;
|
||||
@ -105,9 +109,11 @@ class ProcessNodeImpl
|
||||
void OnRemoteIframeDetached(
|
||||
const blink::LocalFrameToken& parent_frame_token,
|
||||
const blink::RemoteFrameToken& remote_frame_token) override;
|
||||
void RequestSharedPerformanceScenarioRegions(
|
||||
|
||||
// mojom::ChildProcessCoordinationUnit implementation:
|
||||
void InitializeChildProcessCoordination(
|
||||
uint64_t process_track_id,
|
||||
RequestSharedPerformanceScenarioRegionsCallback callback) override;
|
||||
InitializeChildProcessCoordinationCallback callback) override;
|
||||
|
||||
// Partial ProcessNode implementation:
|
||||
content::ProcessType GetProcessType() const override;
|
||||
@ -206,7 +212,12 @@ class ProcessNodeImpl
|
||||
void OnBeforeLeavingGraph() override;
|
||||
void RemoveNodeAttachedData() override;
|
||||
|
||||
mojo::Receiver<mojom::ProcessCoordinationUnit> receiver_
|
||||
// Receiver for renderer-only messages.
|
||||
mojo::Receiver<mojom::ProcessCoordinationUnit> render_process_receiver_
|
||||
GUARDED_BY_CONTEXT(sequence_checker_){this};
|
||||
|
||||
// Receiver for messages from all child processes.
|
||||
mojo::Receiver<mojom::ChildProcessCoordinationUnit> child_process_receiver_
|
||||
GUARDED_BY_CONTEXT(sequence_checker_){this};
|
||||
|
||||
uint64_t private_footprint_kb_ GUARDED_BY_CONTEXT(sequence_checker_) = 0u;
|
||||
|
@ -277,12 +277,12 @@ TEST_F(ProcessNodeImplTest, PublicInterface) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ProcessNodeImplTest, RequestSharedPerformanceScenarioRegions) {
|
||||
TEST_F(ProcessNodeImplTest, InitializeChildProcessCoordination) {
|
||||
auto process_node = CreateNode<ProcessNodeImpl>();
|
||||
|
||||
// No global memory mapped. ProcessNodeImpl automatically creates a process
|
||||
// memory region on request.
|
||||
process_node->RequestSharedPerformanceScenarioRegions(
|
||||
process_node->InitializeChildProcessCoordination(
|
||||
0u, base::BindLambdaForTesting(
|
||||
[&](base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region) {
|
||||
@ -294,7 +294,7 @@ TEST_F(ProcessNodeImplTest, RequestSharedPerformanceScenarioRegions) {
|
||||
|
||||
// Map global memory.
|
||||
ScopedGlobalScenarioMemory global_shared_memory;
|
||||
process_node->RequestSharedPerformanceScenarioRegions(
|
||||
process_node->InitializeChildProcessCoordination(
|
||||
0u, base::BindLambdaForTesting(
|
||||
[&](base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region) {
|
||||
@ -309,7 +309,7 @@ TEST_F(ProcessNodeImplTest, RequestSharedPerformanceScenarioRegions) {
|
||||
base::test::ScopedCommandLine scoped_command_line;
|
||||
scoped_command_line.GetProcessCommandLine()->AppendSwitch(
|
||||
switches::kSingleProcess);
|
||||
process_node->RequestSharedPerformanceScenarioRegions(
|
||||
process_node->InitializeChildProcessCoordination(
|
||||
0u, base::BindLambdaForTesting(
|
||||
[&](base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region) {
|
||||
|
@ -67,8 +67,10 @@ interface DocumentCoordinationUnit {
|
||||
(WebMemoryMeasurement measurement);
|
||||
};
|
||||
|
||||
// Interface used by the RendererResourceCoordinator singleton to send state
|
||||
// associated with resource management of a renderer process to the embedder.
|
||||
// Interface used by the RendererResourceCoordinator singleton to send or
|
||||
// request state associated with resource management of a renderer process.
|
||||
// Implemented in the embedder by ProcessNodeImpl.
|
||||
// TODO(crbug.com/365586676): Rename to RendererProcessCoordinationUnit.
|
||||
interface ProcessCoordinationUnit {
|
||||
// Property signals.
|
||||
SetMainThreadTaskLoadIsLow(bool main_thread_task_load_is_low);
|
||||
@ -119,15 +121,23 @@ interface ProcessCoordinationUnit {
|
||||
// by OnRemoteIframeAttached.
|
||||
OnRemoteIframeDetached(blink.mojom.LocalFrameToken parent_frame_token,
|
||||
blink.mojom.RemoteFrameToken remote_frame_token);
|
||||
};
|
||||
|
||||
// Called immediately after the interface is connected, to request shared
|
||||
// memory regions that communicate state values between the browser and the
|
||||
// renderer. If any returned region handle is invalid, the renderer will use
|
||||
// default state instead of reading from that memory region.
|
||||
// Interface used by ChildThreadImpl to send or request state associated with
|
||||
// resource management of any child process. Implemented in the embedder by
|
||||
// ProcessNodeImpl.
|
||||
interface ChildProcessCoordinationUnit {
|
||||
// Called immediately after the interface is connected, to send and receive
|
||||
// initial state:
|
||||
//
|
||||
// `process_track_id` is the uuid of the renderer's perfetto::ProcessTrack.
|
||||
// If it's non-zero, the browser process will use this to record trace events
|
||||
// when it updates state in `process_region`.
|
||||
// `process_track_id` is the uuid of the child's perfetto::ProcessTrack. If
|
||||
// it's non-zero, the browser process can use this to record trace events
|
||||
// associated with the child process.
|
||||
//
|
||||
// The browser sends back handles to shared memory regions that communicate
|
||||
// state values between the browser and the child. If any returned region
|
||||
// handle is invalid, the child will use default state instead of reading from
|
||||
// that memory region.
|
||||
//
|
||||
// `global_region` should contain a list of `std::atomic` enums representing
|
||||
// global scenarios that the renderer should use when making performance
|
||||
@ -136,7 +146,7 @@ interface ProcessCoordinationUnit {
|
||||
// `process_region` should contain a list of `std::atomic` enums representing
|
||||
// scenarios local to the renderer process that it should use when making
|
||||
// performance decisions.
|
||||
RequestSharedPerformanceScenarioRegions(uint64 process_track_id) =>
|
||||
InitializeChildProcessCoordination(uint64 process_track_id) =>
|
||||
(mojo_base.mojom.ReadOnlySharedMemoryRegion? global_region,
|
||||
mojo_base.mojom.ReadOnlySharedMemoryRegion? process_region);
|
||||
};
|
||||
|
@ -29,6 +29,9 @@ include_rules = [
|
||||
"+components/browsing_topics/common",
|
||||
"+components/input",
|
||||
"+components/memory_pressure",
|
||||
# components/performance_manager sits between chrome/ and content/, except for
|
||||
# the mojo interfaces it exposes to content/ and third_party/blink/.
|
||||
"+components/performance_manager/public/mojom",
|
||||
"+components/services/filesystem",
|
||||
"+components/services/font/public",
|
||||
"+components/services/font_data/public",
|
||||
|
@ -41,6 +41,8 @@ target(link_target_type, "child") {
|
||||
"blink_platform_impl.h",
|
||||
"browser_exposed_child_interfaces.cc",
|
||||
"browser_exposed_child_interfaces.h",
|
||||
"child_performance_coordinator.cc",
|
||||
"child_performance_coordinator.h",
|
||||
"child_process.cc",
|
||||
"child_process.h",
|
||||
"child_process_synthetic_trial_syncer.cc",
|
||||
@ -72,6 +74,7 @@ target(link_target_type, "child") {
|
||||
"//components/discardable_memory/client",
|
||||
"//components/discardable_memory/public/mojom",
|
||||
"//components/metrics",
|
||||
"//components/performance_manager/public/mojom",
|
||||
"//components/permissions:permissions_common",
|
||||
"//components/tracing:startup_tracing",
|
||||
"//components/variations",
|
||||
|
54
content/child/child_performance_coordinator.cc
Normal file
54
content/child/child_performance_coordinator.cc
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "content/child/child_performance_coordinator.h"
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/read_only_shared_memory_region.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/sequence_checker.h"
|
||||
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "third_party/blink/public/common/performance/performance_scenarios.h"
|
||||
#include "third_party/perfetto/include/perfetto/tracing/track.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
ChildPerformanceCoordinator::ChildPerformanceCoordinator() = default;
|
||||
|
||||
ChildPerformanceCoordinator::~ChildPerformanceCoordinator() = default;
|
||||
|
||||
mojo::PendingReceiver<performance_manager::mojom::ChildProcessCoordinationUnit>
|
||||
ChildPerformanceCoordinator::InitializeAndPassReceiver() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
auto receiver = coordination_unit_.BindNewPipeAndPassReceiver();
|
||||
coordination_unit_->InitializeChildProcessCoordination(
|
||||
perfetto::ProcessTrack::Current().uuid,
|
||||
base::BindOnce(
|
||||
&ChildPerformanceCoordinator::OnInitializeChildProcessCoordination,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
return receiver;
|
||||
}
|
||||
|
||||
void ChildPerformanceCoordinator::OnInitializeChildProcessCoordination(
|
||||
base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
using blink::performance_scenarios::ScenarioScope;
|
||||
if (global_region.IsValid()) {
|
||||
global_scenario_memory_.emplace(ScenarioScope::kGlobal,
|
||||
std::move(global_region));
|
||||
}
|
||||
if (process_region.IsValid()) {
|
||||
process_scenario_memory_.emplace(ScenarioScope::kCurrentProcess,
|
||||
std::move(process_region));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace content
|
64
content/child/child_performance_coordinator.h
Normal file
64
content/child/child_performance_coordinator.h
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CONTENT_CHILD_CHILD_PERFORMANCE_COORDINATOR_H_
|
||||
#define CONTENT_CHILD_CHILD_PERFORMANCE_COORDINATOR_H_
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "base/memory/read_only_shared_memory_region.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/sequence_checker.h"
|
||||
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
|
||||
#include "content/common/content_export.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "third_party/blink/public/common/performance/performance_scenarios.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
// Communicates performance information with the browser over a
|
||||
// performance_manager::mojom::ChildProcessCoordinationUnit interface.
|
||||
class CONTENT_EXPORT ChildPerformanceCoordinator {
|
||||
public:
|
||||
ChildPerformanceCoordinator();
|
||||
~ChildPerformanceCoordinator();
|
||||
|
||||
ChildPerformanceCoordinator(const ChildPerformanceCoordinator&) = delete;
|
||||
ChildPerformanceCoordinator& operator=(const ChildPerformanceCoordinator&) =
|
||||
delete;
|
||||
|
||||
// Returns a PendingReceiver to forward to the browser process, and queues an
|
||||
// InitializeChildProcessCoordination message on it.
|
||||
mojo::PendingReceiver<
|
||||
performance_manager::mojom::ChildProcessCoordinationUnit>
|
||||
InitializeAndPassReceiver();
|
||||
|
||||
private:
|
||||
// Receives the results of
|
||||
// ChildProcessCoordinationUnit::InitializeChildProcessCoordination().
|
||||
void OnInitializeChildProcessCoordination(
|
||||
base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region);
|
||||
|
||||
SEQUENCE_CHECKER(sequence_checker_);
|
||||
|
||||
// An interface to the browser's PerformanceManager.
|
||||
mojo::Remote<performance_manager::mojom::ChildProcessCoordinationUnit>
|
||||
coordination_unit_ GUARDED_BY_CONTEXT(sequence_checker_);
|
||||
|
||||
// Scopers to manage the lifetime of shared memory regions for performance
|
||||
// scenarios. These regions are read by functions in
|
||||
// //third_party/blink/public/common/performance/performance_scenarios.h.
|
||||
std::optional<blink::performance_scenarios::ScopedReadOnlyScenarioMemory>
|
||||
process_scenario_memory_ GUARDED_BY_CONTEXT(sequence_checker_);
|
||||
std::optional<blink::performance_scenarios::ScopedReadOnlyScenarioMemory>
|
||||
global_scenario_memory_ GUARDED_BY_CONTEXT(sequence_checker_);
|
||||
|
||||
base::WeakPtrFactory<ChildPerformanceCoordinator> weak_factory_{this};
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_CHILD_CHILD_PERFORMANCE_COORDINATOR_H_
|
141
content/child/child_performance_coordinator_unittest.cc
Normal file
141
content/child/child_performance_coordinator_unittest.cc
Normal file
@ -0,0 +1,141 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "content/child/child_performance_coordinator.h"
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/read_only_shared_memory_region.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/memory/structured_shared_memory.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "components/performance_manager/public/mojom/coordination_unit.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/receiver.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/performance/performance_scenarios.h"
|
||||
|
||||
namespace content {
|
||||
namespace {
|
||||
|
||||
using blink::performance_scenarios::ScenarioScope;
|
||||
using blink::performance_scenarios::ScenarioState;
|
||||
using blink::performance_scenarios::ScopedReadOnlyScenarioMemory;
|
||||
using performance_manager::mojom::ChildProcessCoordinationUnit;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
|
||||
using InitializeChildProcessCoordinationCallback =
|
||||
ChildProcessCoordinationUnit::InitializeChildProcessCoordinationCallback;
|
||||
|
||||
class MockChildProcessCoordinationUnit : public ChildProcessCoordinationUnit {
|
||||
public:
|
||||
MOCK_METHOD(void,
|
||||
InitializeChildProcessCoordination,
|
||||
(uint64_t, InitializeChildProcessCoordinationCallback),
|
||||
(override));
|
||||
|
||||
void Bind(mojo::PendingReceiver<ChildProcessCoordinationUnit> receiver) {
|
||||
receiver_.Bind(std::move(receiver));
|
||||
}
|
||||
|
||||
private:
|
||||
mojo::Receiver<ChildProcessCoordinationUnit> receiver_{this};
|
||||
};
|
||||
|
||||
using StrictMockChildProcessCoordinationUnit =
|
||||
::testing::StrictMock<MockChildProcessCoordinationUnit>;
|
||||
|
||||
class ChildPerformanceCoordinatorTest : public ::testing::Test {
|
||||
public:
|
||||
// Initializes `coordinator` and waits for a mock ChildProcessCoordinationUnit
|
||||
// to send it `global_region` and `process_region`.
|
||||
void InitializeAndWaitForScenarioRegions(
|
||||
ChildPerformanceCoordinator& coordinator,
|
||||
base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region) {
|
||||
global_region_ = std::move(global_region);
|
||||
process_region_ = std::move(process_region);
|
||||
quit_closure_ = task_env_.QuitClosure();
|
||||
|
||||
StrictMockChildProcessCoordinationUnit mock_coordination_unit;
|
||||
EXPECT_CALL(mock_coordination_unit,
|
||||
InitializeChildProcessCoordination(_, _))
|
||||
.WillOnce(Invoke(
|
||||
this,
|
||||
&ChildPerformanceCoordinatorTest::SendScenarioRegionsAndQuit));
|
||||
mock_coordination_unit.Bind(coordinator.InitializeAndPassReceiver());
|
||||
task_env_.RunUntilQuit();
|
||||
}
|
||||
|
||||
// Invokes `callback` with the `global_region_` and `process_region_` and
|
||||
// quits the run loop.
|
||||
void SendScenarioRegionsAndQuit(
|
||||
uint64_t,
|
||||
InitializeChildProcessCoordinationCallback callback) {
|
||||
std::move(callback).Run(std::move(global_region_),
|
||||
std::move(process_region_));
|
||||
// `callback` will post to ChildPerformanceCoordinator. Quit the runloop
|
||||
// after the posted task.
|
||||
task_env_.GetMainThreadTaskRunner()->PostTask(FROM_HERE,
|
||||
std::move(quit_closure_));
|
||||
}
|
||||
|
||||
private:
|
||||
base::test::TaskEnvironment task_env_;
|
||||
|
||||
// State used by SendScenarioRegionsAndQuit.
|
||||
base::ReadOnlySharedMemoryRegion global_region_;
|
||||
base::ReadOnlySharedMemoryRegion process_region_;
|
||||
base::OnceClosure quit_closure_;
|
||||
};
|
||||
|
||||
TEST_F(ChildPerformanceCoordinatorTest, NoScenarioRegion) {
|
||||
ChildPerformanceCoordinator coordinator;
|
||||
InitializeAndWaitForScenarioRegions(coordinator,
|
||||
base::ReadOnlySharedMemoryRegion(),
|
||||
base::ReadOnlySharedMemoryRegion());
|
||||
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kGlobal));
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kCurrentProcess));
|
||||
}
|
||||
|
||||
TEST_F(ChildPerformanceCoordinatorTest, GlobalScenarioRegion) {
|
||||
auto shared_memory = base::StructuredSharedMemory<ScenarioState>::Create();
|
||||
ASSERT_TRUE(shared_memory.has_value());
|
||||
|
||||
ChildPerformanceCoordinator coordinator;
|
||||
InitializeAndWaitForScenarioRegions(coordinator,
|
||||
shared_memory->TakeReadOnlyRegion(),
|
||||
base::ReadOnlySharedMemoryRegion());
|
||||
|
||||
EXPECT_TRUE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kGlobal));
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kCurrentProcess));
|
||||
}
|
||||
|
||||
TEST_F(ChildPerformanceCoordinatorTest, ProcessScenarioRegion) {
|
||||
auto shared_memory = base::StructuredSharedMemory<ScenarioState>::Create();
|
||||
ASSERT_TRUE(shared_memory.has_value());
|
||||
|
||||
ChildPerformanceCoordinator coordinator;
|
||||
InitializeAndWaitForScenarioRegions(coordinator,
|
||||
base::ReadOnlySharedMemoryRegion(),
|
||||
shared_memory->TakeReadOnlyRegion());
|
||||
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kGlobal));
|
||||
EXPECT_TRUE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kCurrentProcess));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace content
|
@ -43,6 +43,7 @@
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/child/browser_exposed_child_interfaces.h"
|
||||
#include "content/child/child_performance_coordinator.h"
|
||||
#include "content/child/child_process.h"
|
||||
#include "content/child/child_process_synthetic_trial_syncer.h"
|
||||
#include "content/common/child_process.mojom.h"
|
||||
@ -721,6 +722,9 @@ void ChildThreadImpl::Init(const Options& options) {
|
||||
source_ptr->Init(std::move(remote_power_monitor));
|
||||
}
|
||||
|
||||
performance_coordinator_ = std::make_unique<ChildPerformanceCoordinator>();
|
||||
BindHostReceiver(performance_coordinator_->InitializeAndPassReceiver());
|
||||
|
||||
#if BUILDFLAG(IS_POSIX)
|
||||
// Check that --process-type is specified so we don't do this in unit tests
|
||||
// and single-process mode.
|
||||
|
@ -61,6 +61,8 @@ class BackgroundTracingAgentProviderImpl;
|
||||
} // namespace tracing
|
||||
|
||||
namespace content {
|
||||
|
||||
class ChildPerformanceCoordinator;
|
||||
class InProcessChildThreadParams;
|
||||
|
||||
// The main thread of a child process derives from this class.
|
||||
@ -253,6 +255,8 @@ class ChildThreadImpl : public IPC::Listener, virtual public ChildThread {
|
||||
// implementation of the mojom ChildProcess interface.
|
||||
scoped_refptr<IOThreadState> io_thread_state_;
|
||||
|
||||
std::unique_ptr<ChildPerformanceCoordinator> performance_coordinator_;
|
||||
|
||||
base::WeakPtrFactory<ChildThreadImpl> weak_factory_{this};
|
||||
};
|
||||
|
||||
|
@ -612,6 +612,13 @@ void ShellContentBrowserClient::ExposeInterfacesToRenderer(
|
||||
.ExposeInterfacesToRendererProcess(registry, render_process_host);
|
||||
}
|
||||
|
||||
void ShellContentBrowserClient::ExposeInterfacesToChild(
|
||||
mojo::BinderMapWithContext<content::BrowserChildProcessHost*>* map) {
|
||||
PerformanceManagerRegistry::GetInstance()
|
||||
->GetBinders()
|
||||
.ExposeInterfacesToBrowserChildProcess(map);
|
||||
}
|
||||
|
||||
mojo::Remote<::media::mojom::MediaService>
|
||||
ShellContentBrowserClient::RunSecondaryMediaService() {
|
||||
mojo::Remote<::media::mojom::MediaService> remote;
|
||||
|
@ -111,6 +111,9 @@ class ShellContentBrowserClient : public ContentBrowserClient {
|
||||
service_manager::BinderRegistry* registry,
|
||||
blink::AssociatedInterfaceRegistry* associated_registry,
|
||||
RenderProcessHost* render_process_host) override;
|
||||
void ExposeInterfacesToChild(
|
||||
mojo::BinderMapWithContext<content::BrowserChildProcessHost*>* map)
|
||||
override;
|
||||
mojo::Remote<::media::mojom::MediaService> RunSecondaryMediaService()
|
||||
override;
|
||||
void RegisterBrowserInterfaceBindersForFrame(
|
||||
|
@ -2916,6 +2916,7 @@ test("content_unittests") {
|
||||
"../browser/worker_host/worker_script_loader_factory_unittest.cc",
|
||||
"../browser/xr/metrics/session_tracker_unittest.cc",
|
||||
"../child/blink_platform_impl_unittest.cc",
|
||||
"../child/child_performance_coordinator_unittest.cc",
|
||||
"../child/child_process_synthetic_trial_syncer_unittest.cc",
|
||||
"../common/background_fetch/background_fetch_mojom_traits_unittest.cc",
|
||||
"../common/color_parser_unittest.cc",
|
||||
@ -3098,6 +3099,7 @@ test("content_unittests") {
|
||||
"//components/network_session_configurator/common",
|
||||
"//components/offline_pages/buildflags",
|
||||
"//components/payments/mojom",
|
||||
"//components/performance_manager/public/mojom",
|
||||
"//components/permissions:permissions_common",
|
||||
"//components/permissions:test_support",
|
||||
"//components/services/quarantine/public/mojom",
|
||||
|
24
third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl.cc
vendored
24
third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl.cc
vendored
@ -4,13 +4,11 @@
|
||||
|
||||
#include "third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl.h"
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/memory/structured_shared_memory.h"
|
||||
#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
|
||||
#include "third_party/blink/public/common/performance/performance_scenarios.h"
|
||||
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
|
||||
#include "third_party/blink/public/common/tokens/tokens.h"
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
@ -258,14 +256,6 @@ RendererResourceCoordinatorImpl::RendererResourceCoordinatorImpl(
|
||||
service_task_runner_ =
|
||||
Thread::MainThread()->GetTaskRunner(MainThreadTaskRunnerRestricted());
|
||||
service_.Bind(std::move(remote));
|
||||
CHECK(service_task_runner_->RunsTasksInCurrentSequence());
|
||||
// Unretained is safe because the renderer resource coordinator is a singleton
|
||||
// that leaks at process shutdown.
|
||||
service_->RequestSharedPerformanceScenarioRegions(
|
||||
perfetto::ProcessTrack::Current().uuid,
|
||||
WTF::BindOnce(
|
||||
&RendererResourceCoordinatorImpl::OnSharedPerformanceScenarioRegions,
|
||||
WTF::Unretained(this)));
|
||||
}
|
||||
|
||||
void RendererResourceCoordinatorImpl::DispatchOnV8ContextCreated(
|
||||
@ -320,18 +310,4 @@ void RendererResourceCoordinatorImpl::DispatchOnV8ContextDestroyed(
|
||||
}
|
||||
}
|
||||
|
||||
void RendererResourceCoordinatorImpl::OnSharedPerformanceScenarioRegions(
|
||||
base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region) {
|
||||
using blink::performance_scenarios::ScenarioScope;
|
||||
if (global_region.IsValid()) {
|
||||
global_performance_scenario_memory_.emplace(ScenarioScope::kGlobal,
|
||||
std::move(global_region));
|
||||
}
|
||||
if (process_region.IsValid()) {
|
||||
process_performance_scenario_memory_.emplace(ScenarioScope::kCurrentProcess,
|
||||
std::move(process_region));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
18
third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl.h
vendored
18
third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl.h
vendored
@ -5,15 +5,11 @@
|
||||
#ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PERFORMANCE_MANAGER_RENDERER_RESOURCE_COORDINATOR_IMPL_H_
|
||||
#define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PERFORMANCE_MANAGER_RENDERER_RESOURCE_COORDINATOR_IMPL_H_
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "base/memory/read_only_shared_memory_region.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "components/performance_manager/public/mojom/coordination_unit.mojom-blink.h"
|
||||
#include "components/performance_manager/public/mojom/v8_contexts.mojom-blink.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "third_party/blink/public/common/performance/performance_scenarios.h"
|
||||
#include "third_party/blink/public/common/tokens/tokens.h"
|
||||
#include "third_party/blink/renderer/controller/controller_export.h"
|
||||
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/renderer_resource_coordinator.h"
|
||||
@ -63,23 +59,9 @@ class CONTROLLER_EXPORT RendererResourceCoordinatorImpl final
|
||||
void DispatchOnV8ContextDestroyed(const blink::V8ContextToken& token);
|
||||
void DispatchFireBackgroundTracingTrigger(const String& trigger_name);
|
||||
|
||||
// Receives the results of
|
||||
// ProcessCoordinationUnit::RequestSharedPerformanceScenarioRegions().
|
||||
void OnSharedPerformanceScenarioRegions(
|
||||
base::ReadOnlySharedMemoryRegion global_region,
|
||||
base::ReadOnlySharedMemoryRegion process_region);
|
||||
|
||||
mojo::Remote<performance_manager::mojom::blink::ProcessCoordinationUnit>
|
||||
service_;
|
||||
scoped_refptr<base::SequencedTaskRunner> service_task_runner_;
|
||||
|
||||
// Scopers to manage the lifetime of shared memory regions for performance
|
||||
// scenarios. These regions are read by functions in
|
||||
// //third_party/blink/public/common/performance/performance_scenarios.h.
|
||||
std::optional<blink::performance_scenarios::ScopedReadOnlyScenarioMemory>
|
||||
process_performance_scenario_memory_;
|
||||
std::optional<blink::performance_scenarios::ScopedReadOnlyScenarioMemory>
|
||||
global_performance_scenario_memory_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
79
third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl_test.cc
vendored
79
third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl_test.cc
vendored
@ -8,16 +8,13 @@
|
||||
#include <utility>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/memory/read_only_shared_memory_region.h"
|
||||
#include "components/performance_manager/public/mojom/coordination_unit.mojom-blink.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "mojo/public/cpp/bindings/receiver.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/performance/performance_scenarios.h"
|
||||
#include "third_party/blink/public/common/tokens/tokens.h"
|
||||
#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom-blink.h"
|
||||
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
|
||||
@ -33,9 +30,6 @@ namespace blink {
|
||||
|
||||
namespace {
|
||||
|
||||
using blink::performance_scenarios::ScenarioScope;
|
||||
using blink::performance_scenarios::ScenarioState;
|
||||
using blink::performance_scenarios::ScopedReadOnlyScenarioMemory;
|
||||
using performance_manager::mojom::blink::IframeAttributionData;
|
||||
using performance_manager::mojom::blink::IframeAttributionDataPtr;
|
||||
using performance_manager::mojom::blink::ProcessCoordinationUnit;
|
||||
@ -81,10 +75,6 @@ class MockProcessCoordinationUnit : public ProcessCoordinationUnit {
|
||||
(const blink::LocalFrameToken& parent_frame_token,
|
||||
const blink::RemoteFrameToken& remote_frame_token),
|
||||
(override));
|
||||
MOCK_METHOD(void,
|
||||
RequestSharedPerformanceScenarioRegions,
|
||||
(uint64_t, RequestSharedPerformanceScenarioRegionsCallback),
|
||||
(override));
|
||||
|
||||
void VerifyExpectations() {
|
||||
// Ensure that any pending Mojo messages are processed.
|
||||
@ -129,15 +119,9 @@ class RendererResourceCoordinatorImplTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
// Creates a MockProcessCoordinationUnit and binds it to a
|
||||
// RendererResourceCoordinatorImpl. `global_region` and `process_region` will
|
||||
// be sent in reply to the RequestSharedPerformanceScenarioRegions() call from
|
||||
// the RendererResourceCoordinatorImpl constructor.
|
||||
// RendererResourceCoordinatorImpl.
|
||||
template <typename MockType>
|
||||
void InitializeMockProcessCoordinationUnit(
|
||||
base::ReadOnlySharedMemoryRegion global_region =
|
||||
base::ReadOnlySharedMemoryRegion(),
|
||||
base::ReadOnlySharedMemoryRegion process_region =
|
||||
base::ReadOnlySharedMemoryRegion()) {
|
||||
void InitializeMockProcessCoordinationUnit() {
|
||||
DCHECK(!mock_process_coordination_unit_);
|
||||
DCHECK(!resource_coordinator_);
|
||||
|
||||
@ -145,29 +129,12 @@ class RendererResourceCoordinatorImplTest : public ::testing::Test {
|
||||
mock_process_coordination_unit_ = std::make_unique<MockType>(
|
||||
pending_remote.InitWithNewPipeAndPassReceiver());
|
||||
|
||||
// The RendererResourceCoordinatorImpl constructor will always call
|
||||
// RequestSharedPerformanceScenarioRegions().
|
||||
base::OnceClosure quit_closure = task_environment_.QuitClosure();
|
||||
EXPECT_CALL(*mock_process_coordination_unit_,
|
||||
RequestSharedPerformanceScenarioRegions(_, _))
|
||||
.WillOnce(
|
||||
[&](uint64_t,
|
||||
ProcessCoordinationUnit::
|
||||
RequestSharedPerformanceScenarioRegionsCallback callback) {
|
||||
std::move(callback).Run(std::move(global_region),
|
||||
std::move(process_region));
|
||||
std::move(quit_closure).Run();
|
||||
});
|
||||
|
||||
// Create a RendererResourceCoordinator bound to the other end of the
|
||||
// MockProcessCoordinationUnit's remote.
|
||||
// Can't use make_unique with a private constructor.
|
||||
resource_coordinator_ = base::WrapUnique(
|
||||
new RendererResourceCoordinatorImpl(std::move(pending_remote)));
|
||||
RendererResourceCoordinator::Set(resource_coordinator_.get());
|
||||
|
||||
// Wait for the RequestSharedPerformanceScenarioRegions() call to finish.
|
||||
task_environment_.RunUntilQuit();
|
||||
}
|
||||
|
||||
test::TaskEnvironment task_environment_;
|
||||
@ -311,46 +278,4 @@ TEST_F(RendererResourceCoordinatorImplTest, NonIframeNotifications) {
|
||||
mock_process_coordination_unit_->VerifyExpectations();
|
||||
}
|
||||
|
||||
TEST_F(RendererResourceCoordinatorImplTest, NoScenarioRegion) {
|
||||
InitializeMockProcessCoordinationUnit<StrictMockProcessCoordinationUnit>(
|
||||
/*global_region=*/base::ReadOnlySharedMemoryRegion(),
|
||||
/*process_region=*/base::ReadOnlySharedMemoryRegion());
|
||||
mock_process_coordination_unit_->VerifyExpectations();
|
||||
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kGlobal));
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kCurrentProcess));
|
||||
}
|
||||
|
||||
TEST_F(RendererResourceCoordinatorImplTest, GlobalScenarioRegion) {
|
||||
auto shared_memory = base::StructuredSharedMemory<ScenarioState>::Create();
|
||||
ASSERT_TRUE(shared_memory.has_value());
|
||||
|
||||
InitializeMockProcessCoordinationUnit<StrictMockProcessCoordinationUnit>(
|
||||
/*global_region=*/shared_memory->DuplicateReadOnlyRegion(),
|
||||
/*process_region=*/base::ReadOnlySharedMemoryRegion());
|
||||
mock_process_coordination_unit_->VerifyExpectations();
|
||||
|
||||
EXPECT_TRUE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kGlobal));
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kCurrentProcess));
|
||||
}
|
||||
|
||||
TEST_F(RendererResourceCoordinatorImplTest, ProcessScenarioRegion) {
|
||||
auto shared_memory = base::StructuredSharedMemory<ScenarioState>::Create();
|
||||
ASSERT_TRUE(shared_memory.has_value());
|
||||
|
||||
InitializeMockProcessCoordinationUnit<StrictMockProcessCoordinationUnit>(
|
||||
/*global_region=*/base::ReadOnlySharedMemoryRegion(),
|
||||
/*process_region=*/shared_memory->DuplicateReadOnlyRegion());
|
||||
mock_process_coordination_unit_->VerifyExpectations();
|
||||
|
||||
EXPECT_FALSE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kGlobal));
|
||||
EXPECT_TRUE(ScopedReadOnlyScenarioMemory::GetMappingForTesting(
|
||||
ScenarioScope::kCurrentProcess));
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
Reference in New Issue
Block a user