Commit 98896435 authored by rajendrant's avatar rajendrant Committed by Commit Bot

Show infobar only for non recently enabled LiteMode users

Infobar should be shown for users who enabled LiteMode before M85
release date. The user likely saw the old help center article (or
privacy whitepaper), and does not know about https image compression.

For users who enabled LiteMode after M85, infobar need not be shown.

Bug: 1090843
Change-Id: I6df372d34d5e4309f66e9f7eb5f8467f6c972d74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2262121
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782677}
parent 4940014d
...@@ -26,8 +26,15 @@ namespace { ...@@ -26,8 +26,15 @@ namespace {
// Pref key that stores whether the user has already seen the infobar. The pref // Pref key that stores whether the user has already seen the infobar. The pref
// is initialized as false, and updated to true when LiteMode is enabled and // is initialized as false, and updated to true when LiteMode is enabled and
// infobar has been shown to user. // infobar has been shown to user.
const char kHasSeenInfoBar[] = constexpr char kHasSeenInfoBar[] =
"litemode.https-image-compression.user-has-seen-infobar"; "litemode.https-image-compression.user-has-seen-infobar";
// The time used to compare and identify recent LiteMode users. Users who
// enabled LiteMode before this time are treated as non-recent and the one-time
// https image compression InfoBar is shown for them. Set approximate as M85
// release date, which is the target for https image compression feature.
constexpr char kRecentLiteModeUserEnableTime[] = "2020-08-25T00:00:01Z";
} // namespace } // namespace
HttpsImageCompressionInfoBarDecider::HttpsImageCompressionInfoBarDecider( HttpsImageCompressionInfoBarDecider::HttpsImageCompressionInfoBarDecider(
...@@ -37,11 +44,22 @@ HttpsImageCompressionInfoBarDecider::HttpsImageCompressionInfoBarDecider( ...@@ -37,11 +44,22 @@ HttpsImageCompressionInfoBarDecider::HttpsImageCompressionInfoBarDecider(
if (!pref_service_ || !drp_settings) if (!pref_service_ || !drp_settings)
return; return;
// The infobar only needs to be shown if the user has never seen it before, // The infobar only needs to be shown if the user has never seen it before,
// and is an existing Data Saver user. // is an existing LiteMode user, and did not recently enable LiteMode.
need_to_show_infobar_ = need_to_show_infobar_ =
base::FeatureList::IsEnabled(blink::features::kSubresourceRedirect) && base::FeatureList::IsEnabled(blink::features::kSubresourceRedirect) &&
drp_settings->IsDataReductionProxyEnabled() && drp_settings->IsDataReductionProxyEnabled() &&
!pref_service_->GetBoolean(kHasSeenInfoBar); !pref_service_->GetBoolean(kHasSeenInfoBar);
if (need_to_show_infobar_) {
const auto last_enabled_time = drp_settings->GetLastEnabledTime();
if (!last_enabled_time.is_null()) {
base::Time recent_lite_mode_user_enable_time;
bool success = base::Time::FromUTCString(
kRecentLiteModeUserEnableTime, &recent_lite_mode_user_enable_time);
DCHECK(success);
need_to_show_infobar_ =
last_enabled_time < recent_lite_mode_user_enable_time;
}
}
} }
// static // static
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/browser/data_store_impl.h" #include "components/data_reduction_proxy/core/browser/data_store_impl.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -63,6 +65,15 @@ class HttpsImageCompressionInfoBarDeciderPrefTest ...@@ -63,6 +65,15 @@ class HttpsImageCompressionInfoBarDeciderPrefTest
return decider_.get(); return decider_.get();
} }
// Sets the last enabled time of LiteMode in prefs.
void SetLiteModeLastEnableDate(const char* enabled_time) {
base::Time time;
EXPECT_TRUE(base::Time::FromUTCString(enabled_time, &time));
profile()->GetPrefs()->SetInt64(
data_reduction_proxy::prefs::kDataReductionProxyLastEnabledTime,
time.ToInternalValue());
}
private: private:
std::unique_ptr<HttpsImageCompressionInfoBarDecider> decider_; std::unique_ptr<HttpsImageCompressionInfoBarDecider> decider_;
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
...@@ -117,3 +128,28 @@ TEST_F(HttpsImageCompressionInfoBarDeciderPrefTest, TestDRPEnabledThenNotify) { ...@@ -117,3 +128,28 @@ TEST_F(HttpsImageCompressionInfoBarDeciderPrefTest, TestDRPEnabledThenNotify) {
EXPECT_FALSE(decider->NeedToShowInfoBar()); EXPECT_FALSE(decider->NeedToShowInfoBar());
} }
TEST_F(HttpsImageCompressionInfoBarDeciderPrefTest, TestRecentLiteModeUser) {
SetLiteModeLastEnableDate("2020-12-01T00:00:01Z");
HttpsImageCompressionInfoBarDecider* decider = GetDeciderWithDRPEnabled(true);
EXPECT_FALSE(decider->NeedToShowInfoBar());
content::WebContentsTester::For(web_contents())
->NavigateAndCommit(GURL(kTestUrl));
// Should still be false after a navigation.
EXPECT_FALSE(decider->NeedToShowInfoBar());
}
TEST_F(HttpsImageCompressionInfoBarDeciderPrefTest, TestNonRecentLiteModeUser) {
HttpsImageCompressionInfoBarDecider* decider = GetDeciderWithDRPEnabled(true);
SetLiteModeLastEnableDate("2020-01-01T00:00:01Z");
EXPECT_TRUE(decider->NeedToShowInfoBar());
decider->SetUserHasSeenInfoBar();
EXPECT_FALSE(decider->NeedToShowInfoBar());
content::WebContentsTester::For(web_contents())
->NavigateAndCommit(GURL(kTestUrl));
EXPECT_FALSE(decider->NeedToShowInfoBar());
}
...@@ -205,6 +205,15 @@ PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() const { ...@@ -205,6 +205,15 @@ PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() const {
return prefs_; return prefs_;
} }
base::Time DataReductionProxySettings::GetLastEnabledTime() const {
PrefService* prefs = GetOriginalProfilePrefs();
int64_t last_enabled_time =
prefs->GetInt64(prefs::kDataReductionProxyLastEnabledTime);
if (last_enabled_time <= 0)
return base::Time();
return base::Time::FromInternalValue(last_enabled_time);
}
void DataReductionProxySettings::RegisterDataReductionProxyFieldTrial() { void DataReductionProxySettings::RegisterDataReductionProxyFieldTrial() {
register_synthetic_field_trial_.Run( register_synthetic_field_trial_.Run(
"SyntheticDataReductionProxySetting", "SyntheticDataReductionProxySetting",
...@@ -242,15 +251,12 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy( ...@@ -242,15 +251,12 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy(
bool enabled = IsDataSaverEnabledByUser(is_off_the_record_profile_, prefs); bool enabled = IsDataSaverEnabledByUser(is_off_the_record_profile_, prefs);
if (enabled && at_startup) { if (enabled && at_startup) {
// Record the number of days since data reduction proxy has been enabled. const auto last_enabled_time = GetLastEnabledTime();
int64_t last_enabled_time = if (!last_enabled_time.is_null()) {
prefs->GetInt64(prefs::kDataReductionProxyLastEnabledTime);
if (last_enabled_time != 0) {
// Record the metric only if the time when data reduction proxy was // Record the metric only if the time when data reduction proxy was
// enabled is available. // enabled is available.
RecordDaysSinceEnabledMetric( RecordDaysSinceEnabledMetric(
(clock_->Now() - base::Time::FromInternalValue(last_enabled_time)) (clock_->Now() - last_enabled_time).InDays());
.InDays());
} }
} }
......
...@@ -179,6 +179,11 @@ class DataReductionProxySettings { ...@@ -179,6 +179,11 @@ class DataReductionProxySettings {
// Returns the list of hosts for the prefetch proxy. // Returns the list of hosts for the prefetch proxy.
const std::vector<GURL>& GetPrefetchProxies() const; const std::vector<GURL>& GetPrefetchProxies() const;
// Returns the time LiteMode was last enabled. This is reset whenever LiteMode
// is disabled and re-enabled from settings. Null time is returned when
// LiteMode has never been enabled.
base::Time GetLastEnabledTime() const;
// Adds an observer that is notified every time the proxy request headers // Adds an observer that is notified every time the proxy request headers
// change. // change.
void AddDataReductionProxySettingsObserver( void AddDataReductionProxySettingsObserver(
......
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