Commit d64a4f38 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Add a Finch param to check lite mode.

If require_lite_mode is set to true, download later dialog will show
only when lite mode(data saver) is enabled.

Bug: 1137925
Change-Id: I8655750cac482fa65cd848b4a688fe97366f634e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2469457Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818180}
parent 2c8dde79
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/download/download_core_service.h" #include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h" #include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_crx_util.h" #include "chrome/browser/download/download_crx_util.h"
...@@ -1154,11 +1156,15 @@ void ChromeDownloadManagerDelegate::OnDownloadCanceled( ...@@ -1154,11 +1156,15 @@ void ChromeDownloadManagerDelegate::OnDownloadCanceled(
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
bool ChromeDownloadManagerDelegate::ShouldShowDownloadLaterDialog() const { bool ChromeDownloadManagerDelegate::ShouldShowDownloadLaterDialog() const {
if (!base::FeatureList::IsEnabled(download::features::kDownloadLater)) if (!base::FeatureList::IsEnabled(download::features::kDownloadLater) ||
profile_->IsOffTheRecord()) {
return false; return false;
}
bool require_cellular = base::GetFieldTrialParamByFeatureAsBool( bool require_cellular = base::GetFieldTrialParamByFeatureAsBool(
download::features::kDownloadLater, download::features::kDownloadLater,
download::features::kDownloadLaterRequireCellular, true); download::features::kDownloadLaterRequireCellular,
/*default_value=*/true);
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
download::switches::kDownloadLaterDebugOnWifi)) { download::switches::kDownloadLaterDebugOnWifi)) {
require_cellular = false; require_cellular = false;
...@@ -1168,11 +1174,26 @@ bool ChromeDownloadManagerDelegate::ShouldShowDownloadLaterDialog() const { ...@@ -1168,11 +1174,26 @@ bool ChromeDownloadManagerDelegate::ShouldShowDownloadLaterDialog() const {
network::mojom::ConnectionType( network::mojom::ConnectionType(
net::NetworkChangeNotifier::GetConnectionType())); net::NetworkChangeNotifier::GetConnectionType()));
// Show download later dialog when network condition is met. // Check whether network condition is met.
if (require_cellular && !on_cellular) if (require_cellular && !on_cellular)
return false; return false;
return download_prefs_->PromptDownloadLater() && !profile_->IsOffTheRecord(); // Check lite mode if the download later prompt is never shown before.
if (!download_prefs_->HasDownloadLaterPromptShown()) {
bool require_lite_mode = base::GetFieldTrialParamByFeatureAsBool(
download::features::kDownloadLater,
download::features::kDownloadLaterRequireLiteMode,
/*default_value=*/false);
auto* data_reduction_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_);
bool lite_mode_enabled =
data_reduction_settings->IsDataReductionProxyEnabled();
if (require_lite_mode && !lite_mode_enabled)
return false;
}
return download_prefs_->PromptDownloadLater();
} }
void ChromeDownloadManagerDelegate::DetermineLocalPath( void ChromeDownloadManagerDelegate::DetermineLocalPath(
......
...@@ -414,6 +414,17 @@ bool DownloadPrefs::PromptDownloadLater() const { ...@@ -414,6 +414,17 @@ bool DownloadPrefs::PromptDownloadLater() const {
return false; return false;
} }
bool DownloadPrefs::HasDownloadLaterPromptShown() const {
#ifdef OS_ANDROID
if (base::FeatureList::IsEnabled(download::features::kDownloadLater)) {
return *prompt_for_download_later_ !=
static_cast<int>(DownloadLaterPromptStatus::kShowInitial);
}
#endif
return false;
}
bool DownloadPrefs::IsDownloadPathManaged() const { bool DownloadPrefs::IsDownloadPathManaged() const {
return download_path_.IsManaged(); return download_path_.IsManaged();
} }
......
...@@ -90,6 +90,9 @@ class DownloadPrefs { ...@@ -90,6 +90,9 @@ class DownloadPrefs {
// download time. // download time.
bool PromptDownloadLater() const; bool PromptDownloadLater() const;
// Returns whether the download later prompt is ever shown to the user.
bool HasDownloadLaterPromptShown() const;
// Returns true if the download path preference is managed. // Returns true if the download path preference is managed.
bool IsDownloadPathManaged() const; bool IsDownloadPathManaged() const;
......
...@@ -448,3 +448,30 @@ TEST(DownloadPrefsTest, DownloadDirSanitization) { ...@@ -448,3 +448,30 @@ TEST(DownloadPrefsTest, DownloadDirSanitization) {
} }
} }
#endif // OS_CHROMEOS #endif // OS_CHROMEOS
#ifdef OS_ANDROID
TEST(DownloadPrefsTest, DownloadLaterPrefs) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(download::features::kDownloadLater);
content::BrowserTaskEnvironment task_environment_;
TestingProfile profile;
DownloadPrefs prefs(&profile);
EXPECT_TRUE(prefs.PromptDownloadLater());
EXPECT_FALSE(prefs.HasDownloadLaterPromptShown());
profile.GetPrefs()->SetInteger(
prefs::kDownloadLaterPromptStatus,
static_cast<int>(DownloadLaterPromptStatus::kShowPreference));
EXPECT_TRUE(prefs.PromptDownloadLater());
EXPECT_TRUE(prefs.HasDownloadLaterPromptShown());
profile.GetPrefs()->SetInteger(
prefs::kDownloadLaterPromptStatus,
static_cast<int>(DownloadLaterPromptStatus::kDontShow));
EXPECT_FALSE(prefs.PromptDownloadLater());
EXPECT_TRUE(prefs.HasDownloadLaterPromptShown());
}
#endif // OS_ANDROID
...@@ -16,6 +16,10 @@ namespace features { ...@@ -16,6 +16,10 @@ namespace features {
// network. // network.
constexpr char kDownloadLaterRequireCellular[] = "require_cellular"; constexpr char kDownloadLaterRequireCellular[] = "require_cellular";
// The Finch parameter for download later feature to enable only in lite
// mode(data saver).
constexpr char kDownloadLaterRequireLiteMode[] = "require_lite_mode";
// Whether offline content provider should be used for the downloads UI.. // Whether offline content provider should be used for the downloads UI..
COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature
kUseDownloadOfflineContentProvider; kUseDownloadOfflineContentProvider;
......
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