Commit 6320d946 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

[PM] Add the unique ID of the browser context to page nodes

Bug: 993029
Change-Id: I5d284c84ac16b1ac6ba708481d283402a88140cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764401Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690069}
parent 1caec412
......@@ -106,10 +106,11 @@ struct TestNodeWrapper<PageNodeImpl>::Factory {
static std::unique_ptr<PageNodeImpl> Create(
GraphImpl* graph,
const WebContentsProxy& wc_proxy = WebContentsProxy(),
const std::string& browser_context_id = std::string(),
bool is_visible = false,
bool is_audible = false) {
return std::make_unique<PageNodeImpl>(graph, wc_proxy, is_visible,
is_audible);
return std::make_unique<PageNodeImpl>(graph, wc_proxy, browser_context_id,
is_visible, is_audible);
}
};
......
......@@ -33,11 +33,13 @@ size_t ToIndex(
PageNodeImpl::PageNodeImpl(GraphImpl* graph,
const WebContentsProxy& contents_proxy,
const std::string& browser_context_id,
bool is_visible,
bool is_audible)
: TypedNodeBase(graph),
contents_proxy_(contents_proxy),
visibility_change_time_(PerformanceManagerClock::NowTicks()),
browser_context_id_(browser_context_id),
is_visible_(is_visible),
is_audible_(is_audible) {
DETACH_FROM_SEQUENCE(sequence_checker_);
......@@ -214,6 +216,11 @@ uint64_t PageNodeImpl::private_footprint_kb_estimate() const {
return private_footprint_kb_estimate_;
}
const std::string& PageNodeImpl::browser_context_id() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return browser_context_id_;
}
bool PageNodeImpl::page_almost_idle() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return page_almost_idle_.value();
......@@ -316,6 +323,11 @@ void PageNodeImpl::LeaveGraph() {
NodeBase::LeaveGraph();
}
const std::string& PageNodeImpl::GetBrowserContextID() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return browser_context_id();
}
bool PageNodeImpl::IsPageAlmostIdle() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return page_almost_idle();
......
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_PERFORMANCE_MANAGER_GRAPH_PAGE_NODE_IMPL_H_
#include <memory>
#include <string>
#include <vector>
#include "base/containers/flat_set.h"
......@@ -30,6 +31,7 @@ class PageNodeImpl : public PublicNodeImpl<PageNodeImpl, PageNode>,
PageNodeImpl(GraphImpl* graph,
const WebContentsProxy& contents_proxy,
const std::string& browser_context_id,
bool is_visible,
bool is_audible);
~PageNodeImpl() override;
......@@ -71,6 +73,7 @@ class PageNodeImpl : public PublicNodeImpl<PageNodeImpl, PageNode>,
FrameNodeImpl* GetMainFrameNodeImpl() const;
// Accessors.
const std::string& browser_context_id() const;
bool is_visible() const;
bool is_audible() const;
bool is_loading() const;
......@@ -133,6 +136,7 @@ class PageNodeImpl : public PublicNodeImpl<PageNodeImpl, PageNode>,
friend class PageAlmostIdleAccess;
// PageNode implementation:
const std::string& GetBrowserContextID() const override;
bool IsPageAlmostIdle() const override;
bool IsVisible() const override;
base::TimeDelta GetTimeSinceLastVisibilityChange() const override;
......@@ -231,6 +235,9 @@ class PageNodeImpl : public PublicNodeImpl<PageNodeImpl, PageNode>,
// is used as a signal that the frame has reported.
size_t intervention_policy_frames_reported_ = 0;
// The unique ID of the browser context that this page belongs to.
const std::string browser_context_id_;
// Page almost idle state. This is the output that is driven by the
// PageAlmostIdleDecorator.
ObservedProperty::NotifiesOnlyOnChanges<
......
......@@ -10,7 +10,6 @@
#include "chrome/browser/performance_manager/graph/graph_impl_operations.h"
#include "chrome/browser/performance_manager/graph/graph_test_harness.h"
#include "chrome/browser/performance_manager/graph/mock_graphs.h"
#include "chrome/browser/performance_manager/graph/page_node_impl.h"
#include "chrome/browser/performance_manager/graph/process_node_impl.h"
#include "chrome/browser/performance_manager/performance_manager_clock.h"
#include "chrome/browser/performance_manager/public/graph/page_node.h"
......@@ -161,6 +160,17 @@ TEST_F(PageNodeImplTest, TimeSinceLastNavigation) {
mock_graph.page->TimeSinceLastNavigation());
}
TEST_F(PageNodeImplTest, BrowserContextID) {
const std::string kTestBrowserContextId =
base::UnguessableToken::Create().ToString();
auto page_node =
CreateNode<PageNodeImpl>(WebContentsProxy(), kTestBrowserContextId);
const PageNode* public_page_node = page_node.get();
EXPECT_EQ(page_node->browser_context_id(), kTestBrowserContextId);
EXPECT_EQ(public_page_node->GetBrowserContextID(), kTestBrowserContextId);
}
TEST_F(PageNodeImplTest, IsLoading) {
MockSinglePageInSingleProcessGraph mock_graph(graph());
auto* page_node = mock_graph.page.get();
......@@ -519,6 +529,8 @@ TEST_F(PageNodeImplTest, PublicInterface) {
// Simply test that the public interface impls yield the same result as their
// private counterpart.
EXPECT_EQ(page_node->browser_context_id(),
public_page_node->GetBrowserContextID());
EXPECT_EQ(page_node->page_almost_idle(),
public_page_node->IsPageAlmostIdle());
EXPECT_EQ(page_node->is_visible(), public_page_node->IsVisible());
......
......@@ -170,10 +170,12 @@ std::unique_ptr<FrameNodeImpl> PerformanceManager::CreateFrameNode(
std::unique_ptr<PageNodeImpl> PerformanceManager::CreatePageNode(
const WebContentsProxy& contents_proxy,
const std::string& browser_context_id,
bool is_visible,
bool is_audible) {
return CreateNodeImpl<PageNodeImpl>(base::OnceCallback<void(PageNodeImpl*)>(),
contents_proxy, is_visible, is_audible);
contents_proxy, browser_context_id,
is_visible, is_audible);
}
std::unique_ptr<ProcessNodeImpl> PerformanceManager::CreateProcessNode(
......
......@@ -103,6 +103,7 @@ class PerformanceManager {
FrameNodeCreationCallback creation_callback);
std::unique_ptr<PageNodeImpl> CreatePageNode(
const WebContentsProxy& contents_proxy,
const std::string& browser_context_id,
bool is_visible,
bool is_audible);
std::unique_ptr<ProcessNodeImpl> CreateProcessNode(
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/performance_manager/graph/process_node_impl.h"
#include "chrome/browser/performance_manager/performance_manager.h"
#include "chrome/browser/performance_manager/render_process_user_data.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/site_instance.h"
......@@ -36,6 +37,7 @@ PerformanceManagerTabHelper::PerformanceManagerTabHelper(
performance_manager_(PerformanceManager::GetInstance()) {
page_node_ = performance_manager_->CreatePageNode(
WebContentsProxy(weak_factory_.GetWeakPtr()),
web_contents->GetBrowserContext()->UniqueId(),
web_contents->GetVisibility() == content::Visibility::VISIBLE,
web_contents->IsCurrentlyAudible());
......
......@@ -58,7 +58,8 @@ TEST_F(PerformanceManagerTest, InstantiateNodes) {
performance_manager()->CreateProcessNode(RenderProcessHostProxy());
EXPECT_NE(nullptr, process_node.get());
std::unique_ptr<PageNodeImpl> page_node =
performance_manager()->CreatePageNode(WebContentsProxy(), false, false);
performance_manager()->CreatePageNode(WebContentsProxy(), std::string(),
false, false);
EXPECT_NE(nullptr, page_node.get());
// Create a node of each type.
......@@ -78,7 +79,8 @@ TEST_F(PerformanceManagerTest, BatchDeleteNodes) {
std::unique_ptr<ProcessNodeImpl> process_node =
performance_manager()->CreateProcessNode(RenderProcessHostProxy());
std::unique_ptr<PageNodeImpl> page_node =
performance_manager()->CreatePageNode(WebContentsProxy(), false, false);
performance_manager()->CreatePageNode(WebContentsProxy(), std::string(),
false, false);
std::unique_ptr<FrameNodeImpl> parent1_frame =
performance_manager()->CreateFrameNode(
......@@ -121,7 +123,8 @@ TEST_F(PerformanceManagerTest, BatchDeleteNodes) {
TEST_F(PerformanceManagerTest, CallOnGraph) {
// Create a page node for something to target.
std::unique_ptr<PageNodeImpl> page_node =
performance_manager()->CreatePageNode(WebContentsProxy(), false, false);
performance_manager()->CreatePageNode(WebContentsProxy(), std::string(),
false, false);
PerformanceManager::GraphCallback graph_callback = base::BindLambdaForTesting(
[&page_node](GraphImpl* graph) { EXPECT_EQ(page_node->graph(), graph); });
......
......@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_PERFORMANCE_MANAGER_PUBLIC_GRAPH_PAGE_NODE_H_
#define CHROME_BROWSER_PERFORMANCE_MANAGER_PUBLIC_GRAPH_PAGE_NODE_H_
#include <string>
#include "base/containers/flat_set.h"
#include "base/macros.h"
#include "chrome/browser/performance_manager/public/graph/node.h"
......@@ -31,6 +33,9 @@ class PageNode : public Node {
PageNode();
~PageNode() override;
// Returns the unique ID of the browser context that this page belongs to.
virtual const std::string& GetBrowserContextID() const = 0;
// Returns the page almost idle state of this page.
// See PageNodeObserver::OnPageAlmostIdleChanged.
virtual bool IsPageAlmostIdle() const = 0;
......
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