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

[PM] Expose PerformanceManagerRegistryImpl in header file.

The goal is to allow the public PerformanceManager to access the
PerformanceManagerRegistryImpl to add observers. See
https://chromium-review.googlesource.com/c/chromium/src/+/1967434

Bug: 1030399
Change-Id: I21fab4f33d18df1bb08f359239d2a4a775fac53b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1970233Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#725599}
parent d533d715
......@@ -47,6 +47,8 @@ static_library("performance_manager") {
"performance_manager_lock_observer.cc",
"performance_manager_lock_observer.h",
"performance_manager_registry.cc",
"performance_manager_registry_impl.cc",
"performance_manager_registry_impl.h",
"performance_manager_tab_helper.cc",
"performance_manager_tab_helper.h",
"process_node_source.cc",
......
......@@ -66,4 +66,4 @@ class PerformanceManagerRegistry {
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_REGISTRY_H_
\ No newline at end of file
#endif // COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_REGISTRY_H_
......@@ -4,154 +4,10 @@
#include "components/performance_manager/embedder/performance_manager_registry.h"
#include "base/containers/flat_set.h"
#include "base/sequence_checker.h"
#include "base/stl_util.h"
#include "components/performance_manager/performance_manager_tab_helper.h"
#include "components/performance_manager/public/performance_manager.h"
#include "components/performance_manager/render_process_user_data.h"
#include "content/public/browser/render_process_host.h"
#include "components/performance_manager/performance_manager_registry_impl.h"
namespace performance_manager {
namespace {
PerformanceManagerRegistry* g_instance = nullptr;
} // namespace
// Not in anonymous namespace to allow friending.
class PerformanceManagerRegistryImpl
: public PerformanceManagerRegistry,
public PerformanceManagerTabHelper::DestructionObserver,
public RenderProcessUserData::DestructionObserver {
public:
PerformanceManagerRegistryImpl();
~PerformanceManagerRegistryImpl() override;
PerformanceManagerRegistryImpl(const PerformanceManagerRegistryImpl&) =
delete;
void operator=(const PerformanceManagerRegistryImpl&) = delete;
// PerformanceManagerRegistry:
void CreatePageNodeForWebContents(
content::WebContents* web_contents) override;
void CreateProcessNodeForRenderProcessHost(
content::RenderProcessHost* render_process_host) override;
void TearDown() override;
// PerformanceManagerTabHelper::DestructionObserver:
void OnPerformanceManagerTabHelperDestroying(
content::WebContents* web_contents) override;
// RenderProcessUserData::DestructionObserver:
void OnRenderProcessUserDataDestroying(
content::RenderProcessHost* render_process_host) override;
private:
SEQUENCE_CHECKER(sequence_checker_);
// Tracks WebContents and RenderProcessHost for which we have created user
// data. Used to destroy all user data when the registry is destroyed.
base::flat_set<content::WebContents*> web_contents_;
base::flat_set<content::RenderProcessHost*> render_process_hosts_;
};
PerformanceManagerRegistryImpl::PerformanceManagerRegistryImpl() {
DCHECK(!g_instance);
g_instance = this;
// The registry should be created after the PerformanceManager.
DCHECK(PerformanceManager::IsAvailable());
}
PerformanceManagerRegistryImpl::~PerformanceManagerRegistryImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TearDown() should have been invoked to reset |g_instance| and clear
// |web_contents_| and |render_process_user_data_| prior to destroying the
// registry.
DCHECK(!g_instance);
DCHECK(web_contents_.empty());
DCHECK(render_process_hosts_.empty());
}
void PerformanceManagerRegistryImpl::CreatePageNodeForWebContents(
content::WebContents* web_contents) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto result = web_contents_.insert(web_contents);
if (result.second) {
// Create a PerformanceManagerTabHelper if |web_contents| doesn't already
// have one. Support for multiple calls to CreatePageNodeForWebContents()
// with the same WebContents is required for Devtools -- see comment in
// header file.
PerformanceManagerTabHelper::CreateForWebContents(web_contents);
PerformanceManagerTabHelper* tab_helper =
PerformanceManagerTabHelper::FromWebContents(web_contents);
DCHECK(tab_helper);
tab_helper->SetDestructionObserver(this);
}
}
void PerformanceManagerRegistryImpl::CreateProcessNodeForRenderProcessHost(
content::RenderProcessHost* render_process_host) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto result = render_process_hosts_.insert(render_process_host);
if (result.second) {
// Create a RenderProcessUserData if |render_process_host| doesn't already
// have one.
RenderProcessUserData* user_data =
RenderProcessUserData::CreateForRenderProcessHost(render_process_host);
user_data->SetDestructionObserver(this);
}
}
void PerformanceManagerRegistryImpl::TearDown() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
// The registry should be torn down before the PerformanceManager.
DCHECK(PerformanceManager::IsAvailable());
for (auto* web_contents : web_contents_) {
PerformanceManagerTabHelper* tab_helper =
PerformanceManagerTabHelper::FromWebContents(web_contents);
DCHECK(tab_helper);
// Clear the destruction observer to avoid a nested notification.
tab_helper->SetDestructionObserver(nullptr);
// Destroy the tab helper.
tab_helper->TearDown();
web_contents->RemoveUserData(PerformanceManagerTabHelper::UserDataKey());
}
web_contents_.clear();
for (auto* render_process_host : render_process_hosts_) {
RenderProcessUserData* user_data =
RenderProcessUserData::GetForRenderProcessHost(render_process_host);
DCHECK(user_data);
// Clear the destruction observer to avoid a nested notification.
user_data->SetDestructionObserver(nullptr);
// Destroy the user data.
render_process_host->RemoveUserData(RenderProcessUserData::UserDataKey());
}
render_process_hosts_.clear();
}
void PerformanceManagerRegistryImpl::OnPerformanceManagerTabHelperDestroying(
content::WebContents* web_contents) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const size_t num_removed = web_contents_.erase(web_contents);
DCHECK_EQ(1U, num_removed);
}
void PerformanceManagerRegistryImpl::OnRenderProcessUserDataDestroying(
content::RenderProcessHost* render_process_host) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const size_t num_removed = render_process_hosts_.erase(render_process_host);
DCHECK_EQ(1U, num_removed);
}
// static
std::unique_ptr<PerformanceManagerRegistry>
PerformanceManagerRegistry::Create() {
......@@ -160,7 +16,7 @@ PerformanceManagerRegistry::Create() {
// static
PerformanceManagerRegistry* PerformanceManagerRegistry::GetInstance() {
return g_instance;
return PerformanceManagerRegistryImpl::GetInstance();
}
} // namespace performance_manager
// 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/performance_manager_registry_impl.h"
#include "base/stl_util.h"
#include "components/performance_manager/performance_manager_tab_helper.h"
#include "components/performance_manager/public/performance_manager.h"
#include "content/public/browser/render_process_host.h"
namespace performance_manager {
namespace {
PerformanceManagerRegistryImpl* g_instance = nullptr;
} // namespace
PerformanceManagerRegistryImpl::PerformanceManagerRegistryImpl() {
DCHECK(!g_instance);
g_instance = this;
// The registry should be created after the PerformanceManager.
DCHECK(PerformanceManager::IsAvailable());
}
PerformanceManagerRegistryImpl::~PerformanceManagerRegistryImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TearDown() should have been invoked to reset |g_instance| and clear
// |web_contents_| and |render_process_user_data_| prior to destroying the
// registry.
DCHECK(!g_instance);
DCHECK(web_contents_.empty());
DCHECK(render_process_hosts_.empty());
}
// static
PerformanceManagerRegistryImpl* PerformanceManagerRegistryImpl::GetInstance() {
return g_instance;
}
void PerformanceManagerRegistryImpl::CreatePageNodeForWebContents(
content::WebContents* web_contents) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto result = web_contents_.insert(web_contents);
if (result.second) {
// Create a PerformanceManagerTabHelper if |web_contents| doesn't already
// have one. Support for multiple calls to CreatePageNodeForWebContents()
// with the same WebContents is required for Devtools -- see comment in
// header file.
PerformanceManagerTabHelper::CreateForWebContents(web_contents);
PerformanceManagerTabHelper* tab_helper =
PerformanceManagerTabHelper::FromWebContents(web_contents);
DCHECK(tab_helper);
tab_helper->SetDestructionObserver(this);
}
}
void PerformanceManagerRegistryImpl::CreateProcessNodeForRenderProcessHost(
content::RenderProcessHost* render_process_host) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto result = render_process_hosts_.insert(render_process_host);
if (result.second) {
// Create a RenderProcessUserData if |render_process_host| doesn't already
// have one.
RenderProcessUserData* user_data =
RenderProcessUserData::CreateForRenderProcessHost(render_process_host);
user_data->SetDestructionObserver(this);
}
}
void PerformanceManagerRegistryImpl::TearDown() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
// The registry should be torn down before the PerformanceManager.
DCHECK(PerformanceManager::IsAvailable());
for (auto* web_contents : web_contents_) {
PerformanceManagerTabHelper* tab_helper =
PerformanceManagerTabHelper::FromWebContents(web_contents);
DCHECK(tab_helper);
// Clear the destruction observer to avoid a nested notification.
tab_helper->SetDestructionObserver(nullptr);
// Destroy the tab helper.
tab_helper->TearDown();
web_contents->RemoveUserData(PerformanceManagerTabHelper::UserDataKey());
}
web_contents_.clear();
for (auto* render_process_host : render_process_hosts_) {
RenderProcessUserData* user_data =
RenderProcessUserData::GetForRenderProcessHost(render_process_host);
DCHECK(user_data);
// Clear the destruction observer to avoid a nested notification.
user_data->SetDestructionObserver(nullptr);
// Destroy the user data.
render_process_host->RemoveUserData(RenderProcessUserData::UserDataKey());
}
render_process_hosts_.clear();
}
void PerformanceManagerRegistryImpl::OnPerformanceManagerTabHelperDestroying(
content::WebContents* web_contents) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const size_t num_removed = web_contents_.erase(web_contents);
DCHECK_EQ(1U, num_removed);
}
void PerformanceManagerRegistryImpl::OnRenderProcessUserDataDestroying(
content::RenderProcessHost* render_process_host) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const size_t num_removed = render_process_hosts_.erase(render_process_host);
DCHECK_EQ(1U, num_removed);
}
} // namespace performance_manager
// 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_PERFORMANCE_MANAGER_REGISTRY_IMPL_H_
#define COMPONENTS_PERFORMANCE_MANAGER_PERFORMANCE_MANAGER_REGISTRY_IMPL_H_
#include "base/containers/flat_set.h"
#include "base/sequence_checker.h"
#include "components/performance_manager/embedder/performance_manager_registry.h"
#include "components/performance_manager/performance_manager_tab_helper.h"
#include "components/performance_manager/render_process_user_data.h"
namespace content {
class RenderProcessHost;
class WebContents;
} // namespace content
namespace performance_manager {
class PerformanceManagerRegistryImpl
: public PerformanceManagerRegistry,
public PerformanceManagerTabHelper::DestructionObserver,
public RenderProcessUserData::DestructionObserver {
public:
PerformanceManagerRegistryImpl();
~PerformanceManagerRegistryImpl() override;
PerformanceManagerRegistryImpl(const PerformanceManagerRegistryImpl&) =
delete;
void operator=(const PerformanceManagerRegistryImpl&) = delete;
// Returns the only instance of PerformanceManagerRegistryImpl living in this
// process, or nullptr if there is none.
static PerformanceManagerRegistryImpl* GetInstance();
// PerformanceManagerRegistry:
void CreatePageNodeForWebContents(
content::WebContents* web_contents) override;
void CreateProcessNodeForRenderProcessHost(
content::RenderProcessHost* render_process_host) override;
void TearDown() override;
// PerformanceManagerTabHelper::DestructionObserver:
void OnPerformanceManagerTabHelperDestroying(
content::WebContents* web_contents) override;
// RenderProcessUserData::DestructionObserver:
void OnRenderProcessUserDataDestroying(
content::RenderProcessHost* render_process_host) override;
private:
SEQUENCE_CHECKER(sequence_checker_);
// Tracks WebContents and RenderProcessHost for which we have created user
// data. Used to destroy all user data when the registry is destroyed.
base::flat_set<content::WebContents*> web_contents_;
base::flat_set<content::RenderProcessHost*> render_process_hosts_;
};
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_PERFORMANCE_MANAGER_REGISTRY_IMPL_H_
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