Commit 4159c800 authored by cco3's avatar cco3 Committed by Commit bot
Browse files

Add a PhysicalWebIgnoreOtherClients feature

The Physical Web feature tests to see if other notification-based
Physical Web clients exist on the device before surfacing
notifications.  This feature, when enabled, will bypass that check.

BUG=616316

Review-Url: https://codereview.chromium.org/2071713002
Cr-Commit-Position: refs/heads/master@{#402329}
parent c0d8da05
...@@ -19,7 +19,9 @@ import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ...@@ -19,7 +19,9 @@ import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
public class PhysicalWeb { public class PhysicalWeb {
public static final int OPTIN_NOTIFY_MAX_TRIES = 1; public static final int OPTIN_NOTIFY_MAX_TRIES = 1;
private static final String PREF_PHYSICAL_WEB_NOTIFY_COUNT = "physical_web_notify_count"; private static final String PREF_PHYSICAL_WEB_NOTIFY_COUNT = "physical_web_notify_count";
private static final String PREF_IGNORE_OTHER_CLIENTS = "physical_web_ignore_other_clients";
private static final String FEATURE_NAME = "PhysicalWeb"; private static final String FEATURE_NAME = "PhysicalWeb";
private static final String IGNORE_OTHER_CLIENTS_FEATURE_NAME = "PhysicalWebIgnoreOtherClients";
private static final int MIN_ANDROID_VERSION = 18; private static final int MIN_ANDROID_VERSION = 18;
/** /**
...@@ -86,6 +88,15 @@ public class PhysicalWeb { ...@@ -86,6 +88,15 @@ public class PhysicalWeb {
}); });
} }
/**
* Returns true if we should fire notifications regardless of the existence of other Physical
* Web clients.
* This method is for use when the native library is not available.
*/
public static boolean shouldIgnoreOtherClients() {
return ContextUtils.getAppSharedPreferences().getBoolean(PREF_IGNORE_OTHER_CLIENTS, false);
}
/** /**
* Increments a value tracking how many times we've shown the Physical Web * Increments a value tracking how many times we've shown the Physical Web
* opt-in notification. * opt-in notification.
...@@ -121,6 +132,11 @@ public class PhysicalWeb { ...@@ -121,6 +132,11 @@ public class PhysicalWeb {
// loaded. This is always the case on chrome startup. // loaded. This is always the case on chrome startup.
if (featureIsEnabled() if (featureIsEnabled()
&& (isPhysicalWebPreferenceEnabled(application) || isOnboarding(application))) { && (isPhysicalWebPreferenceEnabled(application) || isOnboarding(application))) {
boolean ignoreOtherClients =
ChromeFeatureList.isEnabled(IGNORE_OTHER_CLIENTS_FEATURE_NAME);
ContextUtils.getAppSharedPreferences().edit()
.putBoolean(PREF_IGNORE_OTHER_CLIENTS, ignoreOtherClients)
.apply();
startPhysicalWeb(application); startPhysicalWeb(application);
PhysicalWebUma.uploadDeferredMetrics(application); PhysicalWebUma.uploadDeferredMetrics(application);
} else { } else {
......
...@@ -474,9 +474,10 @@ class UrlManager { ...@@ -474,9 +474,10 @@ class UrlManager {
private void showNotification() { private void showNotification() {
// We should only show notifications if there's no other notification-based client. // We should only show notifications if there's no other notification-based client.
if (PhysicalWebEnvironment if (!PhysicalWeb.shouldIgnoreOtherClients()
.getInstance((ChromeApplication) mContext.getApplicationContext()) && PhysicalWebEnvironment
.hasNotificationBasedClient()) { .getInstance((ChromeApplication) mContext.getApplicationContext())
.hasNotificationBasedClient()) {
return; return;
} }
......
...@@ -38,6 +38,7 @@ const base::Feature* kFeaturesExposedToJava[] = { ...@@ -38,6 +38,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&kNTPSnippetsFeature, &kNTPSnippetsFeature,
&kNTPToolbarFeature, &kNTPToolbarFeature,
&kPhysicalWebFeature, &kPhysicalWebFeature,
&kPhysicalWebIgnoreOtherClientsFeature,
&kReadItLaterInMenu, &kReadItLaterInMenu,
&kSystemDownloadManager, &kSystemDownloadManager,
&offline_pages::kOfflinePagesBackgroundLoadingFeature, &offline_pages::kOfflinePagesBackgroundLoadingFeature,
...@@ -80,6 +81,10 @@ const base::Feature kPhysicalWebFeature { ...@@ -80,6 +81,10 @@ const base::Feature kPhysicalWebFeature {
"PhysicalWeb", base::FEATURE_ENABLED_BY_DEFAULT "PhysicalWeb", base::FEATURE_ENABLED_BY_DEFAULT
}; };
const base::Feature kPhysicalWebIgnoreOtherClientsFeature {
"PhysicalWebIgnoreOtherClients", base::FEATURE_DISABLED_BY_DEFAULT
};
const base::Feature kReadItLaterInMenu { const base::Feature kReadItLaterInMenu {
"ReadItLaterInMenu", base::FEATURE_DISABLED_BY_DEFAULT "ReadItLaterInMenu", base::FEATURE_DISABLED_BY_DEFAULT
}; };
......
...@@ -21,6 +21,7 @@ extern const base::Feature kNTPSnippetsFeature; ...@@ -21,6 +21,7 @@ extern const base::Feature kNTPSnippetsFeature;
extern const base::Feature kNTPToolbarFeature; extern const base::Feature kNTPToolbarFeature;
extern const base::Feature kNTPFakeOmniboxTextFeature; extern const base::Feature kNTPFakeOmniboxTextFeature;
extern const base::Feature kPhysicalWebFeature; extern const base::Feature kPhysicalWebFeature;
extern const base::Feature kPhysicalWebIgnoreOtherClientsFeature;
extern const base::Feature kReadItLaterInMenu; extern const base::Feature kReadItLaterInMenu;
extern const base::Feature kSystemDownloadManager; extern const base::Feature kSystemDownloadManager;
......
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