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

Download later: Add a prompt status pref.

The prompt status pref for download later dialog is similar to the
prompt status used in the download location dialog. The checkbox and
the setting UX spec is the same as well.

Bug: 1078454
Change-Id: Ibaea0c63782b8fb4e33fc1336c862a015c9d219a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2236213Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776200}
parent ebd406c6
...@@ -254,6 +254,22 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller { ...@@ -254,6 +254,22 @@ public class DownloadDialogBridge implements ModalDialogProperties.Controller {
PrefServiceBridge.getInstance().setInteger(Pref.PROMPT_FOR_DOWNLOAD_ANDROID, status); PrefServiceBridge.getInstance().setInteger(Pref.PROMPT_FOR_DOWNLOAD_ANDROID, status);
} }
/**
* @return The prompt status for download later dialog.
*/
@DownloadLaterPromptStatus
public static int getDownloadLaterPromptStatus() {
return PrefServiceBridge.getInstance().getInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS);
}
/**
* Sets the prompt status for download later dialog.
* @param status New status to update the download later prmopt status.
*/
public static void setDownloadLaterPromptStatus(@DownloadLaterPromptStatus int status) {
PrefServiceBridge.getInstance().setInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS, status);
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
void onComplete(long nativeDownloadDialogBridge, DownloadDialogBridge caller, void onComplete(long nativeDownloadDialogBridge, DownloadDialogBridge caller,
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/download/public/common/download_features.h"
#include "components/download/public/common/download_item.h" #include "components/download/public/common/download_item.h"
#include "components/policy/core/browser/url_blacklist_manager.h" #include "components/policy/core/browser/url_blacklist_manager.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
...@@ -303,6 +304,14 @@ void DownloadPrefs::RegisterProfilePrefs( ...@@ -303,6 +304,14 @@ void DownloadPrefs::RegisterProfilePrefs(
prefs::kPromptForDownloadAndroid, prefs::kPromptForDownloadAndroid,
static_cast<int>(download_prompt_status), static_cast<int>(download_prompt_status),
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
if (base::FeatureList::IsEnabled(download::features::kDownloadLater)) {
registry->RegisterIntegerPref(
prefs::kDownloadLaterPromptStatus,
static_cast<int>(DownloadLaterPromptStatus::SHOW_INITIAL),
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
}
registry->RegisterBooleanPref( registry->RegisterBooleanPref(
prefs::kShowMissingSdCardErrorAndroid, prefs::kShowMissingSdCardErrorAndroid,
base::FeatureList::IsEnabled(features::kDownloadsLocationChange)); base::FeatureList::IsEnabled(features::kDownloadsLocationChange));
......
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/download/download_prompt_status.h" #include "chrome/browser/download/download_prompt_status.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/download/public/common/download_features.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
#include "components/safe_browsing/core/file_type_policies.h" #include "components/safe_browsing/core/file_type_policies.h"
...@@ -40,18 +42,29 @@ TEST(DownloadPrefsTest, RegisterPrefs) { ...@@ -40,18 +42,29 @@ TEST(DownloadPrefsTest, RegisterPrefs) {
content::BrowserTaskEnvironment task_environment_; content::BrowserTaskEnvironment task_environment_;
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
#ifdef OS_ANDROID
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(download::features::kDownloadLater);
#endif // OS_ANDROID
// Download prefs are registered when creating the profile. // Download prefs are registered when creating the profile.
TestingProfile profile; TestingProfile profile;
DownloadPrefs prefs(&profile); DownloadPrefs prefs(&profile);
#ifdef OS_ANDROID #ifdef OS_ANDROID
// Download prompt pref should be registered correctly. // Download prompt prefs should be registered correctly.
histogram_tester.ExpectBucketCount("MobileDownload.DownloadPromptStatus", histogram_tester.ExpectBucketCount("MobileDownload.DownloadPromptStatus",
DownloadPromptStatus::SHOW_INITIAL, 1); DownloadPromptStatus::SHOW_INITIAL, 1);
int prompt_status = profile.GetTestingPrefService()->GetInteger( int prompt_status = profile.GetTestingPrefService()->GetInteger(
prefs::kPromptForDownloadAndroid); prefs::kPromptForDownloadAndroid);
EXPECT_EQ(prompt_status, EXPECT_EQ(prompt_status,
static_cast<int>(DownloadPromptStatus::SHOW_INITIAL)); static_cast<int>(DownloadPromptStatus::SHOW_INITIAL));
int download_later_prompt_status =
profile.GetTestingPrefService()->GetInteger(
prefs::kDownloadLaterPromptStatus);
EXPECT_EQ(download_later_prompt_status,
static_cast<int>(DownloadLaterPromptStatus::SHOW_INITIAL));
#endif // OS_ANDROID #endif // OS_ANDROID
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROMPT_STATUS_H_ #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROMPT_STATUS_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROMPT_STATUS_H_ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROMPT_STATUS_H_
// The status of the download prompt. // The status of the download location prompt.
// A Java counterpart will be generated for this enum. // A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.download // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.download
enum class DownloadPromptStatus { enum class DownloadPromptStatus {
...@@ -15,4 +15,14 @@ enum class DownloadPromptStatus { ...@@ -15,4 +15,14 @@ enum class DownloadPromptStatus {
MAX_VALUE MAX_VALUE
}; };
// The status of the download later prompt.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.download
enum class DownloadLaterPromptStatus {
SHOW_INITIAL, // Show the prompt because it hasn't been shown before.
SHOW_PREFERENCE, // Show the prompt because user indicated preference.
DONT_SHOW, // Don't show the prompt because user indicated preference.
MAX_VALUE
};
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROMPT_STATUS_H_ #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROMPT_STATUS_H_
...@@ -1662,6 +1662,10 @@ const char kOpenPdfDownloadInSystemReader[] = ...@@ -1662,6 +1662,10 @@ const char kOpenPdfDownloadInSystemReader[] =
// ask the user where they want to download the file (only for Android). // ask the user where they want to download the file (only for Android).
const char kPromptForDownloadAndroid[] = "download.prompt_for_download_android"; const char kPromptForDownloadAndroid[] = "download.prompt_for_download_android";
// The prompt status for the download later dialog.
const char kDownloadLaterPromptStatus[] =
"download.download_later_prompt_status";
// Boolean which specifies whether we should display the missing SD card error. // Boolean which specifies whether we should display the missing SD card error.
// This is only applicable for Android. // This is only applicable for Android.
const char kShowMissingSdCardErrorAndroid[] = const char kShowMissingSdCardErrorAndroid[] =
......
...@@ -555,6 +555,7 @@ extern const char kOpenPdfDownloadInSystemReader[]; ...@@ -555,6 +555,7 @@ extern const char kOpenPdfDownloadInSystemReader[];
#endif #endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
extern const char kPromptForDownloadAndroid[]; extern const char kPromptForDownloadAndroid[];
extern const char kDownloadLaterPromptStatus[];
extern const char kShowMissingSdCardErrorAndroid[]; extern const char kShowMissingSdCardErrorAndroid[];
#endif #endif
......
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