OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.physicalweb; | 5 package org.chromium.chrome.browser.physicalweb; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.AsyncTask; | 8 import android.os.AsyncTask; |
9 import android.text.TextUtils; | |
9 | 10 |
10 import org.chromium.base.CommandLine; | 11 import org.chromium.base.CommandLine; |
11 import org.chromium.chrome.browser.ChromeApplication; | 12 import org.chromium.chrome.browser.ChromeApplication; |
12 import org.chromium.chrome.browser.ChromeSwitches; | 13 import org.chromium.chrome.browser.ChromeSwitches; |
13 import org.chromium.chrome.browser.ChromeVersionInfo; | 14 import org.chromium.chrome.browser.ChromeVersionInfo; |
15 import org.chromium.components.variations.VariationsAssociatedData; | |
14 | 16 |
15 /** | 17 /** |
16 * This class provides the basic interface to the Physical Web feature. | 18 * This class provides the basic interface to the Physical Web feature. |
17 */ | 19 */ |
18 public class PhysicalWeb { | 20 public class PhysicalWeb { |
21 private static final String FIELD_TRIAL_NAME = "PhysicalWeb"; | |
22 private static final String ENABLED_PARAM = "enabled"; | |
23 private static final String ENABLED_VALUE = "true"; | |
24 | |
19 /** | 25 /** |
20 * Evaluate whether the environment is one in which the Physical Web should | 26 * Evaluate whether the environment is one in which the Physical Web should |
21 * be enabled. | 27 * be enabled. |
22 * @return true if the PhysicalWeb should be enabled | 28 * @return true if the PhysicalWeb should be enabled |
23 */ | 29 */ |
24 public static boolean featureIsEnabled() { | 30 public static boolean featureIsEnabled() { |
31 // TODO(cco3): Remove chrome://flag after Finch is experiment is more in place. | |
Alexei Svitkine (slow)
2015/12/16 20:11:30
"Finch" is an internal codename. Don't use it in c
| |
25 boolean allowedChannel = | 32 boolean allowedChannel = |
26 ChromeVersionInfo.isLocalBuild() || ChromeVersionInfo.isDevBuild (); | 33 ChromeVersionInfo.isLocalBuild() || ChromeVersionInfo.isDevBuild (); |
27 boolean switchEnabled = | 34 boolean switchEnabled = |
28 CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_PHYSIC AL_WEB); | 35 CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_PHYSIC AL_WEB); |
Alexei Svitkine (slow)
2015/12/16 20:11:30
You should also have a disable switch, so that if
| |
29 return allowedChannel && switchEnabled; | 36 // Check chrome://flag, command line flag, and finch, in that order |
37 return (allowedChannel && switchEnabled) || getBooleanParam(ENABLED_PARA M, false); | |
Alexei Svitkine (slow)
2015/12/16 20:11:30
The current logic won't integrate well with go/var
| |
30 } | 38 } |
31 | 39 |
32 /** | 40 /** |
33 * Start the Physical Web feature. | 41 * Start the Physical Web feature. |
34 * At the moment, this only enables URL discovery over BLE. | 42 * At the moment, this only enables URL discovery over BLE. |
35 * @param application An instance of {@link ChromeApplication}, used to get the | 43 * @param application An instance of {@link ChromeApplication}, used to get the |
36 * appropriate PhysicalWebBleClient implementation. | 44 * appropriate PhysicalWebBleClient implementation. |
37 */ | 45 */ |
38 public static void startPhysicalWeb(ChromeApplication application) { | 46 public static void startPhysicalWeb(ChromeApplication application) { |
39 PhysicalWebBleClient physicalWebBleClient = PhysicalWebBleClient.getInst ance(application); | 47 PhysicalWebBleClient physicalWebBleClient = PhysicalWebBleClient.getInst ance(application); |
(...skipping 23 matching lines...) Expand all Loading... | |
63 | 71 |
64 private static void clearUrlsAsync(final Context context) { | 72 private static void clearUrlsAsync(final Context context) { |
65 Runnable task = new Runnable() { | 73 Runnable task = new Runnable() { |
66 @Override | 74 @Override |
67 public void run() { | 75 public void run() { |
68 UrlManager.getInstance(context).clearUrls(); | 76 UrlManager.getInstance(context).clearUrls(); |
69 } | 77 } |
70 }; | 78 }; |
71 AsyncTask.THREAD_POOL_EXECUTOR.execute(task); | 79 AsyncTask.THREAD_POOL_EXECUTOR.execute(task); |
72 } | 80 } |
81 | |
82 /** | |
83 * Gets a boolean Finch parameter, assuming the <paramName>="true" format. Also checks for a | |
84 * command-line switch with the same name, for easy local testing. | |
nyquist
2015/12/17 02:02:23
Couldn't you force the trial through a command lin
| |
85 * @param paramName The name of the Finch parameter (or command-line switch) to get a value for. | |
86 * @param defaultValue The default value to return when there's no param or switch. | |
87 * @return Whether the Finch param is defined with a value "true", if there' s a command-line | |
88 * flag present with any value. | |
89 */ | |
90 private static boolean getBooleanParam(String paramName, boolean defaultValu e) { | |
91 if (CommandLine.getInstance().hasSwitch(paramName)) { | |
92 return true; | |
93 } | |
94 String paramValue = | |
95 VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME , paramName); | |
96 if (TextUtils.isEmpty(paramValue)) { | |
97 return defaultValue; | |
98 } | |
99 return TextUtils.equals(ENABLED_VALUE, paramValue); | |
100 } | |
73 } | 101 } |
OLD | NEW |