Commit 1cd76c6d authored by Xinghui Lu's avatar Xinghui Lu Committed by Commit Bot

[Android] Add memory upper threshold control for real time URL lookup.

In order to control real time URL lookup via high-end and low-end
groups, add a memory upper threshold control.

This change will make it easier for finch configuration, see:
go/wmpfd

Bug: 1014202
Change-Id: I639153c9baac73cd8bfcdaff3a82c020237a6c4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2092697
Commit-Queue: Varun Khaneja <vakh@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748468}
parent d479873f
......@@ -26,7 +26,9 @@
namespace safe_browsing {
#if defined(OS_ANDROID)
const int kDefaultMemoryThresholdMb = 4096;
const int kDefaultMemoryLowerThresholdMb = 4096;
// By default, the upper threshold shouldn't be in effect.
const int kDefaultMemoryUpperThresholdMb = INT_MAX;
#endif
// static
......@@ -35,12 +37,17 @@ bool RealTimePolicyEngine::IsUrlLookupEnabled() {
return false;
#if defined(OS_ANDROID)
// On Android, performs real time URL lookup only if
// |kRealTimeUrlLookupEnabled| is enabled, and system memory is larger than
// threshold.
int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
kRealTimeUrlLookupEnabled, kRealTimeUrlLookupMemoryThresholdMb,
kDefaultMemoryThresholdMb);
return base::SysInfo::AmountOfPhysicalMemoryMB() >= memory_threshold_mb;
// |kRealTimeUrlLookupEnabled| is enabled, and system memory is between the
// upper threshold and lower threshold.
int memory_lower_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
kRealTimeUrlLookupEnabled, kRealTimeUrlLookupMemoryLowerThresholdMb,
kDefaultMemoryLowerThresholdMb);
int memory_upper_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
kRealTimeUrlLookupEnabled, kRealTimeUrlLookupMemoryUpperThresholdMb,
kDefaultMemoryUpperThresholdMb);
return base::SysInfo::AmountOfPhysicalMemoryMB() >=
memory_lower_threshold_mb &&
base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_upper_threshold_mb;
#else
return true;
#endif
......
......@@ -20,9 +20,12 @@ enum class ResourceType;
#if defined(OS_ANDROID)
// A parameter controlled by finch experiment.
// On Android, performs real time URL lookup only if |kRealTimeUrlLookupEnabled|
// is enabled, and system memory is larger than threshold.
const char kRealTimeUrlLookupMemoryThresholdMb[] =
// is enabled, and system memory is between the upper threshold and the lower
// threshold.
const char kRealTimeUrlLookupMemoryLowerThresholdMb[] =
"SafeBrowsingRealTimeUrlLookupMemoryThresholdMb";
const char kRealTimeUrlLookupMemoryUpperThresholdMb[] =
"SafeBrowsingRealTimeUrlLookupMemoryUpperThresholdMb";
#endif
// This class implements the logic to decide whether the real time lookup
......
......@@ -59,12 +59,12 @@ class RealTimePolicyEngineTest : public PlatformTest {
TEST_F(RealTimePolicyEngineTest, TestCanPerformFullURLLookup_LargeMemorySize) {
base::test::ScopedFeatureList feature_list;
int system_memory_size = base::SysInfo::AmountOfPhysicalMemoryMB();
int memory_size_threshold = system_memory_size - 1;
int memory_size_lower_threshold = system_memory_size - 1;
feature_list.InitWithFeaturesAndParameters(
/* enabled_features */ {{kRealTimeUrlLookupEnabled,
{{kRealTimeUrlLookupMemoryThresholdMb,
{{kRealTimeUrlLookupMemoryLowerThresholdMb,
base::NumberToString(
memory_size_threshold)}}}},
memory_size_lower_threshold)}}}},
/* disabled_features */ {});
pref_service_.SetUserPref(
unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
......@@ -72,15 +72,32 @@ TEST_F(RealTimePolicyEngineTest, TestCanPerformFullURLLookup_LargeMemorySize) {
EXPECT_TRUE(CanPerformFullURLLookup(/* is_off_the_record */ false));
}
TEST_F(RealTimePolicyEngineTest,
TestCanPerformFullURLLookup_LargeMemorySizeExceedUpperThreshold) {
base::test::ScopedFeatureList feature_list;
int system_memory_size = base::SysInfo::AmountOfPhysicalMemoryMB();
int memory_size_upper_threshold = system_memory_size - 1;
feature_list.InitWithFeaturesAndParameters(
/* enabled_features */ {{kRealTimeUrlLookupEnabled,
{{kRealTimeUrlLookupMemoryUpperThresholdMb,
base::NumberToString(
memory_size_upper_threshold)}}}},
/* disabled_features */ {});
pref_service_.SetUserPref(
unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
std::make_unique<base::Value>(true));
EXPECT_FALSE(CanPerformFullURLLookup(/* is_off_the_record */ false));
}
TEST_F(RealTimePolicyEngineTest, TestCanPerformFullURLLookup_SmallMemorySize) {
base::test::ScopedFeatureList feature_list;
int system_memory_size = base::SysInfo::AmountOfPhysicalMemoryMB();
int memory_size_threshold = system_memory_size + 1;
int memory_size_lower_threshold = system_memory_size + 1;
feature_list.InitWithFeaturesAndParameters(
/* enabled_features */ {{kRealTimeUrlLookupEnabled,
{{kRealTimeUrlLookupMemoryThresholdMb,
{{kRealTimeUrlLookupMemoryLowerThresholdMb,
base::NumberToString(
memory_size_threshold)}}}},
memory_size_lower_threshold)}}}},
/* disabled_features */ {});
pref_service_.SetUserPref(
unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
......@@ -139,11 +156,12 @@ TEST_F(RealTimePolicyEngineTest,
base::test::ScopedFeatureList feature_list;
#if defined(OS_ANDROID)
int system_memory_size = base::SysInfo::AmountOfPhysicalMemoryMB();
int memory_size_threshold = system_memory_size - 1;
int memory_size_lower_threshold = system_memory_size - 1;
feature_list.InitWithFeaturesAndParameters(
/* enabled_features */ {{kRealTimeUrlLookupEnabled,
{{kRealTimeUrlLookupMemoryThresholdMb,
base::NumberToString(memory_size_threshold)}}},
{{kRealTimeUrlLookupMemoryLowerThresholdMb,
base::NumberToString(
memory_size_lower_threshold)}}},
{kRealTimeUrlLookupEnabledWithToken, {}}},
/* disabled_features */ {});
#else
......
......@@ -133,14 +133,15 @@ class RealTimeUrlLookupServiceTest : public PlatformTest {
std::make_unique<base::Value>(true));
#if defined(OS_ANDROID)
int system_memory_size = base::SysInfo::AmountOfPhysicalMemoryMB();
int memory_size_threshold = system_memory_size - 1;
int memory_size_lower_threshold = system_memory_size - 1;
if (is_with_token_enabled) {
feature_list_.InitWithFeaturesAndParameters(
/* enabled_features */ {{kRealTimeUrlLookupEnabled,
{ {
kRealTimeUrlLookupMemoryThresholdMb,
base::NumberToString(memory_size_threshold)
} }},
{
{ kRealTimeUrlLookupMemoryLowerThresholdMb,
base::NumberToString(
memory_size_lower_threshold) }
}},
{ kRealTimeUrlLookupEnabledWithToken,
{} }},
/* disabled_features */ {});
......@@ -149,8 +150,8 @@ class RealTimeUrlLookupServiceTest : public PlatformTest {
/* enabled_features */ {{
kRealTimeUrlLookupEnabled,
{
{ kRealTimeUrlLookupMemoryThresholdMb,
base::NumberToString(memory_size_threshold) }
{ kRealTimeUrlLookupMemoryLowerThresholdMb,
base::NumberToString(memory_size_lower_threshold) }
}
}},
/* disabled_features */ {});
......
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