Commit 85ac4c48 authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

Adding restrictions to Cryptid Rendering

Disables this feature for managed browsers and incognito profiles.

Change-Id: Ib17a03d0aa78971732536ff72f57e0559622f9a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161668Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762119}
parent db311e7a
......@@ -292,6 +292,7 @@ android_library("chrome_java") {
"//chrome/browser/android/thin_webview:java",
"//chrome/browser/download/android:java",
"//chrome/browser/download/android:java_resources",
"//chrome/browser/enterprise/util:java",
"//chrome/browser/flags:java",
"//chrome/browser/image_editor/public:java",
"//chrome/browser/image_fetcher:java",
......
include_rules = [
"+components/permissions/android/nfc",
"+chrome/browser/enterprise",
"+chrome/browser/flags/android",
"+chrome/browser/notifications",
"+chrome/browser/preferences/android/java",
......
......@@ -7,8 +7,10 @@ package org.chromium.chrome.browser.cryptids;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.Log;
import org.chromium.chrome.browser.enterprise.util.ManagedBrowserUtils;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
/**
* Allows for cryptids to be displayed on the New Tab Page under certain probabilistic conditions.
......@@ -22,10 +24,15 @@ public class ProbabilisticCryptidRenderer {
/**
* Determines whether cryptid should be rendered on this NTP instance, based on probability
* factors as well as variations groups.
* @param profile the current user profile. Should not be null, except in tests.
* @return true if the probability conditions are met and cryptid should be shown,
* false otherwise
*/
public boolean shouldUseCryptidRendering() {
public boolean shouldUseCryptidRendering(Profile profile) {
// Profile may be null for testing.
if (profile != null && isBlocked(profile)) {
return false;
}
// TODO: This should be disabled unless enabled by variations.
return getRandom() < calculateProbability();
}
......@@ -120,4 +127,12 @@ public class ProbabilisticCryptidRenderer {
return calculateProbability(getLastRenderTimestampMillis(), System.currentTimeMillis(),
getRenderingMoratoriumLengthMillis(), getRampUpLengthMillis(), getMaxProbability());
}
/**
* Enforces that feature is not used in blocked contexts (namely, incognito/OTR, and when
* enterprise policies are active).
*/
private boolean isBlocked(Profile profile) {
return profile.isOffTheRecord() || ManagedBrowserUtils.hasBrowserPoliciesApplied(profile);
}
}
......@@ -144,7 +144,7 @@ public class ProbabilisticCryptidRendererUnitTest {
new FakeProbabilisticCrpytidRenderer(lastRenderDeltaFromNow);
int numTrueRuns = 0;
for (int i = 0; i < NUM_RUNS; i++) {
numTrueRuns += render.shouldUseCryptidRendering() ? 1 : 0;
numTrueRuns += render.shouldUseCryptidRendering(/*profile=*/null) ? 1 : 0;
}
return numTrueRuns;
}
......
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