| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.util; | 5 package org.chromium.chrome.browser.util; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 */ | 147 */ |
| 148 public static void setIsInMultiWindowMode(boolean isInMultiWindowMode) { | 148 public static void setIsInMultiWindowMode(boolean isInMultiWindowMode) { |
| 149 nativeSetIsInMultiWindowMode(isInMultiWindowMode); | 149 nativeSetIsInMultiWindowMode(isInMultiWindowMode); |
| 150 } | 150 } |
| 151 | 151 |
| 152 private static boolean isHerbDisallowed(Context context) { | 152 private static boolean isHerbDisallowed(Context context) { |
| 153 return isDocumentMode(context); | 153 return isDocumentMode(context); |
| 154 } | 154 } |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * @return Which flavor of Herb is being tested. See {@link ChromeSwitches#
HERB_FLAVOR_ANISE} | 157 * @return Which flavor of Herb is being tested. |
| 158 * and its related switches. | 158 * See {@link ChromeSwitches#HERB_FLAVOR_ELDERBERRY} and its related
switches. |
| 159 */ | 159 */ |
| 160 public static String getHerbFlavor() { | 160 public static String getHerbFlavor() { |
| 161 Context context = ContextUtils.getApplicationContext(); | 161 Context context = ContextUtils.getApplicationContext(); |
| 162 if (isHerbDisallowed(context)) return ChromeSwitches.HERB_FLAVOR_DISABLE
D; | 162 if (isHerbDisallowed(context)) return ChromeSwitches.HERB_FLAVOR_DISABLE
D; |
| 163 | 163 |
| 164 if (!sIsHerbFlavorCached) { | 164 if (!sIsHerbFlavorCached) { |
| 165 sCachedHerbFlavor = null; | 165 sCachedHerbFlavor = null; |
| 166 | 166 |
| 167 // Allowing disk access for preferences while prototyping. | 167 // Allowing disk access for preferences while prototyping. |
| 168 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); | 168 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 196 private static void cacheHerbFlavor() { | 196 private static void cacheHerbFlavor() { |
| 197 Context context = ContextUtils.getApplicationContext(); | 197 Context context = ContextUtils.getApplicationContext(); |
| 198 if (isHerbDisallowed(context)) return; | 198 if (isHerbDisallowed(context)) return; |
| 199 | 199 |
| 200 String oldFlavor = getHerbFlavor(); | 200 String oldFlavor = getHerbFlavor(); |
| 201 | 201 |
| 202 // Check the experiment value before the command line to put the user in
the correct group. | 202 // Check the experiment value before the command line to put the user in
the correct group. |
| 203 // The first clause does the null checks so so we can freely use the sta
rtsWith() function. | 203 // The first clause does the null checks so so we can freely use the sta
rtsWith() function. |
| 204 String newFlavor = FieldTrialList.findFullName(HERB_EXPERIMENT_NAME); | 204 String newFlavor = FieldTrialList.findFullName(HERB_EXPERIMENT_NAME); |
| 205 Log.d(TAG, "Experiment flavor: " + newFlavor); | 205 Log.d(TAG, "Experiment flavor: " + newFlavor); |
| 206 if (TextUtils.isEmpty(newFlavor) | 206 if (!TextUtils.isEmpty(newFlavor) |
| 207 || newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_CONTROL) | 207 && newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_ELDERBERRY))
{ |
| 208 || newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_DEFAULT)) { | 208 newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY; |
| 209 } else { |
| 209 newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED; | 210 newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED; |
| 210 } else if (newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_ANISE)) { | |
| 211 newFlavor = ChromeSwitches.HERB_FLAVOR_ANISE; | |
| 212 } else if (newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_BASIL)) { | |
| 213 newFlavor = ChromeSwitches.HERB_FLAVOR_BASIL; | |
| 214 } else if (newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_CHIVE)) { | |
| 215 newFlavor = ChromeSwitches.HERB_FLAVOR_CHIVE; | |
| 216 } else if (newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_DILL)) { | |
| 217 newFlavor = ChromeSwitches.HERB_FLAVOR_DILL; | |
| 218 } else if (newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_ELDERBERRY))
{ | |
| 219 newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY; | |
| 220 } | 211 } |
| 221 | 212 |
| 222 CommandLine instance = CommandLine.getInstance(); | 213 CommandLine instance = CommandLine.getInstance(); |
| 223 if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH)) { | 214 if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH)) { |
| 224 newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED; | 215 newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED; |
| 225 } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_ANISE_SWITCH))
{ | |
| 226 newFlavor = ChromeSwitches.HERB_FLAVOR_ANISE; | |
| 227 } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_BASIL_SWITCH))
{ | |
| 228 newFlavor = ChromeSwitches.HERB_FLAVOR_BASIL; | |
| 229 } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_CHIVE_SWITCH))
{ | |
| 230 newFlavor = ChromeSwitches.HERB_FLAVOR_CHIVE; | |
| 231 } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_DILL_SWITCH)) { | |
| 232 newFlavor = ChromeSwitches.HERB_FLAVOR_DILL; | |
| 233 } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_ELDERBERRY_SWIT
CH)) { | 216 } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_ELDERBERRY_SWIT
CH)) { |
| 234 newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY; | 217 newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY; |
| 235 } | 218 } |
| 236 | 219 |
| 237 Log.d(TAG, "Caching flavor: " + newFlavor); | 220 Log.d(TAG, "Caching flavor: " + newFlavor); |
| 238 sCachedHerbFlavor = newFlavor; | 221 sCachedHerbFlavor = newFlavor; |
| 239 | 222 |
| 240 if (!TextUtils.equals(oldFlavor, newFlavor)) { | 223 if (!TextUtils.equals(oldFlavor, newFlavor)) { |
| 241 ChromePreferenceManager.getInstance(context).setCachedHerbFlavor(new
Flavor); | 224 ChromePreferenceManager.getInstance(context).setCachedHerbFlavor(new
Flavor); |
| 242 } | 225 } |
| 243 } | 226 } |
| 244 | 227 |
| 245 /** | 228 /** |
| 246 * @return True if tab model merging for Android N+ is enabled. | 229 * @return True if tab model merging for Android N+ is enabled. |
| 247 */ | 230 */ |
| 248 public static boolean isTabModelMergingEnabled() { | 231 public static boolean isTabModelMergingEnabled() { |
| 249 return Build.VERSION.SDK_INT > Build.VERSION_CODES.M; | 232 return Build.VERSION.SDK_INT > Build.VERSION_CODES.M; |
| 250 } | 233 } |
| 251 | 234 |
| 252 private static native void nativeSetCustomTabVisible(boolean visible); | 235 private static native void nativeSetCustomTabVisible(boolean visible); |
| 253 private static native void nativeSetIsInMultiWindowMode(boolean isInMultiWin
dowMode); | 236 private static native void nativeSetIsInMultiWindowMode(boolean isInMultiWin
dowMode); |
| 254 } | 237 } |
| OLD | NEW |