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 | 9 |
10 import org.chromium.base.CommandLine; | 10 import org.chromium.base.CommandLine; |
11 import org.chromium.chrome.browser.ChromeApplication; | 11 import org.chromium.chrome.browser.ChromeApplication; |
12 import org.chromium.chrome.browser.ChromeSwitches; | 12 import org.chromium.chrome.browser.ChromeSwitches; |
13 import org.chromium.chrome.browser.ChromeVersionInfo; | 13 import org.chromium.chrome.browser.ChromeVersionInfo; |
14 | 14 |
15 /** | 15 /** |
16 * This class provides the basic interface to the Physical Web feature. | 16 * This class provides the basic interface to the Physical Web feature. |
17 */ | 17 */ |
18 public class PhysicalWeb { | 18 public class PhysicalWeb { |
19 private static final String FIELD_TRIAL_NAME = "PhysicalWeb"; | |
20 private static final String ENABLED_PARAM = "enabled"; | |
21 private static final String ENABLED_VALUE = "true"; | |
22 | |
19 /** | 23 /** |
20 * Evaluate whether the environment is one in which the Physical Web should | 24 * Evaluate whether the environment is one in which the Physical Web should |
21 * be enabled. | 25 * be enabled. |
22 * @return true if the PhysicalWeb should be enabled | 26 * @return true if the PhysicalWeb should be enabled |
23 */ | 27 */ |
24 public static boolean featureIsEnabled() { | 28 public static boolean featureIsEnabled() { |
29 // TODO(cco3): Remove chrome://flag after Finch is experiment is more in place. | |
mmocny
2015/12/10 15:07:04
I thought we still want to make the chrome://flag
cco3
2015/12/11 21:32:19
That's what I thought too, but this seriously comp
| |
25 boolean allowedChannel = | 30 boolean allowedChannel = |
26 ChromeVersionInfo.isLocalBuild() || ChromeVersionInfo.isDevBuild (); | 31 ChromeVersionInfo.isLocalBuild() || ChromeVersionInfo.isDevBuild (); |
27 boolean switchEnabled = | 32 boolean switchEnabled = |
28 CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_PHYSIC AL_WEB); | 33 CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_PHYSIC AL_WEB); |
29 return allowedChannel && switchEnabled; | 34 // Check chrome://flag, command line flag, and finch, in that order |
35 return (allowedChannel && switchEnabled) || getBooleanParam(ENABLED_PARA M); | |
30 } | 36 } |
31 | 37 |
32 /** | 38 /** |
33 * Start the Physical Web feature. | 39 * Start the Physical Web feature. |
34 * At the moment, this only enables URL discovery over BLE. | 40 * At the moment, this only enables URL discovery over BLE. |
35 * @param application An instance of {@link ChromeApplication}, used to get the | 41 * @param application An instance of {@link ChromeApplication}, used to get the |
36 * appropriate PhysicalWebBleClient implementation. | 42 * appropriate PhysicalWebBleClient implementation. |
37 */ | 43 */ |
38 public static void startPhysicalWeb(ChromeApplication application) { | 44 public static void startPhysicalWeb(ChromeApplication application) { |
39 PhysicalWebBleClient physicalWebBleClient = PhysicalWebBleClient.getInst ance(application); | 45 PhysicalWebBleClient physicalWebBleClient = PhysicalWebBleClient.getInst ance(application); |
(...skipping 23 matching lines...) Expand all Loading... | |
63 | 69 |
64 private static void clearUrlsAsync(final Context context) { | 70 private static void clearUrlsAsync(final Context context) { |
65 Runnable task = new Runnable() { | 71 Runnable task = new Runnable() { |
66 @Override | 72 @Override |
67 public void run() { | 73 public void run() { |
68 UrlManager.getInstance(context).clearUrls(); | 74 UrlManager.getInstance(context).clearUrls(); |
69 } | 75 } |
70 }; | 76 }; |
71 AsyncTask.THREAD_POOL_EXECUTOR.execute(task); | 77 AsyncTask.THREAD_POOL_EXECUTOR.execute(task); |
72 } | 78 } |
79 | |
80 /** | |
81 * Gets a boolean Finch parameter, assuming the <paramName>="true" format. Also checks for a | |
82 * command-line switch with the same name, for easy local testing. | |
83 * @param paramName The name of the Finch parameter (or command-line switch) to get a value for. | |
84 * @param defaultValue The default value to return when there's no param or switch. | |
85 * @return Whether the Finch param is defined with a value "true", if there' s a command-line | |
86 * flag present with any value. | |
87 */ | |
88 private static boolean getBooleanParam(String paramName, boolean defaultValu e) { | |
nyquist
2015/12/10 00:04:06
defaultValue doesn't seem to be used? In the call
cco3
2015/12/10 01:22:54
Done.
| |
89 if (CommandLine.getInstance().hasSwitch(paramName)) { | |
90 return true; | |
91 } | |
92 return TextUtils.equals(ENABLED_VALUE, | |
93 VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME , paramName)); | |
94 } | |
73 } | 95 } |
OLD | NEW |