Commit 7f858a6c authored by Duc Bui's avatar Duc Bui Committed by Commit Bot

Keep track of restored-in-foreground tabs.

Since we want to record UMA for session-restored tabs only when they are
initially foreground, we need to track restored-in-foreground tabs. This
CL adds tracking of tabs which are created by session restore and
initially in foreground.

IsTabRestoredInForeground() API added by this CL will be used in
SessionRestorePageLoadMetricsObserver to measure FP, FCP and FMP for
foreground tabs during session restore (http://crrev.com/2930013005/).

started_in_foreground in PageLoadMetricsObserver::OnStart() cannot be
used to determine whether a tab is initially foreground after it is
created by session restore or not. For example, when browser-side
navigation is disabled and a restored tab is created in background,
switching to it before it loads will yield started_in_foreground as
true.

Bug: 731901
Change-Id: I58c6c0330bf6121e78d9d9b9cad72729faeb8885
Reviewed-on: https://chromium-review.googlesource.com/599507Reviewed-by: default avatarZhen Wang <zhenw@chromium.org>
Reviewed-by: default avatarFadi Meawad <fmeawad@chromium.org>
Commit-Queue: Duc Bui <ducbui@google.com>
Cr-Commit-Position: refs/heads/master@{#491821}
parent 44a32024
......@@ -598,6 +598,10 @@ bool TabManager::IsTabInSessionRestore(WebContents* web_contents) const {
return GetWebContentsData(web_contents)->is_in_session_restore();
}
bool TabManager::IsTabRestoredInForeground(WebContents* web_contents) const {
return GetWebContentsData(web_contents)->is_restored_in_foreground();
}
///////////////////////////////////////////////////////////////////////////////
// TabManager, private:
......@@ -1159,6 +1163,7 @@ void TabManager::OnWillRestoreTab(WebContents* web_contents) {
WebContentsData* data = GetWebContentsData(web_contents);
DCHECK(!data->is_in_session_restore());
data->SetIsInSessionRestore(true);
data->SetIsRestoredInForeground(web_contents->IsVisible());
}
void TabManager::OnDidFinishNavigation(
......
......@@ -222,6 +222,10 @@ class TabManager : public TabStripModelObserver,
// the first navigation.
bool IsTabInSessionRestore(content::WebContents* web_contents) const;
// Returns true if the tab was created by session restore and initially in
// foreground.
bool IsTabRestoredInForeground(content::WebContents* web_contents) const;
private:
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, PurgeBackgroundRenderer);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ActivateTabResetPurgeState);
......@@ -268,6 +272,7 @@ class TabManager : public TabStripModelObserver,
ProactiveFastShutdownWithBeforeunloadHandler);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest,
UrgentFastShutdownWithBeforeunloadHandler);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsTabRestoredInForeground);
// The time of the first purging after a renderer is backgrounded.
// The initial value was chosen because most of users activate backgrounded
......
......@@ -976,4 +976,18 @@ TEST_F(TabManagerTest, BackgroundTabsLoadingOrdering) {
EXPECT_FALSE(tab_manager->IsNavigationDelayedForTest(nav_handle3_.get()));
}
TEST_F(TabManagerTest, IsTabRestoredInForeground) {
TabManager* tab_manager = g_browser_process->GetTabManager();
std::unique_ptr<WebContents> contents(CreateWebContents());
contents->WasShown();
tab_manager->OnWillRestoreTab(contents.get());
EXPECT_TRUE(tab_manager->IsTabRestoredInForeground(contents.get()));
contents.reset(CreateWebContents());
contents->WasHidden();
tab_manager->OnWillRestoreTab(contents.get());
EXPECT_FALSE(tab_manager->IsTabRestoredInForeground(contents.get()));
}
} // namespace resource_coordinator
......@@ -212,7 +212,8 @@ TabManager::WebContentsData::Data::Data()
engagement_score(-1.0),
is_auto_discardable(true),
tab_loading_state(TAB_IS_NOT_LOADING),
is_in_session_restore(false) {}
is_in_session_restore(false),
is_restored_in_foreground(false) {}
bool TabManager::WebContentsData::Data::operator==(const Data& right) const {
return is_discarded == right.is_discarded &&
......@@ -222,7 +223,9 @@ bool TabManager::WebContentsData::Data::operator==(const Data& right) const {
last_reload_time == right.last_reload_time &&
last_inactive_time == right.last_inactive_time &&
engagement_score == right.engagement_score &&
tab_loading_state == right.tab_loading_state;
tab_loading_state == right.tab_loading_state &&
is_in_session_restore == right.is_in_session_restore &&
is_restored_in_foreground == right.is_restored_in_foreground;
}
bool TabManager::WebContentsData::Data::operator!=(const Data& right) const {
......
......@@ -143,6 +143,14 @@ class TabManager::WebContentsData
bool is_in_session_restore() const { return tab_data_.is_in_session_restore; }
void SetIsRestoredInForeground(bool is_restored_in_foreground) {
tab_data_.is_restored_in_foreground = is_restored_in_foreground;
}
bool is_restored_in_foreground() const {
return tab_data_.is_restored_in_foreground;
}
private:
// Needed to access tab_data_.
FRIEND_TEST_ALL_PREFIXES(TabManagerWebContentsDataTest, CopyState);
......@@ -177,6 +185,8 @@ class TabManager::WebContentsData
// True if the tab was created by session restore. Remains true until the
// end of the first navigation or the tab is closed.
bool is_in_session_restore;
// True if the tab was created by session restore and initially foreground.
bool is_restored_in_foreground;
};
// Returns either the system's clock or the test clock. See |test_tick_clock_|
......
......@@ -235,4 +235,10 @@ TEST_F(TabManagerWebContentsDataTest, IsInSessionRestoreWithTabClose) {
EXPECT_FALSE(tab_data()->is_in_session_restore());
}
TEST_F(TabManagerWebContentsDataTest, IsTabRestoredInForeground) {
EXPECT_FALSE(tab_data()->is_restored_in_foreground());
tab_data()->SetIsRestoredInForeground(true);
EXPECT_TRUE(tab_data()->is_restored_in_foreground());
}
} // namespace resource_coordinator
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