Commit 96b8fdb0 authored by Chris Hamilton's avatar Chris Hamilton Committed by Commit Bot

Move RendererResourceCoordinator to controller/

This moves the implementation of RendererResourceCoordinator to
controller, leaving behind only the interface definition and singleton
accessor in platform.

Change-Id: Ibdf23280e53b48df897ec341d27fe366efb04f5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354534
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797865}
parent 290feaaa
...@@ -15,6 +15,7 @@ component("controller") { ...@@ -15,6 +15,7 @@ component("controller") {
output_name = "blink_controller" output_name = "blink_controller"
deps = [ deps = [
"//components/performance_manager/public/mojom:mojom_blink",
"//skia", "//skia",
"//third_party/blink/renderer/core", "//third_party/blink/renderer/core",
"//third_party/blink/renderer/modules", "//third_party/blink/renderer/modules",
...@@ -42,6 +43,8 @@ component("controller") { ...@@ -42,6 +43,8 @@ component("controller") {
"dev_tools_frontend_impl.h", "dev_tools_frontend_impl.h",
"memory_usage_monitor.cc", "memory_usage_monitor.cc",
"memory_usage_monitor.h", "memory_usage_monitor.h",
"performance_manager/renderer_resource_coordinator_impl.cc",
"performance_manager/renderer_resource_coordinator_impl.h",
] ]
if (is_linux || is_chromeos) { if (is_linux || is_chromeos) {
......
include_rules = [ include_rules = [
"+base", "+base",
"+components/performance_manager/public",
"+mojo/public", "+mojo/public",
"+third_party/blink/public/web", "+third_party/blink/public/web",
"+third_party/blink/renderer/bindings", "+third_party/blink/renderer/bindings",
"+third_party/blink/renderer/controller", "+third_party/blink/renderer/controller",
"+third_party/blink/renderer/core", "+third_party/blink/renderer/core",
"+third_party/blink/renderer/modules", "+third_party/blink/renderer/modules",
"+third_party/blink/renderer/platform",
"+web", "+web",
] ]
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_initializer.h" #include "third_party/blink/renderer/bindings/core/v8/v8_initializer.h"
#include "third_party/blink/renderer/controller/blink_leak_detector.h" #include "third_party/blink/renderer/controller/blink_leak_detector.h"
#include "third_party/blink/renderer/controller/dev_tools_frontend_impl.h" #include "third_party/blink/renderer/controller/dev_tools_frontend_impl.h"
#include "third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl.h"
#include "third_party/blink/renderer/core/animation/animation_clock.h" #include "third_party/blink/renderer/core/animation/animation_clock.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/agent.h" #include "third_party/blink/renderer/core/execution_context/agent.h"
...@@ -163,6 +164,9 @@ void InitializeCommon(Platform* platform, mojo::BinderMap* binders) { ...@@ -163,6 +164,9 @@ void InitializeCommon(Platform* platform, mojo::BinderMap* binders) {
// navigation. // navigation.
HighestPmfReporter::Instance(); HighestPmfReporter::Instance();
#endif #endif
// Initialize performance manager.
RendererResourceCoordinatorImpl::MaybeInitialize();
} }
} // namespace } // namespace
......
// Copyright 2020 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.
#include "third_party/blink/renderer/controller/performance_manager/renderer_resource_coordinator_impl.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
RendererResourceCoordinatorImpl::~RendererResourceCoordinatorImpl() = default;
// static
void RendererResourceCoordinatorImpl::MaybeInitialize() {
if (!RuntimeEnabledFeatures::PerformanceManagerInstrumentationEnabled())
return;
blink::Platform* platform = Platform::Current();
DCHECK(IsMainThread());
DCHECK(platform);
mojo::PendingRemote<
performance_manager::mojom::blink::ProcessCoordinationUnit>
remote;
platform->GetBrowserInterfaceBroker()->GetInterface(
remote.InitWithNewPipeAndPassReceiver());
RendererResourceCoordinator::Set(
new RendererResourceCoordinatorImpl(std::move(remote)));
}
void RendererResourceCoordinatorImpl::SetMainThreadTaskLoadIsLow(
bool main_thread_task_load_is_low) {
if (!service_)
return;
service_->SetMainThreadTaskLoadIsLow(main_thread_task_load_is_low);
}
void RendererResourceCoordinatorImpl::OnScriptStateCreated(
ScriptState* script_state,
ExecutionContext* execution_context) {
// TODO(chrisha): Extract tokens and forward this to the browser!
}
void RendererResourceCoordinatorImpl::OnScriptStateDetached(
ScriptState* script_state) {
// TODO(chrisha): Extract tokens and forward this to the browser!
}
void RendererResourceCoordinatorImpl::OnScriptStateDestroyed(
ScriptState* script_state) {
// TODO(chrisha): Extract tokens and forward this to the browser!
}
RendererResourceCoordinatorImpl::RendererResourceCoordinatorImpl(
mojo::PendingRemote<
performance_manager::mojom::blink::ProcessCoordinationUnit> remote) {
service_.Bind(std::move(remote));
}
} // namespace blink
// Copyright 2020 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 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 "components/performance_manager/public/mojom/coordination_unit.mojom-blink.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/renderer/controller/controller_export.h"
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/renderer_resource_coordinator.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink {
class CONTROLLER_EXPORT RendererResourceCoordinatorImpl final
: public RendererResourceCoordinator {
USING_FAST_MALLOC(RendererResourceCoordinatorImpl);
public:
RendererResourceCoordinatorImpl(const RendererResourceCoordinatorImpl&) =
delete;
RendererResourceCoordinatorImpl& operator=(
const RendererResourceCoordinatorImpl&) = delete;
~RendererResourceCoordinatorImpl() final;
// Only initializes if the instrumentation runtime feature is enabled.
static void MaybeInitialize();
// RendererResourceCoordinator:
void SetMainThreadTaskLoadIsLow(bool) final;
void OnScriptStateCreated(ScriptState* script_state,
ExecutionContext* execution_context) final;
void OnScriptStateDetached(ScriptState* script_state) final;
void OnScriptStateDestroyed(ScriptState* script_state) final;
private:
explicit RendererResourceCoordinatorImpl(
mojo::PendingRemote<
performance_manager::mojom::blink::ProcessCoordinationUnit> remote);
mojo::Remote<performance_manager::mojom::blink::ProcessCoordinationUnit>
service_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
#include "third_party/blink/renderer/platform/instrumentation/instance_counters_memory_dump_provider.h" #include "third_party/blink/renderer/platform/instrumentation/instance_counters_memory_dump_provider.h"
#include "third_party/blink/renderer/platform/instrumentation/memory_pressure_listener.h" #include "third_party/blink/renderer/platform/instrumentation/memory_pressure_listener.h"
#include "third_party/blink/renderer/platform/instrumentation/partition_alloc_memory_dump_provider.h" #include "third_party/blink/renderer/platform/instrumentation/partition_alloc_memory_dump_provider.h"
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/renderer_resource_coordinator.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/memory_cache_dump_provider.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/memory_cache_dump_provider.h"
#include "third_party/blink/renderer/platform/language.h" #include "third_party/blink/renderer/platform/language.h"
#include "third_party/blink/renderer/platform/scheduler/common/simple_thread_scheduler.h" #include "third_party/blink/renderer/platform/scheduler/common/simple_thread_scheduler.h"
...@@ -240,7 +239,6 @@ void Platform::InitializeMainThreadCommon(Platform* platform, ...@@ -240,7 +239,6 @@ void Platform::InitializeMainThreadCommon(Platform* platform,
CanvasMemoryDumpProvider::Instance(), "Canvas", CanvasMemoryDumpProvider::Instance(), "Canvas",
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
RendererResourceCoordinator::MaybeInitialize();
// Use a delayed idle task as this is low priority work that should stop when // Use a delayed idle task as this is low priority work that should stop when
// the main thread is not doing any work. // the main thread is not doing any work.
WTF::Partitions::StartPeriodicReclaim( WTF::Partitions::StartPeriodicReclaim(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h" #include "third_party/blink/renderer/platform/heap/thread_state.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink { namespace blink {
...@@ -15,69 +16,38 @@ namespace { ...@@ -15,69 +16,38 @@ namespace {
RendererResourceCoordinator* g_renderer_resource_coordinator = nullptr; RendererResourceCoordinator* g_renderer_resource_coordinator = nullptr;
} // namespace class DummyRendererResourceCoordinator final
: public RendererResourceCoordinator {
// static public:
void RendererResourceCoordinator::MaybeInitialize() { DummyRendererResourceCoordinator() = default;
if (!RuntimeEnabledFeatures::PerformanceManagerInstrumentationEnabled()) ~DummyRendererResourceCoordinator() final = default;
return;
static DummyRendererResourceCoordinator* Get() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(DummyRendererResourceCoordinator, instance,
());
return &instance;
}
// RendererResourceCoordinator:
void SetMainThreadTaskLoadIsLow(bool) final {}
void OnScriptStateCreated(ScriptState* script_state,
ExecutionContext* execution_context) final {}
void OnScriptStateDetached(ScriptState* script_state) final {}
void OnScriptStateDestroyed(ScriptState* script_state) final {}
};
blink::Platform* platform = Platform::Current(); } // namespace
DCHECK(IsMainThread());
DCHECK(platform);
mojo::PendingRemote<
performance_manager::mojom::blink::ProcessCoordinationUnit>
remote;
platform->GetBrowserInterfaceBroker()->GetInterface(
remote.InitWithNewPipeAndPassReceiver());
g_renderer_resource_coordinator =
new RendererResourceCoordinator(std::move(remote));
}
// static // static
void RendererResourceCoordinator:: void RendererResourceCoordinator::Set(RendererResourceCoordinator* instance) {
SetCurrentRendererResourceCoordinatorForTesting( g_renderer_resource_coordinator = instance;
RendererResourceCoordinator* renderer_resource_coordinator) {
g_renderer_resource_coordinator = renderer_resource_coordinator;
} }
// static // static
RendererResourceCoordinator* RendererResourceCoordinator::Get() { RendererResourceCoordinator* RendererResourceCoordinator::Get() {
return g_renderer_resource_coordinator; if (g_renderer_resource_coordinator)
} return g_renderer_resource_coordinator;
return DummyRendererResourceCoordinator::Get();
RendererResourceCoordinator::RendererResourceCoordinator(
mojo::PendingRemote<
performance_manager::mojom::blink::ProcessCoordinationUnit> remote) {
service_.Bind(std::move(remote));
}
RendererResourceCoordinator::RendererResourceCoordinator() = default;
RendererResourceCoordinator::~RendererResourceCoordinator() = default;
void RendererResourceCoordinator::SetMainThreadTaskLoadIsLow(
bool main_thread_task_load_is_low) {
if (!service_)
return;
service_->SetMainThreadTaskLoadIsLow(main_thread_task_load_is_low);
}
void RendererResourceCoordinator::OnScriptStateCreated(
ScriptState* script_state,
ExecutionContext* execution_context) {
// TODO(chrisha): Extract tokens and forward this to the browser!
}
void RendererResourceCoordinator::OnScriptStateDetached(
ScriptState* script_state) {
// TODO(chrisha): Extract tokens and forward this to the browser!
}
void RendererResourceCoordinator::OnScriptStateDestroyed(
ScriptState* script_state) {
// TODO(chrisha): Extract tokens and forward this to the browser!
} }
} // namespace blink } // namespace blink
...@@ -5,32 +5,33 @@ ...@@ -5,32 +5,33 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_
#include "base/macros.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom-blink.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink { namespace blink {
// TODO(chrisha): Remove knowledge of ExecutionContext class from this code!
class ExecutionContext; class ExecutionContext;
class ScriptState; class ScriptState;
class PLATFORM_EXPORT RendererResourceCoordinator { class PLATFORM_EXPORT RendererResourceCoordinator {
USING_FAST_MALLOC(RendererResourceCoordinator);
public: public:
// Only initializes if the instrumentation runtime feature is enabled. static void Set(RendererResourceCoordinator* instance);
static void MaybeInitialize();
static RendererResourceCoordinator* Get();
// Used to switch the current renderer resource coordinator only for testing. // This will always return a valid object. However, unless an explicit
static void SetCurrentRendererResourceCoordinatorForTesting( // implementation has been provided via Set, it will be a dummy
RendererResourceCoordinator*); // implementation.
static RendererResourceCoordinator* Get();
~RendererResourceCoordinator(); RendererResourceCoordinator() = default;
RendererResourceCoordinator(const RendererResourceCoordinator&) = delete;
RendererResourceCoordinator& operator=(const RendererResourceCoordinator&) =
delete;
virtual ~RendererResourceCoordinator() = default;
void SetMainThreadTaskLoadIsLow(bool); // Notifies the browser that the main thread task load is low.
// TODO(chrisha): Move this to a per-agent interface, and drive this off of
// a signal from each agent scheduler when those exist.
virtual void SetMainThreadTaskLoadIsLow(bool) = 0;
// Used for tracking content javascript contexts (frames, workers, worklets, // Used for tracking content javascript contexts (frames, workers, worklets,
// etc). These functions are thread-safe. // etc). These functions are thread-safe.
...@@ -38,28 +39,15 @@ class PLATFORM_EXPORT RendererResourceCoordinator { ...@@ -38,28 +39,15 @@ class PLATFORM_EXPORT RendererResourceCoordinator {
// Called when a |script_state| is created. Note that |execution_context| may // Called when a |script_state| is created. Note that |execution_context| may
// be nullptr if the |script_state| is not associated with an // be nullptr if the |script_state| is not associated with an
// |execution_context|. // |execution_context|.
void OnScriptStateCreated(ScriptState* script_state, virtual void OnScriptStateCreated(ScriptState* script_state,
ExecutionContext* execution_context); ExecutionContext* execution_context) = 0;
// Called when the |script_state| has been detached from the v8::Context // Called when the |script_state| has been detached from the v8::Context
// (and ExecutionContext, if applicable) it was associated with at creation. // (and ExecutionContext, if applicable) it was associated with at creation.
// At this point the associated v8::Context is considered "detached" until it // At this point the associated v8::Context is considered "detached" until it
// is garbage collected. // is garbage collected.
void OnScriptStateDetached(ScriptState* script_state); virtual void OnScriptStateDetached(ScriptState* script_state) = 0;
// Called when the |script_state| itself is garbage collected. // Called when the |script_state| itself is garbage collected.
void OnScriptStateDestroyed(ScriptState* script_state); virtual void OnScriptStateDestroyed(ScriptState* script_state) = 0;
protected:
RendererResourceCoordinator();
private:
explicit RendererResourceCoordinator(
mojo::PendingRemote<
performance_manager::mojom::blink::ProcessCoordinationUnit> remote);
mojo::Remote<performance_manager::mojom::blink::ProcessCoordinationUnit>
service_;
DISALLOW_COPY_AND_ASSIGN(RendererResourceCoordinator);
}; };
} // namespace blink } // namespace blink
......
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#include "third_party/blink/public/platform/web_runtime_features.h" #include "third_party/blink/public/platform/web_runtime_features.h"
#include "third_party/blink/renderer/platform/font_family_names.h" #include "third_party/blink/renderer/platform/font_family_names.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/renderer_resource_coordinator.h"
#include "third_party/blink/renderer/platform/language.h" #include "third_party/blink/renderer/platform/language.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/network/http_names.h" #include "third_party/blink/renderer/platform/network/http_names.h"
...@@ -137,9 +136,6 @@ void TestingPlatformSupport::SetThreadedAnimationEnabled(bool enabled) { ...@@ -137,9 +136,6 @@ void TestingPlatformSupport::SetThreadedAnimationEnabled(bool enabled) {
is_threaded_animation_enabled_ = enabled; is_threaded_animation_enabled_ = enabled;
} }
class ScopedUnittestsEnvironmentSetup::DummyRendererResourceCoordinator final
: public blink::RendererResourceCoordinator {};
ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup(int argc, ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup(int argc,
char** argv) { char** argv) {
base::CommandLine::Init(argc, argv); base::CommandLine::Init(argc, argv);
...@@ -170,11 +166,6 @@ ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup(int argc, ...@@ -170,11 +166,6 @@ ScopedUnittestsEnvironmentSetup::ScopedUnittestsEnvironmentSetup(int argc,
testing_platform_support_ = std::make_unique<TestingPlatformSupport>(); testing_platform_support_ = std::make_unique<TestingPlatformSupport>();
Platform::SetCurrentPlatformForTesting(testing_platform_support_.get()); Platform::SetCurrentPlatformForTesting(testing_platform_support_.get());
dummy_renderer_resource_coordinator_ =
std::make_unique<DummyRendererResourceCoordinator>();
RendererResourceCoordinator::SetCurrentRendererResourceCoordinatorForTesting(
dummy_renderer_resource_coordinator_.get());
ProcessHeap::Init(); ProcessHeap::Init();
ThreadState::AttachMainThread(); ThreadState::AttachMainThread();
blink::ThreadState::Current()->DetachFromIsolate(); blink::ThreadState::Current()->DetachFromIsolate();
......
...@@ -161,12 +161,9 @@ class ScopedUnittestsEnvironmentSetup final { ...@@ -161,12 +161,9 @@ class ScopedUnittestsEnvironmentSetup final {
~ScopedUnittestsEnvironmentSetup(); ~ScopedUnittestsEnvironmentSetup();
private: private:
class DummyRendererResourceCoordinator;
std::unique_ptr<base::TestDiscardableMemoryAllocator> std::unique_ptr<base::TestDiscardableMemoryAllocator>
discardable_memory_allocator_; discardable_memory_allocator_;
std::unique_ptr<Platform> dummy_platform_; std::unique_ptr<Platform> dummy_platform_;
std::unique_ptr<DummyRendererResourceCoordinator>
dummy_renderer_resource_coordinator_;
std::unique_ptr<TestingPlatformSupport> testing_platform_support_; std::unique_ptr<TestingPlatformSupport> testing_platform_support_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment