Commit 10c8a12f authored by Hailey Wang's avatar Hailey Wang Committed by Commit Bot

[PM] PageNodeImpl's TimeSinceLastVisibilityChange initial value

Change the initial value to the LastActiveTime of the web content.

Used inside BackgroundTabLoadingPolicy in order to determine if a
PageNode should be loaded.

Bug: 1059341
Change-Id: Ieea245eaaebc3cb71ccaad6bb31695df160e6813
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132526
Commit-Queue: Hailey Wang <haileywang@google.com>
Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755575}
parent 39760144
...@@ -20,9 +20,10 @@ PageNodeImpl::PageNodeImpl(const WebContentsProxy& contents_proxy, ...@@ -20,9 +20,10 @@ PageNodeImpl::PageNodeImpl(const WebContentsProxy& contents_proxy,
const std::string& browser_context_id, const std::string& browser_context_id,
const GURL& visible_url, const GURL& visible_url,
bool is_visible, bool is_visible,
bool is_audible) bool is_audible,
base::TimeTicks visibility_change_time)
: contents_proxy_(contents_proxy), : contents_proxy_(contents_proxy),
visibility_change_time_(base::TimeTicks::Now()), visibility_change_time_(visibility_change_time),
main_frame_url_(visible_url), main_frame_url_(visible_url),
browser_context_id_(browser_context_id), browser_context_id_(browser_context_id),
is_visible_(is_visible), is_visible_(is_visible),
......
...@@ -33,7 +33,8 @@ class PageNodeImpl ...@@ -33,7 +33,8 @@ class PageNodeImpl
const std::string& browser_context_id, const std::string& browser_context_id,
const GURL& visible_url, const GURL& visible_url,
bool is_visible, bool is_visible,
bool is_audible); bool is_audible,
base::TimeTicks visibility_change_time);
~PageNodeImpl() override; ~PageNodeImpl() override;
// Returns the web contents associated with this page node. It is valid to // Returns the web contents associated with this page node. It is valid to
......
...@@ -124,10 +124,12 @@ std::unique_ptr<PageNodeImpl> PerformanceManagerImpl::CreatePageNode( ...@@ -124,10 +124,12 @@ std::unique_ptr<PageNodeImpl> PerformanceManagerImpl::CreatePageNode(
const std::string& browser_context_id, const std::string& browser_context_id,
const GURL& visible_url, const GURL& visible_url,
bool is_visible, bool is_visible,
bool is_audible) { bool is_audible,
base::TimeTicks visibility_change_time) {
return CreateNodeImpl<PageNodeImpl>(base::OnceCallback<void(PageNodeImpl*)>(), return CreateNodeImpl<PageNodeImpl>(base::OnceCallback<void(PageNodeImpl*)>(),
contents_proxy, browser_context_id, contents_proxy, browser_context_id,
visible_url, is_visible, is_audible); visible_url, is_visible, is_audible,
visibility_change_time);
} }
// static // static
......
...@@ -100,7 +100,8 @@ class PerformanceManagerImpl : public PerformanceManager { ...@@ -100,7 +100,8 @@ class PerformanceManagerImpl : public PerformanceManager {
const std::string& browser_context_id, const std::string& browser_context_id,
const GURL& visible_url, const GURL& visible_url,
bool is_visible, bool is_visible,
bool is_audible); bool is_audible,
base::TimeTicks visibility_change_time);
static std::unique_ptr<ProcessNodeImpl> CreateProcessNode( static std::unique_ptr<ProcessNodeImpl> CreateProcessNode(
RenderProcessHostProxy proxy); RenderProcessHostProxy proxy);
static std::unique_ptr<WorkerNodeImpl> CreateWorkerNode( static std::unique_ptr<WorkerNodeImpl> CreateWorkerNode(
......
...@@ -55,7 +55,8 @@ TEST_F(PerformanceManagerImplTest, InstantiateNodes) { ...@@ -55,7 +55,8 @@ TEST_F(PerformanceManagerImplTest, InstantiateNodes) {
EXPECT_NE(nullptr, process_node.get()); EXPECT_NE(nullptr, process_node.get());
std::unique_ptr<PageNodeImpl> page_node = std::unique_ptr<PageNodeImpl> page_node =
PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(), PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(),
GURL(), false, false); GURL(), false, false,
base::TimeTicks::Now());
EXPECT_NE(nullptr, page_node.get()); EXPECT_NE(nullptr, page_node.get());
// Create a node of each type. // Create a node of each type.
...@@ -77,7 +78,8 @@ TEST_F(PerformanceManagerImplTest, BatchDeleteNodes) { ...@@ -77,7 +78,8 @@ TEST_F(PerformanceManagerImplTest, BatchDeleteNodes) {
PerformanceManagerImpl::CreateProcessNode(RenderProcessHostProxy()); PerformanceManagerImpl::CreateProcessNode(RenderProcessHostProxy());
std::unique_ptr<PageNodeImpl> page_node = std::unique_ptr<PageNodeImpl> page_node =
PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(), PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(),
GURL(), false, false); GURL(), false, false,
base::TimeTicks::Now());
std::unique_ptr<FrameNodeImpl> parent1_frame = std::unique_ptr<FrameNodeImpl> parent1_frame =
PerformanceManagerImpl::CreateFrameNode( PerformanceManagerImpl::CreateFrameNode(
...@@ -121,7 +123,8 @@ TEST_F(PerformanceManagerImplTest, CallOnGraphImpl) { ...@@ -121,7 +123,8 @@ TEST_F(PerformanceManagerImplTest, CallOnGraphImpl) {
// Create a page node for something to target. // Create a page node for something to target.
std::unique_ptr<PageNodeImpl> page_node = std::unique_ptr<PageNodeImpl> page_node =
PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(), PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(),
GURL(), false, false); GURL(), false, false,
base::TimeTicks::Now());
base::RunLoop run_loop; base::RunLoop run_loop;
base::OnceClosure quit_closure = run_loop.QuitClosure(); base::OnceClosure quit_closure = run_loop.QuitClosure();
EXPECT_FALSE(PerformanceManagerImpl::OnPMTaskRunnerForTesting()); EXPECT_FALSE(PerformanceManagerImpl::OnPMTaskRunnerForTesting());
...@@ -142,7 +145,8 @@ TEST_F(PerformanceManagerImplTest, CallOnGraphAndReplyWithResult) { ...@@ -142,7 +145,8 @@ TEST_F(PerformanceManagerImplTest, CallOnGraphAndReplyWithResult) {
// Create a page node for something to target. // Create a page node for something to target.
std::unique_ptr<PageNodeImpl> page_node = std::unique_ptr<PageNodeImpl> page_node =
PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(), PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), std::string(),
GURL(), false, false); GURL(), false, false,
base::TimeTicks::Now());
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_FALSE(PerformanceManagerImpl::OnPMTaskRunnerForTesting()); EXPECT_FALSE(PerformanceManagerImpl::OnPMTaskRunnerForTesting());
......
...@@ -33,7 +33,7 @@ PerformanceManagerTabHelper::PerformanceManagerTabHelper( ...@@ -33,7 +33,7 @@ PerformanceManagerTabHelper::PerformanceManagerTabHelper(
web_contents->GetBrowserContext()->UniqueId(), web_contents->GetBrowserContext()->UniqueId(),
web_contents->GetVisibleURL(), web_contents->GetVisibleURL(),
web_contents->GetVisibility() == content::Visibility::VISIBLE, web_contents->GetVisibility() == content::Visibility::VISIBLE,
web_contents->IsCurrentlyAudible()); web_contents->IsCurrentlyAudible(), web_contents->GetLastActiveTime());
// Dispatch creation notifications for any pre-existing frames. // Dispatch creation notifications for any pre-existing frames.
std::vector<content::RenderFrameHost*> existing_frames = std::vector<content::RenderFrameHost*> existing_frames =
web_contents->GetAllFrames(); web_contents->GetAllFrames();
......
...@@ -108,9 +108,11 @@ struct TestNodeWrapper<PageNodeImpl>::Factory { ...@@ -108,9 +108,11 @@ struct TestNodeWrapper<PageNodeImpl>::Factory {
const std::string& browser_context_id = std::string(), const std::string& browser_context_id = std::string(),
const GURL& url = GURL(), const GURL& url = GURL(),
bool is_visible = false, bool is_visible = false,
bool is_audible = false) { bool is_audible = false,
base::TimeTicks visibility_change_time = base::TimeTicks::Now()) {
return std::make_unique<PageNodeImpl>(wc_proxy, browser_context_id, url, return std::make_unique<PageNodeImpl>(wc_proxy, browser_context_id, url,
is_visible, is_audible); is_visible, is_audible,
visibility_change_time);
} }
}; };
......
...@@ -502,11 +502,13 @@ class TestFrameNodeSource : public FrameNodeSource { ...@@ -502,11 +502,13 @@ class TestFrameNodeSource : public FrameNodeSource {
}; };
TestFrameNodeSource::TestFrameNodeSource() TestFrameNodeSource::TestFrameNodeSource()
: page_node_(PerformanceManagerImpl::CreatePageNode(WebContentsProxy(), : page_node_(
"page_node_context_id", PerformanceManagerImpl::CreatePageNode(WebContentsProxy(),
GURL(), "page_node_context_id",
false, GURL(),
false)) {} false,
false,
base::TimeTicks::Now())) {}
TestFrameNodeSource::~TestFrameNodeSource() { TestFrameNodeSource::~TestFrameNodeSource() {
std::vector<std::unique_ptr<NodeBase>> nodes; std::vector<std::unique_ptr<NodeBase>> nodes;
......
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