Commit 3240afe8 authored by Hailey Wang's avatar Hailey Wang Committed by Commit Bot

[PM] Set tab properties when creating a PageNode

Tab properties will be used for upcoming Performance Manager session
restore policy.

Bug: 1059341
Change-Id: I81214143b55d747cfbde02d6a6959f5c83c36323
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2091653Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Hailey Wang <haileywang@google.com>
Cr-Commit-Position: refs/heads/master@{#748864}
parent ceb560cc
// 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 "components/performance_manager/public/decorators/tab_properties_decorator.h"
#include "base/test/bind_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/public/performance_manager.h"
namespace performance_manager {
using TabPropertiesDecoratorBrowserTest = InProcessBrowserTest;
// Integration test verifying that when a PageNode is created for a tab, the
// corresponding tab properties is set.
IN_PROC_BROWSER_TEST_F(TabPropertiesDecoratorBrowserTest, SetIsTab) {
EXPECT_EQ(1, browser()->tab_strip_model()->count());
// Get PageNode associated with the current tab.
base::WeakPtr<PageNode> page_node =
PerformanceManager::GetPageNodeForWebContents(
browser()->tab_strip_model()->GetActiveWebContents());
// Get data from the PageNode and verify the tab properties.
base::RunLoop run_loop;
auto call_on_graph_cb = base::BindLambdaForTesting([&](Graph* unused) {
EXPECT_TRUE(page_node);
EXPECT_TRUE(TabPropertiesDecorator::Data::FromPageNode(page_node.get())
->IsInTabStrip());
run_loop.Quit();
});
PerformanceManager::CallOnGraph(FROM_HERE, call_on_graph_cb);
run_loop.Run();
}
} // namespace performance_manager
......@@ -102,6 +102,7 @@
#include "components/offline_pages/buildflags/buildflags.h"
#include "components/password_manager/core/browser/password_manager.h"
#include "components/performance_manager/embedder/performance_manager_registry.h"
#include "components/performance_manager/public/decorators/tab_properties_decorator.h"
#include "components/permissions/permission_request_manager.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "components/tracing/common/tracing_switches.h"
......@@ -267,6 +268,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
if (auto* performance_manager_registry =
performance_manager::PerformanceManagerRegistry::GetInstance()) {
performance_manager_registry->CreatePageNodeForWebContents(web_contents);
performance_manager::TabPropertiesDecorator::SetIsTab(web_contents, true);
}
permissions::PermissionRequestManager::CreateForWebContents(web_contents);
// The PopupBlockerTabHelper has an implicit dependency on
......
......@@ -1059,6 +1059,7 @@ if (!is_android) {
"../browser/pdf/pdf_extension_test_util.h",
"../browser/performance_manager/graph/page_node_impl_browsertest.cc",
"../browser/performance_manager/page_load_tracker_decorator_browsertest.cc",
"../browser/performance_manager/tab_properties_decorator_browsertest.cc",
"../browser/permissions/permission_delegation_browsertest.cc",
"../browser/permissions/permission_manager_browsertest.cc",
"../browser/permissions/permission_request_manager_browsertest.cc",
......
......@@ -50,6 +50,11 @@ void TabPropertiesDecorator::SetIsTab(content::WebContents* contents,
TabPropertiesDecorator::Data::Data() = default;
TabPropertiesDecorator::Data::~Data() = default;
const TabPropertiesDecorator::Data* TabPropertiesDecorator::Data::FromPageNode(
const PageNode* page_node) {
return TabPropertiesDataImpl::Get(PageNodeImpl::FromNode(page_node));
}
TabPropertiesDecorator::Data*
TabPropertiesDecorator::Data::GetOrCreateForTesting(PageNode* page_node) {
return TabPropertiesDataImpl::GetOrCreate(PageNodeImpl::FromNode(page_node));
......
......@@ -42,6 +42,7 @@ class TabPropertiesDecorator::Data {
// Indicates if a PageNode belongs to a tab strip.
virtual bool IsInTabStrip() const = 0;
static const Data* FromPageNode(const PageNode* page_node);
static Data* GetOrCreateForTesting(PageNode* page_node);
};
......
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