Commit caec9a07 authored by Hailey Wang's avatar Hailey Wang Committed by Commit Bot

[PM] Add tab properties class decorator.

Properties of PageNode that are tabs.

This class will be used for background page loading policy.

Bug: 1059341
Change-Id: Ic25aa92d06f6690a91d8e2de310478427ca97964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2085633
Commit-Queue: Hailey Wang <haileywang@google.com>
Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747874}
parent 99703f90
......@@ -8,6 +8,7 @@ static_library("performance_manager") {
"decorators/page_load_tracker_decorator.cc",
"decorators/page_load_tracker_decorator.h",
"decorators/page_load_tracker_decorator_helper.cc",
"decorators/tab_properties_decorator.cc",
"embedder/performance_manager_lifetime.h",
"embedder/performance_manager_registry.h",
"frame_priority/boosting_vote_aggregator.cc",
......@@ -60,6 +61,7 @@ static_library("performance_manager") {
"process_node_source.h",
"public/decorators/page_live_state_decorator.h",
"public/decorators/page_load_tracker_decorator_helper.h",
"public/decorators/tab_properties_decorator.h",
"public/frame_priority/boosting_vote_aggregator.h",
"public/frame_priority/frame_priority.h",
"public/frame_priority/max_vote_aggregator.h",
......@@ -105,6 +107,7 @@ source_set("unit_tests") {
"decorators/decorators_utils_unittest.cc",
"decorators/page_live_state_decorator_unittest.cc",
"decorators/page_load_tracker_decorator_unittest.cc",
"decorators/tab_properties_decorator_unittest.cc",
"frame_priority/boosting_vote_aggregator_unittest.cc",
"frame_priority/frame_priority_unittest.cc",
"frame_priority/max_vote_aggregator_unittest.cc",
......
// 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 "components/performance_manager/decorators/decorators_utils.h"
#include "components/performance_manager/graph/node_attached_data_impl.h"
#include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/public/performance_manager.h"
#include "content/public/browser/browser_thread.h"
namespace performance_manager {
namespace {
class TabPropertiesDataImpl
: public TabPropertiesDecorator::Data,
public NodeAttachedDataImpl<TabPropertiesDataImpl> {
public:
struct Traits : public NodeAttachedDataInMap<PageNodeImpl> {};
~TabPropertiesDataImpl() override = default;
TabPropertiesDataImpl(const TabPropertiesDataImpl& other) = delete;
TabPropertiesDataImpl& operator=(const TabPropertiesDataImpl&) = delete;
// TabPropertiesDecorator::Data implementation.
bool IsInTabStrip() const override { return is_tab_; }
void set_is_tab(bool is_tab) { is_tab_ = is_tab; }
private:
// Make the impl our friend so it can access the constructor and any
// storage providers.
friend class ::performance_manager::NodeAttachedDataImpl<
TabPropertiesDataImpl>;
explicit TabPropertiesDataImpl(const PageNodeImpl* page_node) {}
bool is_tab_ = false;
};
} // namespace
void TabPropertiesDecorator::SetIsTab(content::WebContents* contents,
bool is_tab) {
SetPropertyForWebContentsPageNode(contents,
&TabPropertiesDataImpl::set_is_tab, is_tab);
}
TabPropertiesDecorator::Data::Data() = default;
TabPropertiesDecorator::Data::~Data() = default;
TabPropertiesDecorator::Data*
TabPropertiesDecorator::Data::GetOrCreateForTesting(PageNode* page_node) {
return TabPropertiesDataImpl::GetOrCreate(PageNodeImpl::FromNode(page_node));
}
} // namespace performance_manager
\ No newline at end of file
// 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 "components/performance_manager/performance_manager_test_harness.h"
#include "components/performance_manager/test_support/decorators_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace performance_manager {
class TabPropertiesDecoratorTest : public PerformanceManagerTestHarness {
public:
TabPropertiesDecoratorTest() = default;
~TabPropertiesDecoratorTest() override = default;
TabPropertiesDecoratorTest(const TabPropertiesDecoratorTest& other) = delete;
TabPropertiesDecoratorTest& operator=(const TabPropertiesDecoratorTest&) =
delete;
void SetUp() override {
PerformanceManagerTestHarness::SetUp();
SetContents(CreateTestWebContents());
}
void TearDown() override {
DeleteContents();
PerformanceManagerTestHarness::TearDown();
}
};
TEST_F(TabPropertiesDecoratorTest, SetIsTab) {
testing::EndToEndBooleanPropertyTest(
web_contents(), &TabPropertiesDecorator::Data::IsInTabStrip,
&TabPropertiesDecorator::SetIsTab);
}
} // namespace performance_manager
\ No newline at end of file
// 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 COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_DECORATORS_TAB_PROPERTIES_DECORATOR_H_
#define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_DECORATORS_TAB_PROPERTIES_DECORATOR_H_
namespace content {
class WebContents;
} // namespace content
namespace performance_manager {
class PageNode;
// The TabProperties decorator is responsible for tracking properties of
// PageNodes that are tabs. All the functions that take a WebContents* as a
// parameter should only be called from the UI thread, the event will be
// forwarded to the corresponding PageNode on the Performance Manager's
// sequence.
class TabPropertiesDecorator {
public:
class Data;
// This object should only be used via its static methods.
TabPropertiesDecorator() = delete;
~TabPropertiesDecorator() = delete;
TabPropertiesDecorator(const TabPropertiesDecorator& other) = delete;
TabPropertiesDecorator& operator=(const TabPropertiesDecorator&) = delete;
// Set the is_tab property of a PageNode.
static void SetIsTab(content::WebContents* contents, bool is_tab);
};
class TabPropertiesDecorator::Data {
public:
Data();
virtual ~Data();
Data(const Data& other) = delete;
Data& operator=(const Data&) = delete;
// Indicates if a PageNode belongs to a tab strip.
virtual bool IsInTabStrip() const = 0;
static Data* GetOrCreateForTesting(PageNode* page_node);
};
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_DECORATORS_TAB_PROPERTIES_DECORATOR_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