Commit eada5782 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Stop reading the "AllowMultipleDiscards" param of the "AutomaticTabDiscarding" field trial.

The "AutomaticTabDiscarding" field trial has expired. Not having
to read the "AllowMultipleDiscards" param of this field trial will
simplify the TabManager refactor.

Bug: 775644
Change-Id: Idaded6bbc74c8ceb02379d5b7ddf43715b552a6e
Reviewed-on: https://chromium-review.googlesource.com/772090
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517502}
parent 7bdc27ac
......@@ -219,7 +219,6 @@ constexpr base::TimeDelta TabManager::kDefaultMinTimeToPurge;
TabManager::TabManager()
: discard_count_(0),
discard_once_(false),
#if !defined(OS_CHROMEOS)
minimum_protection_time_(base::TimeDelta::FromMinutes(10)),
#endif
......@@ -257,9 +256,6 @@ void TabManager::Start() {
return;
#endif
// Check if only one discard is allowed.
discard_once_ = CanOnlyDiscardOnce();
if (!update_timer_.IsRunning()) {
update_timer_.Start(FROM_HERE,
TimeDelta::FromSeconds(kAdjustmentIntervalSeconds),
......@@ -392,9 +388,11 @@ bool TabManager::CanDiscardTab(const TabStats& tab_stats) const {
if (web_contents->GetContentsMimeType() == "application/pdf")
return false;
// Do not discard a previously discarded tab if that's the desired behavior.
if (discard_once_ && GetWebContentsData(web_contents)->DiscardCount() > 0)
// Do not discard a previously discarded tab on non-ChromeOS platforms.
#if !defined(OS_CHROMEOS)
if (GetWebContentsData(web_contents)->DiscardCount() > 0)
return false;
#endif // !defined(OS_CHROMEOS)
// Do not discard a recently used tab.
if (minimum_protection_time_.InSeconds() > 0) {
......@@ -1050,23 +1048,6 @@ content::WebContents* TabManager::DiscardTabImpl(DiscardCondition condition) {
return nullptr;
}
// Check the variation parameter to see if a tab can be discarded only once or
// multiple times.
// Default is to only discard once per tab.
bool TabManager::CanOnlyDiscardOnce() const {
#if defined(OS_WIN) || defined(OS_MACOSX)
// On Windows and MacOS, default to discarding only once unless otherwise
// specified by the variation parameter.
// TODO(georgesak): Add Linux when automatic discarding is enabled for that
// platform.
std::string allow_multiple_discards = variations::GetVariationParamValue(
features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards");
return (allow_multiple_discards != "true");
#else
return false;
#endif
}
bool TabManager::IsActiveWebContentsInActiveBrowser(
content::WebContents* contents) const {
auto browser_info_list = GetBrowserInfoList();
......
......@@ -402,9 +402,6 @@ class TabManager : public TabStripModelObserver,
// Otherwise returns the new web_contents of the discarded tab.
content::WebContents* DiscardTabImpl(DiscardCondition condition);
// Returns true if tabs can be discarded only once.
bool CanOnlyDiscardOnce() const;
// Returns true if |web_contents| is the active WebContents in the last active
// Browser.
bool IsActiveWebContentsInActiveBrowser(content::WebContents* contents) const;
......@@ -493,9 +490,6 @@ class TabManager : public TabStripModelObserver,
// Number of times a tab has been discarded, for statistics.
int discard_count_;
// Whether a tab can only ever discarded once.
bool discard_once_;
// This allows protecting tabs for a certain amount of time after being
// backgrounded.
base::TimeDelta minimum_protection_time_;
......
......@@ -525,61 +525,6 @@ TEST_F(TabManagerTest, DiscardedTabKeepsLastActiveTime) {
EXPECT_TRUE(tabstrip.empty());
}
// Test to see if a tab can only be discarded once. On Windows and Mac, this
// defaults to true unless overridden through a variation parameter. On other
// platforms, it's always false.
#if defined(OS_WIN) || defined(OS_MACOSX)
TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
TabManager tab_manager;
const std::string kTrialName = features::kAutomaticTabDiscarding.name;
// Not setting the variation parameter.
{
bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
EXPECT_TRUE(discard_once_value);
}
// Setting the variation parameter to true.
{
std::unique_ptr<base::FieldTrialList> field_trial_list_;
field_trial_list_.reset(new base::FieldTrialList(
base::MakeUnique<base::MockEntropyProvider>()));
variations::testing::ClearAllVariationParams();
std::map<std::string, std::string> params;
params["AllowMultipleDiscards"] = "true";
ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "A", params));
base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
EXPECT_FALSE(discard_once_value);
}
// Setting the variation parameter to something else.
{
std::unique_ptr<base::FieldTrialList> field_trial_list_;
field_trial_list_.reset(new base::FieldTrialList(
base::MakeUnique<base::MockEntropyProvider>()));
variations::testing::ClearAllVariationParams();
std::map<std::string, std::string> params;
params["AllowMultipleDiscards"] = "somethingElse";
ASSERT_TRUE(variations::AssociateVariationParams(kTrialName, "B", params));
base::FieldTrialList::CreateFieldTrial(kTrialName, "B");
bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
EXPECT_TRUE(discard_once_value);
}
}
#else
TEST_F(TabManagerTest, CanOnlyDiscardOnce) {
TabManager tab_manager;
bool discard_once_value = tab_manager.CanOnlyDiscardOnce();
EXPECT_FALSE(discard_once_value);
}
#endif // defined(OS_WIN) || defined(OS_MACOSX)
TEST_F(TabManagerTest, DefaultTimeToPurgeInCorrectRange) {
TabManager tab_manager;
base::TimeDelta time_to_purge =
......
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