Commit f76a7298 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

[PM] Move PageAlmostIdleDecorator to //components/performance_manager.

This CL moves PageAlmostIdleDecorator from
//chrome/browser/performance_manager to
//components/performance_manager. The PageAlmostIdleDecorator doesn't
depend on anything in //chrome.

Additionally, this CL adds a function to create the PerformanceManager
with default decorators. This allows the embedder to create a
PerformanceManager with default decorators without knowing about these
decorators.

Bug: 1028291
Change-Id: I7115b5a7002585043d9905a440560cd82540b659
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972612Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726374}
parent e943bf15
...@@ -1118,8 +1118,6 @@ jumbo_static_library("browser") { ...@@ -1118,8 +1118,6 @@ jumbo_static_library("browser") {
"performance_manager/decorators/helpers/page_live_state_decorator_helper.h", "performance_manager/decorators/helpers/page_live_state_decorator_helper.h",
"performance_manager/decorators/page_aggregator.cc", "performance_manager/decorators/page_aggregator.cc",
"performance_manager/decorators/page_aggregator.h", "performance_manager/decorators/page_aggregator.h",
"performance_manager/decorators/page_almost_idle_decorator.cc",
"performance_manager/decorators/page_almost_idle_decorator.h",
"performance_manager/decorators/process_metrics_decorator.cc", "performance_manager/decorators/process_metrics_decorator.cc",
"performance_manager/decorators/process_metrics_decorator.h", "performance_manager/decorators/process_metrics_decorator.h",
"performance_manager/decorators/process_priority_aggregator.cc", "performance_manager/decorators/process_priority_aggregator.cc",
......
...@@ -14,17 +14,16 @@ ...@@ -14,17 +14,16 @@
#include "chrome/browser/performance_manager/decorators/frozen_frame_aggregator.h" #include "chrome/browser/performance_manager/decorators/frozen_frame_aggregator.h"
#include "chrome/browser/performance_manager/decorators/helpers/page_live_state_decorator_helper.h" #include "chrome/browser/performance_manager/decorators/helpers/page_live_state_decorator_helper.h"
#include "chrome/browser/performance_manager/decorators/page_aggregator.h" #include "chrome/browser/performance_manager/decorators/page_aggregator.h"
#include "chrome/browser/performance_manager/decorators/page_almost_idle_decorator.h"
#include "chrome/browser/performance_manager/decorators/process_metrics_decorator.h" #include "chrome/browser/performance_manager/decorators/process_metrics_decorator.h"
#include "chrome/browser/performance_manager/graph/policies/policy_features.h" #include "chrome/browser/performance_manager/graph/policies/policy_features.h"
#include "chrome/browser/performance_manager/graph/policies/working_set_trimmer_policy.h" #include "chrome/browser/performance_manager/graph/policies/working_set_trimmer_policy.h"
#include "chrome/browser/performance_manager/observers/isolation_context_metrics.h" #include "chrome/browser/performance_manager/observers/isolation_context_metrics.h"
#include "chrome/browser/performance_manager/observers/metrics_collector.h" #include "chrome/browser/performance_manager/observers/metrics_collector.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "components/performance_manager/embedder/performance_manager_lifetime.h"
#include "components/performance_manager/embedder/performance_manager_registry.h" #include "components/performance_manager/embedder/performance_manager_registry.h"
#include "components/performance_manager/graph/graph_impl.h"
#include "components/performance_manager/performance_manager_impl.h"
#include "components/performance_manager/performance_manager_lock_observer.h" #include "components/performance_manager/performance_manager_lock_observer.h"
#include "components/performance_manager/public/graph/graph.h"
#include "components/performance_manager/shared_worker_watcher.h" #include "components/performance_manager/shared_worker_watcher.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
...@@ -62,13 +61,11 @@ ChromeBrowserMainExtraPartsPerformanceManager::GetInstance() { ...@@ -62,13 +61,11 @@ ChromeBrowserMainExtraPartsPerformanceManager::GetInstance() {
} }
// static // static
void ChromeBrowserMainExtraPartsPerformanceManager:: void ChromeBrowserMainExtraPartsPerformanceManager::CreatePoliciesAndDecorators(
CreateDefaultPoliciesAndDecorators(performance_manager::GraphImpl* graph) { performance_manager::Graph* graph) {
graph->PassToGraph(std::make_unique<performance_manager::PageAggregator>()); graph->PassToGraph(std::make_unique<performance_manager::PageAggregator>());
graph->PassToGraph( graph->PassToGraph(
std::make_unique<performance_manager::FrozenFrameAggregator>()); std::make_unique<performance_manager::FrozenFrameAggregator>());
graph->PassToGraph(
std::make_unique<performance_manager::PageAlmostIdleDecorator>());
graph->PassToGraph( graph->PassToGraph(
std::make_unique<performance_manager::IsolationContextMetrics>()); std::make_unique<performance_manager::IsolationContextMetrics>());
graph->PassToGraph(std::make_unique<performance_manager::MetricsCollector>()); graph->PassToGraph(std::make_unique<performance_manager::MetricsCollector>());
...@@ -98,9 +95,10 @@ ChromeBrowserMainExtraPartsPerformanceManager::GetLockObserver() { ...@@ -98,9 +95,10 @@ ChromeBrowserMainExtraPartsPerformanceManager::GetLockObserver() {
} }
void ChromeBrowserMainExtraPartsPerformanceManager::PostCreateThreads() { void ChromeBrowserMainExtraPartsPerformanceManager::PostCreateThreads() {
performance_manager_ = performance_manager::PerformanceManagerImpl::Create( performance_manager_ =
base::BindOnce(&ChromeBrowserMainExtraPartsPerformanceManager:: performance_manager::CreatePerformanceManagerWithDefaultDecorators(
CreateDefaultPoliciesAndDecorators)); base::BindOnce(&ChromeBrowserMainExtraPartsPerformanceManager::
CreatePoliciesAndDecorators));
registry_ = performance_manager::PerformanceManagerRegistry::Create(); registry_ = performance_manager::PerformanceManagerRegistry::Create();
browser_child_process_watcher_ = browser_child_process_watcher_ =
std::make_unique<performance_manager::BrowserChildProcessWatcher>(); std::make_unique<performance_manager::BrowserChildProcessWatcher>();
...@@ -139,7 +137,7 @@ void ChromeBrowserMainExtraPartsPerformanceManager::PostMainMessageLoopRun() { ...@@ -139,7 +137,7 @@ void ChromeBrowserMainExtraPartsPerformanceManager::PostMainMessageLoopRun() {
registry_->TearDown(); registry_->TearDown();
registry_.reset(); registry_.reset();
performance_manager::PerformanceManagerImpl::Destroy( performance_manager::DestroyPerformanceManager(
std::move(performance_manager_)); std::move(performance_manager_));
} }
......
...@@ -26,9 +26,9 @@ class LockObserver; ...@@ -26,9 +26,9 @@ class LockObserver;
namespace performance_manager { namespace performance_manager {
class BrowserChildProcessWatcher; class BrowserChildProcessWatcher;
class GraphImpl; class Graph;
class PageLiveStateDecoratorHelper; class PageLiveStateDecoratorHelper;
class PerformanceManagerImpl; class PerformanceManager;
class PerformanceManagerRegistry; class PerformanceManagerRegistry;
class SharedWorkerWatcher; class SharedWorkerWatcher;
} // namespace performance_manager } // namespace performance_manager
...@@ -46,9 +46,6 @@ class ChromeBrowserMainExtraPartsPerformanceManager ...@@ -46,9 +46,6 @@ class ChromeBrowserMainExtraPartsPerformanceManager
// Returns the only instance of this class. // Returns the only instance of this class.
static ChromeBrowserMainExtraPartsPerformanceManager* GetInstance(); static ChromeBrowserMainExtraPartsPerformanceManager* GetInstance();
static void CreateDefaultPoliciesAndDecorators(
performance_manager::GraphImpl* graph);
// Returns the LockObserver that should be exposed to //content to allow the // Returns the LockObserver that should be exposed to //content to allow the
// performance manager to track usage of locks in frames. Valid to call from // performance manager to track usage of locks in frames. Valid to call from
// any thread, but external synchronization is needed to make sure that the // any thread, but external synchronization is needed to make sure that the
...@@ -56,6 +53,8 @@ class ChromeBrowserMainExtraPartsPerformanceManager ...@@ -56,6 +53,8 @@ class ChromeBrowserMainExtraPartsPerformanceManager
content::LockObserver* GetLockObserver(); content::LockObserver* GetLockObserver();
private: private:
static void CreatePoliciesAndDecorators(performance_manager::Graph* graph);
// ChromeBrowserMainExtraParts overrides. // ChromeBrowserMainExtraParts overrides.
void PostCreateThreads() override; void PostCreateThreads() override;
void PostMainMessageLoopRun() override; void PostMainMessageLoopRun() override;
...@@ -67,8 +66,7 @@ class ChromeBrowserMainExtraPartsPerformanceManager ...@@ -67,8 +66,7 @@ class ChromeBrowserMainExtraPartsPerformanceManager
void OnOffTheRecordProfileCreated(Profile* off_the_record) override; void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileWillBeDestroyed(Profile* profile) override; void OnProfileWillBeDestroyed(Profile* profile) override;
std::unique_ptr<performance_manager::PerformanceManagerImpl> std::unique_ptr<performance_manager::PerformanceManager> performance_manager_;
performance_manager_;
std::unique_ptr<performance_manager::PerformanceManagerRegistry> registry_; std::unique_ptr<performance_manager::PerformanceManagerRegistry> registry_;
// This must be alive at least until the end of base::ThreadPool shutdown, // This must be alive at least until the end of base::ThreadPool shutdown,
......
...@@ -3222,7 +3222,6 @@ test("unit_tests") { ...@@ -3222,7 +3222,6 @@ test("unit_tests") {
"../browser/performance_manager/decorators/frozen_frame_aggregator_unittest.cc", "../browser/performance_manager/decorators/frozen_frame_aggregator_unittest.cc",
"../browser/performance_manager/decorators/helpers/page_live_state_decorator_helper_unittest.cc", "../browser/performance_manager/decorators/helpers/page_live_state_decorator_helper_unittest.cc",
"../browser/performance_manager/decorators/page_aggregator_unittest.cc", "../browser/performance_manager/decorators/page_aggregator_unittest.cc",
"../browser/performance_manager/decorators/page_almost_idle_decorator_unittest.cc",
"../browser/performance_manager/decorators/process_metrics_decorator_unittest.cc", "../browser/performance_manager/decorators/process_metrics_decorator_unittest.cc",
"../browser/performance_manager/decorators/process_priority_aggregator_unittest.cc", "../browser/performance_manager/decorators/process_priority_aggregator_unittest.cc",
"../browser/performance_manager/graph/policies/dynamic_tcmalloc_policy_linux_unittest.cc", "../browser/performance_manager/graph/policies/dynamic_tcmalloc_policy_linux_unittest.cc",
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
static_library("performance_manager") { static_library("performance_manager") {
sources = [ sources = [
"decorators/page_almost_idle_decorator.cc",
"decorators/page_almost_idle_decorator.h",
"decorators/page_live_state_decorator.cc", "decorators/page_live_state_decorator.cc",
"embedder/performance_manager_lifetime.h",
"embedder/performance_manager_registry.h", "embedder/performance_manager_registry.h",
"frame_priority/boosting_vote_aggregator.cc", "frame_priority/boosting_vote_aggregator.cc",
"frame_priority/frame_priority.cc", "frame_priority/frame_priority.cc",
...@@ -44,6 +47,7 @@ static_library("performance_manager") { ...@@ -44,6 +47,7 @@ static_library("performance_manager") {
"performance_manager.cc", "performance_manager.cc",
"performance_manager_impl.cc", "performance_manager_impl.cc",
"performance_manager_impl.h", "performance_manager_impl.h",
"performance_manager_lifetime.cc",
"performance_manager_lock_observer.cc", "performance_manager_lock_observer.cc",
"performance_manager_lock_observer.h", "performance_manager_lock_observer.h",
"performance_manager_registry.cc", "performance_manager_registry.cc",
...@@ -96,6 +100,7 @@ source_set("unit_tests") { ...@@ -96,6 +100,7 @@ source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"decorators/page_almost_idle_decorator_unittest.cc",
"decorators/page_live_state_decorator_unittest.cc", "decorators/page_live_state_decorator_unittest.cc",
"frame_priority/boosting_vote_aggregator_unittest.cc", "frame_priority/boosting_vote_aggregator_unittest.cc",
"frame_priority/frame_priority_unittest.cc", "frame_priority/frame_priority_unittest.cc",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/performance_manager/decorators/page_almost_idle_decorator.h" #include "components/performance_manager/decorators/page_almost_idle_decorator.h"
#include <algorithm> #include <algorithm>
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_PERFORMANCE_MANAGER_DECORATORS_PAGE_ALMOST_IDLE_DECORATOR_H_ #ifndef COMPONENTS_PERFORMANCE_MANAGER_DECORATORS_PAGE_ALMOST_IDLE_DECORATOR_H_
#define CHROME_BROWSER_PERFORMANCE_MANAGER_DECORATORS_PAGE_ALMOST_IDLE_DECORATOR_H_ #define COMPONENTS_PERFORMANCE_MANAGER_DECORATORS_PAGE_ALMOST_IDLE_DECORATOR_H_
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
...@@ -138,4 +138,4 @@ class PageAlmostIdleDecorator::Data { ...@@ -138,4 +138,4 @@ class PageAlmostIdleDecorator::Data {
} // namespace performance_manager } // namespace performance_manager
#endif // CHROME_BROWSER_PERFORMANCE_MANAGER_DECORATORS_PAGE_ALMOST_IDLE_DECORATOR_H_ #endif // COMPONENTS_BROWSER_PERFORMANCE_MANAGER_DECORATORS_PAGE_ALMOST_IDLE_DECORATOR_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/performance_manager/decorators/page_almost_idle_decorator.h" #include "components/performance_manager/decorators/page_almost_idle_decorator.h"
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
......
// Copyright 2019 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 COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_LIFETIME_H_
#define COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_LIFETIME_H_
#include <memory>
#include "base/callback_forward.h"
#include "components/performance_manager/public/performance_manager.h"
namespace performance_manager {
class Graph;
using GraphCreatedCallback = base::OnceCallback<void(Graph*)>;
// Creates a PerformanceManager with default decorators.
// |graph_created_callback| is invoked on the PM sequence once the Graph is
// created.
std::unique_ptr<PerformanceManager>
CreatePerformanceManagerWithDefaultDecorators(
GraphCreatedCallback graph_created_callback);
// Unregisters |instance| and arranges for its deletion on its sequence.
void DestroyPerformanceManager(std::unique_ptr<PerformanceManager> instance);
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_LIFETIME_H_
...@@ -91,7 +91,7 @@ std::unique_ptr<PerformanceManagerImpl> PerformanceManagerImpl::Create( ...@@ -91,7 +91,7 @@ std::unique_ptr<PerformanceManagerImpl> PerformanceManagerImpl::Create(
// static // static
void PerformanceManagerImpl::Destroy( void PerformanceManagerImpl::Destroy(
std::unique_ptr<PerformanceManagerImpl> instance) { std::unique_ptr<PerformanceManager> instance) {
DCHECK_EQ(instance.get(), g_performance_manager_from_any_sequence); DCHECK_EQ(instance.get(), g_performance_manager_from_any_sequence);
g_performance_manager_from_any_sequence = nullptr; g_performance_manager_from_any_sequence = nullptr;
GetTaskRunner()->DeleteSoon(FROM_HERE, instance.release()); GetTaskRunner()->DeleteSoon(FROM_HERE, instance.release());
......
...@@ -66,9 +66,8 @@ class PerformanceManagerImpl : public PerformanceManager { ...@@ -66,9 +66,8 @@ class PerformanceManagerImpl : public PerformanceManager {
static std::unique_ptr<PerformanceManagerImpl> Create( static std::unique_ptr<PerformanceManagerImpl> Create(
GraphImplCallback on_start); GraphImplCallback on_start);
// Unregisters |instance| if it's currently registered and arranges for its // Unregisters |instance| and arranges for its deletion on its sequence.
// deletion on its sequence. static void Destroy(std::unique_ptr<PerformanceManager> instance);
static void Destroy(std::unique_ptr<PerformanceManagerImpl> instance);
// Creates a new node of the requested type and adds it to the graph. // Creates a new node of the requested type and adds it to the graph.
// May be called from any sequence. If a |creation_callback| is provided it // May be called from any sequence. If a |creation_callback| is provided it
......
// Copyright 2019 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 "components/performance_manager/embedder/performance_manager_lifetime.h"
#include "base/bind.h"
#include "components/performance_manager/decorators/page_almost_idle_decorator.h"
#include "components/performance_manager/performance_manager_impl.h"
#include "components/performance_manager/public/graph/graph.h"
namespace performance_manager {
namespace {
void DefaultGraphCreatedCallback(
GraphCreatedCallback external_graph_created_callback,
GraphImpl* graph) {
graph->PassToGraph(std::make_unique<PageAlmostIdleDecorator>());
std::move(external_graph_created_callback).Run(graph);
}
} // namespace
std::unique_ptr<PerformanceManager>
CreatePerformanceManagerWithDefaultDecorators(
GraphCreatedCallback graph_created_callback) {
return PerformanceManagerImpl::Create(base::BindOnce(
&DefaultGraphCreatedCallback, std::move(graph_created_callback)));
}
void DestroyPerformanceManager(std::unique_ptr<PerformanceManager> instance) {
PerformanceManagerImpl::Destroy(std::move(instance));
}
} // namespace performance_manager
...@@ -24,6 +24,8 @@ class PerformanceManagerMainThreadObserver; ...@@ -24,6 +24,8 @@ class PerformanceManagerMainThreadObserver;
// performance manager graph on its dedicated sequence. // performance manager graph on its dedicated sequence.
class PerformanceManager { class PerformanceManager {
public: public:
virtual ~PerformanceManager();
// Returns true if the performance manager is initialized. Valid to call from // Returns true if the performance manager is initialized. Valid to call from
// the main thread only. // the main thread only.
static bool IsAvailable(); static bool IsAvailable();
...@@ -55,7 +57,6 @@ class PerformanceManager { ...@@ -55,7 +57,6 @@ class PerformanceManager {
protected: protected:
PerformanceManager(); PerformanceManager();
virtual ~PerformanceManager();
private: private:
DISALLOW_COPY_AND_ASSIGN(PerformanceManager); DISALLOW_COPY_AND_ASSIGN(PerformanceManager);
......
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