Commit 77be021f authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Remove TabManager::IsTabDiscarded/IsTabAutoDiscardable.

These properties are available on TabLifecycleUnitExternal, which
is intended for use outside of
chrome/browser/resource_coordinator/.

Bug: 775644
Change-Id: I5708c3be32806c0109ad04ece1fffaa5f1f0709f
Reviewed-on: https://chromium-review.googlesource.com/858046
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548414}
parent 7a462a5d
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "chrome/browser/extensions/window_controller_list.h" #include "chrome/browser/extensions/window_controller_list.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_manager.h" #include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/sessions/session_tab_helper.h" #include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/translate/chrome_translate_client.h" #include "chrome/browser/translate/chrome_translate_client.h"
...@@ -986,8 +987,6 @@ ExtensionFunction::ResponseAction TabsQueryFunction::Run() { ...@@ -986,8 +987,6 @@ ExtensionFunction::ResponseAction TabsQueryFunction::Run() {
TabStripModel* tab_strip = browser->tab_strip_model(); TabStripModel* tab_strip = browser->tab_strip_model();
for (int i = 0; i < tab_strip->count(); ++i) { for (int i = 0; i < tab_strip->count(); ++i) {
WebContents* web_contents = tab_strip->GetWebContentsAt(i); WebContents* web_contents = tab_strip->GetWebContentsAt(i);
resource_coordinator::TabManager* tab_manager =
g_browser_process->GetTabManager();
if (index > -1 && i != index) if (index > -1 && i != index)
continue; continue;
...@@ -1016,13 +1015,17 @@ ExtensionFunction::ResponseAction TabsQueryFunction::Run() { ...@@ -1016,13 +1015,17 @@ ExtensionFunction::ResponseAction TabsQueryFunction::Run() {
continue; continue;
} }
auto* tab_lifecycle_unit_external =
resource_coordinator::TabLifecycleUnitExternal::FromWebContents(
web_contents);
if (!MatchesBool(params->query_info.discarded.get(), if (!MatchesBool(params->query_info.discarded.get(),
tab_manager->IsTabDiscarded(web_contents))) { tab_lifecycle_unit_external->IsDiscarded())) {
continue; continue;
} }
if (!MatchesBool(params->query_info.auto_discardable.get(), if (!MatchesBool(params->query_info.auto_discardable.get(),
tab_manager->IsTabAutoDiscardable(web_contents))) { tab_lifecycle_unit_external->IsAutoDiscardable())) {
continue; continue;
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "chrome/browser/extensions/window_controller.h" #include "chrome/browser/extensions/window_controller.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_manager.h" #include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/resource_coordinator/time.h" #include "chrome/browser/resource_coordinator/time.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -1460,10 +1461,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithId) { ...@@ -1460,10 +1461,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithId) {
discard.get(), base::StringPrintf("[%u]", tab_id), browser()))); discard.get(), base::StringPrintf("[%u]", tab_id), browser())));
// Confirms that TabManager sees the tab as discarded. // Confirms that TabManager sees the tab as discarded.
resource_coordinator::TabManager* tab_manager =
g_browser_process->GetTabManager();
web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
EXPECT_TRUE(tab_manager->IsTabDiscarded(web_contents)); EXPECT_TRUE(resource_coordinator::TabLifecycleUnitExternal::FromWebContents(
web_contents)
->IsDiscarded());
// Make sure the returned tab is the one discarded and its discarded state is // Make sure the returned tab is the one discarded and its discarded state is
// correct. // correct.
...@@ -1507,8 +1508,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithInvalidId) { ...@@ -1507,8 +1508,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithInvalidId) {
discard.get(), base::StringPrintf("[%u]", tab_invalid_id), browser()); discard.get(), base::StringPrintf("[%u]", tab_invalid_id), browser());
// Discarded state should still be false as no tab was discarded. // Discarded state should still be false as no tab was discarded.
EXPECT_FALSE(g_browser_process->GetTabManager()->IsTabDiscarded( EXPECT_FALSE(resource_coordinator::TabLifecycleUnitExternal::FromWebContents(
browser()->tab_strip_model()->GetWebContentsAt(1))); browser()->tab_strip_model()->GetWebContentsAt(1))
->IsDiscarded());
// Check error message. // Check error message.
EXPECT_TRUE(base::MatchPattern(error, keys::kTabNotFoundError)); EXPECT_TRUE(base::MatchPattern(error, keys::kTabNotFoundError));
...@@ -1537,7 +1539,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithoutId) { ...@@ -1537,7 +1539,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardWithoutId) {
// Confirms that TabManager sees the tab as discarded. // Confirms that TabManager sees the tab as discarded.
web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); web_contents = browser()->tab_strip_model()->GetWebContentsAt(1);
EXPECT_TRUE(g_browser_process->GetTabManager()->IsTabDiscarded(web_contents)); EXPECT_TRUE(resource_coordinator::TabLifecycleUnitExternal::FromWebContents(
web_contents)
->IsDiscarded());
// Make sure the returned tab is the one discarded and its discarded state is // Make sure the returned tab is the one discarded and its discarded state is
// correct. // correct.
...@@ -1567,10 +1571,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardNoTabProtection) { ...@@ -1567,10 +1571,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DiscardNoTabProtection) {
utils::RunFunctionAndReturnError(discard.get(), "[]", browser()); utils::RunFunctionAndReturnError(discard.get(), "[]", browser());
// Discarded state should be false for both tabs as no tab was discarded. // Discarded state should be false for both tabs as no tab was discarded.
EXPECT_FALSE(g_browser_process->GetTabManager()->IsTabDiscarded( EXPECT_FALSE(resource_coordinator::TabLifecycleUnitExternal::FromWebContents(
browser()->tab_strip_model()->GetWebContentsAt(1))); browser()->tab_strip_model()->GetWebContentsAt(1))
EXPECT_FALSE(g_browser_process->GetTabManager()->IsTabDiscarded( ->IsDiscarded());
browser()->tab_strip_model()->GetWebContentsAt(0))); EXPECT_FALSE(resource_coordinator::TabLifecycleUnitExternal::FromWebContents(
browser()->tab_strip_model()->GetWebContentsAt(0))
->IsDiscarded());
// Check error message. // Check error message.
EXPECT_TRUE(base::MatchPattern(error, keys::kCannotFindTabToDiscard)); EXPECT_TRUE(base::MatchPattern(error, keys::kCannotFindTabToDiscard));
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "chrome/browser/extensions/chrome_extension_function_details.h" #include "chrome/browser/extensions/chrome_extension_function_details.h"
#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/tab_manager.h" #include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/sessions/session_tab_helper.h" #include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
...@@ -352,10 +352,13 @@ std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( ...@@ -352,10 +352,13 @@ std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject(
tab_object->highlighted = tab_strip && tab_strip->IsTabSelected(tab_index); tab_object->highlighted = tab_strip && tab_strip->IsTabSelected(tab_index);
tab_object->pinned = tab_strip && tab_strip->IsTabPinned(tab_index); tab_object->pinned = tab_strip && tab_strip->IsTabPinned(tab_index);
tab_object->audible = std::make_unique<bool>(contents->WasRecentlyAudible()); tab_object->audible = std::make_unique<bool>(contents->WasRecentlyAudible());
auto* tab_lifeycle_unit_external =
resource_coordinator::TabLifecycleUnitExternal::FromWebContents(contents);
tab_object->discarded = tab_object->discarded =
g_browser_process->GetTabManager()->IsTabDiscarded(contents); tab_lifeycle_unit_external && tab_lifeycle_unit_external->IsDiscarded();
tab_object->auto_discardable = tab_object->auto_discardable =
g_browser_process->GetTabManager()->IsTabAutoDiscardable(contents); !tab_lifeycle_unit_external ||
tab_lifeycle_unit_external->IsAutoDiscardable();
tab_object->muted_info = CreateMutedInfo(contents); tab_object->muted_info = CreateMutedInfo(contents);
tab_object->incognito = contents->GetBrowserContext()->IsOffTheRecord(); tab_object->incognito = contents->GetBrowserContext()->IsOffTheRecord();
gfx::Size contents_size = contents->GetContainerBounds().size(); gfx::Size contents_size = contents->GetContainerBounds().size();
......
...@@ -260,11 +260,6 @@ LifecycleUnitVector TabManager::GetSortedLifecycleUnits() { ...@@ -260,11 +260,6 @@ LifecycleUnitVector TabManager::GetSortedLifecycleUnits() {
return sorted_lifecycle_units; return sorted_lifecycle_units;
} }
bool TabManager::IsTabDiscarded(content::WebContents* contents) const {
auto* lifecycle_unit = TabLifecycleUnitExternal::FromWebContents(contents);
return lifecycle_unit && lifecycle_unit->IsDiscarded();
}
void TabManager::DiscardTab(DiscardReason reason) { void TabManager::DiscardTab(DiscardReason reason) {
if (reason == DiscardReason::kUrgent) if (reason == DiscardReason::kUrgent)
stats_collector_->RecordWillDiscardUrgently(GetNumAliveTabs()); stats_collector_->RecordWillDiscardUrgently(GetNumAliveTabs());
...@@ -329,11 +324,6 @@ void TabManager::RemoveObserver(TabLifecycleObserver* observer) { ...@@ -329,11 +324,6 @@ void TabManager::RemoveObserver(TabLifecycleObserver* observer) {
TabLifecycleUnitExternal::RemoveTabLifecycleObserver(observer); TabLifecycleUnitExternal::RemoveTabLifecycleObserver(observer);
} }
bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const {
auto* lifecycle_unit = TabLifecycleUnitExternal::FromWebContents(contents);
return !lifecycle_unit || lifecycle_unit->IsAutoDiscardable();
}
void TabManager::SetTabAutoDiscardableState(int32_t tab_id, bool state) { void TabManager::SetTabAutoDiscardableState(int32_t tab_id, bool state) {
for (LifecycleUnit* lifecycle_unit : lifecycle_units_) { for (LifecycleUnit* lifecycle_unit : lifecycle_units_) {
if (lifecycle_unit->GetID() == tab_id) { if (lifecycle_unit->GetID() == tab_id) {
...@@ -477,7 +467,7 @@ base::TimeDelta TabManager::GetTimeToPurge( ...@@ -477,7 +467,7 @@ base::TimeDelta TabManager::GetTimeToPurge(
bool TabManager::ShouldPurgeNow(content::WebContents* content) const { bool TabManager::ShouldPurgeNow(content::WebContents* content) const {
if (GetWebContentsData(content)->is_purged()) if (GetWebContentsData(content)->is_purged())
return false; return false;
if (IsTabDiscarded(content)) if (TabLifecycleUnitExternal::FromWebContents(content)->IsDiscarded())
return false; return false;
base::TimeDelta time_passed = base::TimeDelta time_passed =
...@@ -880,7 +870,7 @@ int TabManager::GetNumAliveTabs() const { ...@@ -880,7 +870,7 @@ int TabManager::GetNumAliveTabs() const {
TabStripModel* tab_strip_model = browser->tab_strip_model(); TabStripModel* tab_strip_model = browser->tab_strip_model();
for (int index = 0; index < tab_strip_model->count(); ++index) { for (int index = 0; index < tab_strip_model->count(); ++index) {
content::WebContents* contents = tab_strip_model->GetWebContentsAt(index); content::WebContents* contents = tab_strip_model->GetWebContentsAt(index);
if (!IsTabDiscarded(contents)) if (!TabLifecycleUnitExternal::FromWebContents(contents)->IsDiscarded())
++tab_count; ++tab_count;
} }
} }
......
...@@ -98,9 +98,6 @@ class TabManager : public LifecycleUnitObserver, ...@@ -98,9 +98,6 @@ class TabManager : public LifecycleUnitObserver,
// vector after a LifecycleUnit has been destroyed. // vector after a LifecycleUnit has been destroyed.
LifecycleUnitVector GetSortedLifecycleUnits(); LifecycleUnitVector GetSortedLifecycleUnits();
// Returns true if |contents| is currently discarded.
bool IsTabDiscarded(content::WebContents* contents) const;
// Discards a tab to free the memory occupied by its renderer. The tab still // Discards a tab to free the memory occupied by its renderer. The tab still
// exists in the tab-strip; clicking on it will reload it. If the |reason| is // exists in the tab-strip; clicking on it will reload it. If the |reason| is
// urgent, an aggressive fast-kill will be attempted if the sudden termination // urgent, an aggressive fast-kill will be attempted if the sudden termination
...@@ -138,13 +135,6 @@ class TabManager : public LifecycleUnitObserver, ...@@ -138,13 +135,6 @@ class TabManager : public LifecycleUnitObserver,
void AddObserver(TabLifecycleObserver* observer); void AddObserver(TabLifecycleObserver* observer);
void RemoveObserver(TabLifecycleObserver* observer); void RemoveObserver(TabLifecycleObserver* observer);
// Returns the auto-discardable state of the tab. When true, the tab is
// eligible to be automatically discarded when critical memory pressure hits,
// otherwise the tab is ignored and will never be automatically discarded.
// Note that this property doesn't block the discarding of the tab via other
// methods (about:discards for instance).
bool IsTabAutoDiscardable(content::WebContents* contents) const;
// Sets/clears the auto-discardable state of the tab. // Sets/clears the auto-discardable state of the tab.
void SetTabAutoDiscardableState(int32_t tab_id, bool state); void SetTabAutoDiscardableState(int32_t tab_id, bool state);
void SetTabAutoDiscardableState(content::WebContents* contents, bool state); void SetTabAutoDiscardableState(content::WebContents* contents, bool state);
......
...@@ -110,6 +110,10 @@ bool ObserveNavEntryCommitted(const GURL& expected_url, ...@@ -110,6 +110,10 @@ bool ObserveNavEntryCommitted(const GURL& expected_url,
->entry->GetURL() == expected_url; ->entry->GetURL() == expected_url;
} }
bool IsTabDiscarded(content::WebContents* web_contents) {
return TabLifecycleUnitExternal::FromWebContents(web_contents)->IsDiscarded();
}
} // namespace } // namespace
IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
...@@ -180,32 +184,32 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { ...@@ -180,32 +184,32 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
// and was not selected. // and was not selected.
EXPECT_TRUE(tab_manager->DiscardTabImpl(DiscardReason::kProactive)); EXPECT_TRUE(tab_manager->DiscardTabImpl(DiscardReason::kProactive));
EXPECT_EQ(3, tsm->count()); EXPECT_EQ(3, tsm->count());
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(2)));
// Run discard again, make sure it kills the second tab. // Run discard again, make sure it kills the second tab.
EXPECT_TRUE(tab_manager->DiscardTabImpl(DiscardReason::kProactive)); EXPECT_TRUE(tab_manager->DiscardTabImpl(DiscardReason::kProactive));
EXPECT_EQ(3, tsm->count()); EXPECT_EQ(3, tsm->count());
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(2)));
// Kill the third tab. It should not kill the last tab, since it is active // Kill the third tab. It should not kill the last tab, since it is active
// tab. // tab.
EXPECT_FALSE(tab_manager->DiscardTabImpl(DiscardReason::kProactive)); EXPECT_FALSE(tab_manager->DiscardTabImpl(DiscardReason::kProactive));
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(2)));
// Kill the third tab after making second tab active. // Kill the third tab after making second tab active.
tsm->ActivateTabAt(1, true); tsm->ActivateTabAt(1, true);
EXPECT_EQ(1, tsm->active_index()); EXPECT_EQ(1, tsm->active_index());
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
FastForwardAfterDiscardProtectionTime(); FastForwardAfterDiscardProtectionTime();
tab_manager->DiscardTabImpl(DiscardReason::kProactive); tab_manager->DiscardTabImpl(DiscardReason::kProactive);
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(2)));
// Force creation of the FindBarController. // Force creation of the FindBarController.
browser()->GetFindBarController(); browser()->GetFindBarController();
...@@ -221,9 +225,9 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { ...@@ -221,9 +225,9 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
EXPECT_EQ(browser()->GetFindBarController()->web_contents(), EXPECT_EQ(browser()->GetFindBarController()->web_contents(),
tsm->GetActiveWebContents()); tsm->GetActiveWebContents());
EXPECT_EQ(0, tsm->active_index()); EXPECT_EQ(0, tsm->active_index());
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(2)));
// Select the third tab. It should reload. // Select the third tab. It should reload.
WindowedNotificationObserver reload2( WindowedNotificationObserver reload2(
...@@ -232,9 +236,9 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { ...@@ -232,9 +236,9 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
chrome::SelectNumberedTab(browser(), 2); chrome::SelectNumberedTab(browser(), 2);
reload2.Wait(); reload2.Wait();
EXPECT_EQ(2, tsm->active_index()); EXPECT_EQ(2, tsm->active_index());
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(2)));
// Navigate the third tab back twice. We used to crash here due to // Navigate the third tab back twice. We used to crash here due to
// crbug.com/121373. // crbug.com/121373.
...@@ -262,7 +266,6 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { ...@@ -262,7 +266,6 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
// Test that the MemoryPressureListener event is properly triggering a tab // Test that the MemoryPressureListener event is properly triggering a tab
// discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event. // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event.
IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) { IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) {
TabManager* tab_manager = g_browser_process->GetTabManager();
TabStripModel* tsm = browser()->tab_strip_model(); TabStripModel* tsm = browser()->tab_strip_model();
// Get two tabs open. // Get two tabs open.
...@@ -287,14 +290,14 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) { ...@@ -287,14 +290,14 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) {
ASSERT_EQ(tsm->count(), 2); ASSERT_EQ(tsm->count(), 2);
FastForwardAfterDiscardProtectionTime(); FastForwardAfterDiscardProtectionTime();
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
// Nothing should happen with a moderate memory pressure event. // Nothing should happen with a moderate memory pressure event.
base::MemoryPressureListener::NotifyMemoryPressure( base::MemoryPressureListener::NotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
// A critical memory pressure event should discard a tab. // A critical memory pressure event should discard a tab.
base::MemoryPressureListener::NotifyMemoryPressure( base::MemoryPressureListener::NotifyMemoryPressure(
...@@ -308,11 +311,11 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) { ...@@ -308,11 +311,11 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) {
base::PlatformThread::Sleep( base::PlatformThread::Sleep(
base::TimeDelta::FromMilliseconds(kIntervalTimeInMS)); base::TimeDelta::FromMilliseconds(kIntervalTimeInMS));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
if (tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))) if (IsTabDiscarded(tsm->GetWebContentsAt(0)))
break; break;
} }
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); EXPECT_FALSE(IsTabDiscarded(tsm->GetWebContentsAt(1)));
} }
#endif #endif
...@@ -536,7 +539,7 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) { ...@@ -536,7 +539,7 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) {
// Now it should be able to discard the tab. // Now it should be able to discard the tab.
EXPECT_TRUE(tab_manager->DiscardTabImpl(DiscardReason::kProactive)); EXPECT_TRUE(tab_manager->DiscardTabImpl(DiscardReason::kProactive));
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); EXPECT_TRUE(IsTabDiscarded(tsm->GetWebContentsAt(0)));
} }
IN_PROC_BROWSER_TEST_F(TabManagerTest, PurgeBackgroundRenderer) { IN_PROC_BROWSER_TEST_F(TabManagerTest, PurgeBackgroundRenderer) {
...@@ -1090,34 +1093,28 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, ...@@ -1090,34 +1093,28 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest,
// On ChromeOS, active tabs are discarded if their window is non-visible. On // On ChromeOS, active tabs are discarded if their window is non-visible. On
// other platforms, they are never discarded. // other platforms, they are never discarded.
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
EXPECT_TRUE(tab_manager->IsTabDiscarded( EXPECT_TRUE(IsTabDiscarded(browser1->tab_strip_model()->GetWebContentsAt(0)));
browser1->tab_strip_model()->GetWebContentsAt(0))); EXPECT_FALSE(
EXPECT_FALSE(tab_manager->IsTabDiscarded( IsTabDiscarded(browser2->tab_strip_model()->GetWebContentsAt(0)));
browser2->tab_strip_model()->GetWebContentsAt(0))); EXPECT_FALSE(
EXPECT_FALSE(tab_manager->IsTabDiscarded( IsTabDiscarded(browser3->tab_strip_model()->GetWebContentsAt(0)));
browser3->tab_strip_model()->GetWebContentsAt(0))); EXPECT_TRUE(IsTabDiscarded(browser4->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_TRUE(tab_manager->IsTabDiscarded(
browser4->tab_strip_model()->GetWebContentsAt(0)));
#else #else
EXPECT_FALSE(tab_manager->IsTabDiscarded( EXPECT_FALSE(
browser1->tab_strip_model()->GetWebContentsAt(0))); IsTabDiscarded(browser1->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded( EXPECT_FALSE(
browser2->tab_strip_model()->GetWebContentsAt(0))); IsTabDiscarded(browser2->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded( EXPECT_FALSE(
browser3->tab_strip_model()->GetWebContentsAt(0))); IsTabDiscarded(browser3->tab_strip_model()->GetWebContentsAt(0)));
EXPECT_FALSE(tab_manager->IsTabDiscarded( EXPECT_FALSE(
browser4->tab_strip_model()->GetWebContentsAt(0))); IsTabDiscarded(browser4->tab_strip_model()->GetWebContentsAt(0)));
#endif #endif
// Non-active tabs can be discarded on all platforms. // Non-active tabs can be discarded on all platforms.
EXPECT_TRUE(tab_manager->IsTabDiscarded( EXPECT_TRUE(IsTabDiscarded(browser1->tab_strip_model()->GetWebContentsAt(1)));
browser1->tab_strip_model()->GetWebContentsAt(1))); EXPECT_TRUE(IsTabDiscarded(browser2->tab_strip_model()->GetWebContentsAt(1)));
EXPECT_TRUE(tab_manager->IsTabDiscarded( EXPECT_TRUE(IsTabDiscarded(browser3->tab_strip_model()->GetWebContentsAt(1)));
browser2->tab_strip_model()->GetWebContentsAt(1))); EXPECT_TRUE(IsTabDiscarded(browser4->tab_strip_model()->GetWebContentsAt(1)));
EXPECT_TRUE(tab_manager->IsTabDiscarded(
browser3->tab_strip_model()->GetWebContentsAt(1)));
EXPECT_TRUE(tab_manager->IsTabDiscarded(
browser4->tab_strip_model()->GetWebContentsAt(1)));
} }
} // namespace resource_coordinator } // namespace resource_coordinator
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h" #include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_manager_features.h" #include "chrome/browser/resource_coordinator/tab_manager_features.h"
#include "chrome/browser/resource_coordinator/tab_manager_resource_coordinator_signal_observer.h" #include "chrome/browser/resource_coordinator/tab_manager_resource_coordinator_signal_observer.h"
#include "chrome/browser/resource_coordinator/tab_manager_stats_collector.h" #include "chrome/browser/resource_coordinator/tab_manager_stats_collector.h"
...@@ -130,6 +131,10 @@ enum TestIndicies { ...@@ -130,6 +131,10 @@ enum TestIndicies {
kInternalPage, kInternalPage,
}; };
bool IsTabDiscarded(content::WebContents* web_contents) {
return TabLifecycleUnitExternal::FromWebContents(web_contents)->IsDiscarded();
}
} // namespace } // namespace
class TabManagerTest : public ChromeRenderViewHostTestHarness { class TabManagerTest : public ChromeRenderViewHostTestHarness {
...@@ -434,20 +439,20 @@ TEST_F(TabManagerTest, MAYBE_DiscardTabWithNonVisibleTabs) { ...@@ -434,20 +439,20 @@ TEST_F(TabManagerTest, MAYBE_DiscardTabWithNonVisibleTabs) {
tab_manager_->DiscardTab(DiscardReason::kProactive); tab_manager_->DiscardTab(DiscardReason::kProactive);
// Active tab in a visible window should not be discarded. // Active tab in a visible window should not be discarded.
EXPECT_FALSE(tab_manager_->IsTabDiscarded(tab_strip1->GetWebContentsAt(0))); EXPECT_FALSE(IsTabDiscarded(tab_strip1->GetWebContentsAt(0)));
// Non-active tabs should be discarded. // Non-active tabs should be discarded.
EXPECT_TRUE(tab_manager_->IsTabDiscarded(tab_strip1->GetWebContentsAt(1))); EXPECT_TRUE(IsTabDiscarded(tab_strip1->GetWebContentsAt(1)));
EXPECT_TRUE(tab_manager_->IsTabDiscarded(tab_strip2->GetWebContentsAt(1))); EXPECT_TRUE(IsTabDiscarded(tab_strip2->GetWebContentsAt(1)));
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// On ChromeOS, a non-visible tab should be discarded even if it's active in // On ChromeOS, a non-visible tab should be discarded even if it's active in
// its tab strip. // its tab strip.
EXPECT_TRUE(tab_manager_->IsTabDiscarded(tab_strip2->GetWebContentsAt(0))); EXPECT_TRUE(IsTabDiscarded(tab_strip2->GetWebContentsAt(0)));
#else #else
// On other platforms, an active tab is never discarded, even if it's not // On other platforms, an active tab is never discarded, even if it's not
// visible. // visible.
EXPECT_FALSE(tab_manager_->IsTabDiscarded(tab_strip2->GetWebContentsAt(0))); EXPECT_FALSE(IsTabDiscarded(tab_strip2->GetWebContentsAt(0)));
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
// Tabs with a committed URL must be closed explicitly to avoid DCHECK errors. // Tabs with a committed URL must be closed explicitly to avoid DCHECK errors.
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "chrome/browser/engagement/site_engagement_service.h" #include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/tab_manager.h" #include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
...@@ -236,10 +236,6 @@ void TabMetricsLogger::LogBackgroundTab(ukm::SourceId ukm_source_id, ...@@ -236,10 +236,6 @@ void TabMetricsLogger::LogBackgroundTab(ukm::SourceId ukm_source_id,
// audio indicator in the tab strip. // audio indicator in the tab strip.
entry.SetWasRecentlyAudible(web_contents->WasRecentlyAudible()); entry.SetWasRecentlyAudible(web_contents->WasRecentlyAudible());
resource_coordinator::TabManager* tab_manager =
g_browser_process->GetTabManager();
DCHECK(tab_manager);
PopulatePageTransitionMetrics(&entry, tab_metrics.page_transition); PopulatePageTransitionMetrics(&entry, tab_metrics.page_transition);
entry entry
.SetHasBeforeUnloadHandler( .SetHasBeforeUnloadHandler(
...@@ -247,9 +243,10 @@ void TabMetricsLogger::LogBackgroundTab(ukm::SourceId ukm_source_id, ...@@ -247,9 +243,10 @@ void TabMetricsLogger::LogBackgroundTab(ukm::SourceId ukm_source_id,
blink::kBeforeUnloadHandler)) blink::kBeforeUnloadHandler))
.SetHasFormEntry( .SetHasFormEntry(
web_contents->GetPageImportanceSignals().had_form_interaction) web_contents->GetPageImportanceSignals().had_form_interaction)
// TODO(michaelpg): This dependency should be reversed during the .SetIsExtensionProtected(
// resource_coordinator refactor: https://crbug.com/775644. !resource_coordinator::TabLifecycleUnitExternal::FromWebContents(
.SetIsExtensionProtected(!tab_manager->IsTabAutoDiscardable(web_contents)) web_contents)
->IsAutoDiscardable())
.SetIsPinned(tab_strip_model->IsTabPinned(index)) .SetIsPinned(tab_strip_model->IsTabPinned(index))
.SetNavigationEntryCount(web_contents->GetController().GetEntryCount()) .SetNavigationEntryCount(web_contents->GetController().GetEntryCount())
.SetSequenceId(++sequence_id_) .SetSequenceId(++sequence_id_)
......
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