Commit 258ab397 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

[PM] Set page visibility at node creation time.

This will allow graph observers to immediately know the page
visibility in the OnNodeAdded() function.

Bug: 910288
Change-Id: Ib369b4dc36447a408b0fc4971ed01779ef42df1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637579
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664845}
parent 2b3acdab
......@@ -91,8 +91,9 @@ template <>
struct TestNodeWrapper<PageNodeImpl>::Factory {
static std::unique_ptr<PageNodeImpl> Create(
GraphImpl* graph,
const WebContentsProxy& wc_proxy = WebContentsProxy()) {
return std::make_unique<PageNodeImpl>(graph, wc_proxy);
const WebContentsProxy& wc_proxy = WebContentsProxy(),
bool is_visible = false) {
return std::make_unique<PageNodeImpl>(graph, wc_proxy, is_visible);
}
};
......
......@@ -46,10 +46,12 @@ PageNodeImplObserver::PageNodeImplObserver() = default;
PageNodeImplObserver::~PageNodeImplObserver() = default;
PageNodeImpl::PageNodeImpl(GraphImpl* graph,
const WebContentsProxy& contents_proxy)
const WebContentsProxy& contents_proxy,
bool is_visible)
: TypedNodeBase(graph),
contents_proxy_(contents_proxy),
visibility_change_time_(PerformanceManagerClock::NowTicks()) {
visibility_change_time_(PerformanceManagerClock::NowTicks()),
is_visible_(is_visible) {
DETACH_FROM_SEQUENCE(sequence_checker_);
}
......
......@@ -79,7 +79,8 @@ class PageNodeImpl : public PublicNodeImpl<PageNodeImpl, PageNode>,
static constexpr NodeTypeEnum Type() { return NodeTypeEnum::kPage; }
explicit PageNodeImpl(GraphImpl* graph,
const WebContentsProxy& contents_proxy);
const WebContentsProxy& contents_proxy,
bool is_visible);
~PageNodeImpl() override;
// Returns the web contents associated with this page node. It is valid to
......@@ -273,8 +274,9 @@ class PageNodeImpl : public PublicNodeImpl<PageNodeImpl, PageNode>,
&Observer::OnPageAlmostIdleChanged>
page_almost_idle_{false};
// Whether or not the page is visible. Driven by browser instrumentation.
// Initialized on construction.
ObservedProperty::NotifiesOnlyOnChanges<bool, &Observer::OnIsVisibleChanged>
is_visible_{false};
is_visible_;
// The loading state. This is driven by instrumentation in the browser
// process.
ObservedProperty::NotifiesOnlyOnChanges<bool, &Observer::OnIsLoadingChanged>
......
......@@ -111,9 +111,10 @@ std::unique_ptr<FrameNodeImpl> PerformanceManager::CreateFrameNode(
}
std::unique_ptr<PageNodeImpl> PerformanceManager::CreatePageNode(
const WebContentsProxy& contents_proxy) {
const WebContentsProxy& contents_proxy,
bool is_visible) {
return CreateNodeImpl<PageNodeImpl>(base::OnceCallback<void(PageNodeImpl*)>(),
contents_proxy);
contents_proxy, is_visible);
}
std::unique_ptr<ProcessNodeImpl> PerformanceManager::CreateProcessNode() {
......
......@@ -86,7 +86,8 @@ class PerformanceManager {
int32_t site_instance_id,
FrameNodeCreationCallback creation_callback);
std::unique_ptr<PageNodeImpl> CreatePageNode(
const WebContentsProxy& contents_proxy);
const WebContentsProxy& contents_proxy,
bool is_visible);
std::unique_ptr<ProcessNodeImpl> CreateProcessNode();
// Destroys a node returned from the creation functions above.
......
......@@ -36,11 +36,8 @@ PerformanceManagerTabHelper::PerformanceManagerTabHelper(
performance_manager_(PerformanceManager::GetInstance()),
weak_factory_(this) {
page_node_ = performance_manager_->CreatePageNode(
WebContentsProxy(weak_factory_.GetWeakPtr()));
// Make sure to set the visibility property when we create
// |page_resource_coordinator_|.
UpdatePageNodeVisibility(web_contents->GetVisibility());
WebContentsProxy(weak_factory_.GetWeakPtr()),
web_contents->GetVisibility() == content::Visibility::VISIBLE);
// Dispatch creation notifications for any pre-existing frames.
std::vector<content::RenderFrameHost*> existing_frames =
......@@ -210,7 +207,9 @@ void PerformanceManagerTabHelper::DidStopLoading() {
void PerformanceManagerTabHelper::OnVisibilityChanged(
content::Visibility visibility) {
UpdatePageNodeVisibility(visibility);
const bool is_visible = visibility == content::Visibility::VISIBLE;
PostToGraph(FROM_HERE, &PageNodeImpl::SetIsVisible, page_node_.get(),
is_visible);
}
void PerformanceManagerTabHelper::DidFinishNavigation(
......@@ -316,13 +315,6 @@ void PerformanceManagerTabHelper::OnMainFrameNavigation(int64_t navigation_id) {
first_time_favicon_set_ = false;
}
void PerformanceManagerTabHelper::UpdatePageNodeVisibility(
content::Visibility visibility) {
const bool is_visible = visibility == content::Visibility::VISIBLE;
PostToGraph(FROM_HERE, &PageNodeImpl::SetIsVisible, page_node_.get(),
is_visible);
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(PerformanceManagerTabHelper)
} // namespace performance_manager
......@@ -79,7 +79,6 @@ class PerformanceManagerTabHelper
Args&&... args);
void OnMainFrameNavigation(int64_t navigation_id);
void UpdatePageNodeVisibility(content::Visibility visibility);
// The performance manager for this process, if any.
PerformanceManager* const performance_manager_;
......
......@@ -57,7 +57,7 @@ TEST_F(PerformanceManagerTest, InstantiateNodes) {
performance_manager()->CreateProcessNode();
EXPECT_NE(nullptr, process_node.get());
std::unique_ptr<PageNodeImpl> page_node =
performance_manager()->CreatePageNode(WebContentsProxy());
performance_manager()->CreatePageNode(WebContentsProxy(), false);
EXPECT_NE(nullptr, page_node.get());
// Create a node of each type.
......@@ -77,7 +77,7 @@ TEST_F(PerformanceManagerTest, BatchDeleteNodes) {
std::unique_ptr<ProcessNodeImpl> process_node =
performance_manager()->CreateProcessNode();
std::unique_ptr<PageNodeImpl> page_node =
performance_manager()->CreatePageNode(WebContentsProxy());
performance_manager()->CreatePageNode(WebContentsProxy(), false);
std::unique_ptr<FrameNodeImpl> parent1_frame =
performance_manager()->CreateFrameNode(
......@@ -120,7 +120,7 @@ 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());
performance_manager()->CreatePageNode(WebContentsProxy(), false);
PerformanceManager::GraphCallback graph_callback = base::BindLambdaForTesting(
[&page_node](GraphImpl* graph) { EXPECT_EQ(page_node->graph(), graph); });
......
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