Commit 49392e1b authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Move IsInitialized() to base FeatureList.

This method should not be in ChromeFeatureList and can be used by
components.

Bug: 1060097
Change-Id: I954f71fd4dc0207a7f3b90ec855e2814f733475e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2111274
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757145}
parent 3fbd3e3b
...@@ -1413,6 +1413,7 @@ jumbo_component("base") { ...@@ -1413,6 +1413,7 @@ jumbo_component("base") {
"android/early_trace_event_binding.h", "android/early_trace_event_binding.h",
"android/event_log.cc", "android/event_log.cc",
"android/event_log.h", "android/event_log.h",
"android/feature_list_jni.cc",
"android/field_trial_list.cc", "android/field_trial_list.cc",
"android/important_file_writer_android.cc", "android/important_file_writer_android.cc",
"android/int_string_callback.cc", "android/int_string_callback.cc",
...@@ -3187,6 +3188,7 @@ if (is_android) { ...@@ -3187,6 +3188,7 @@ if (is_android) {
"android/java/src/org/chromium/base/CpuFeatures.java", "android/java/src/org/chromium/base/CpuFeatures.java",
"android/java/src/org/chromium/base/EarlyTraceEvent.java", "android/java/src/org/chromium/base/EarlyTraceEvent.java",
"android/java/src/org/chromium/base/EventLog.java", "android/java/src/org/chromium/base/EventLog.java",
"android/java/src/org/chromium/base/FeatureList.java",
"android/java/src/org/chromium/base/FieldTrialList.java", "android/java/src/org/chromium/base/FieldTrialList.java",
"android/java/src/org/chromium/base/ImportantFileWriterAndroid.java", "android/java/src/org/chromium/base/ImportantFileWriterAndroid.java",
"android/java/src/org/chromium/base/IntStringCallback.java", "android/java/src/org/chromium/base/IntStringCallback.java",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/base_jni_headers/FeatureList_jni.h"
#include "base/feature_list.h"
namespace base {
namespace android {
static jboolean JNI_FeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
} // namespace android
} // namespace base
...@@ -7,11 +7,18 @@ package org.chromium.base; ...@@ -7,11 +7,18 @@ package org.chromium.base;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
import java.util.Map; import java.util.Map;
/** /**
* Provides shared capabilities for feature flag support. * Provides shared capabilities for feature flag support.
*/ */
@JNINamespace("base::android")
@MainDex
public class FeatureList { public class FeatureList {
/** Map that stores substitution feature flags for tests. */ /** Map that stores substitution feature flags for tests. */
private static @Nullable Map<String, Boolean> sTestFeatures; private static @Nullable Map<String, Boolean> sTestFeatures;
...@@ -21,6 +28,31 @@ public class FeatureList { ...@@ -21,6 +28,31 @@ public class FeatureList {
private FeatureList() {} private FeatureList() {}
/**
* @return Whether the native FeatureList has been initialized. If this method returns false,
* none of the methods in this class that require native access should be called (except
* in tests if test features have been set).
*/
public static boolean isInitialized() {
return hasTestFeatures() || isNativeInitialized();
}
/**
* @return Whether the native FeatureList is initialized or not.
*/
public static boolean isNativeInitialized() {
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return FeatureListJni.get().isInitialized();
}
/** /**
* This is called explicitly for instrumentation tests via Features#applyForInstrumentation(). * This is called explicitly for instrumentation tests via Features#applyForInstrumentation().
* Unit tests and Robolectric tests must not invoke this and should rely on the {@link Features} * Unit tests and Robolectric tests must not invoke this and should rely on the {@link Features}
...@@ -75,4 +107,9 @@ public class FeatureList { ...@@ -75,4 +107,9 @@ public class FeatureList {
} }
return null; return null;
} }
@NativeMethods
interface Natives {
boolean isInitialized();
}
} }
...@@ -607,10 +607,6 @@ const base::Feature kVrBrowsingFeedback{"VrBrowsingFeedback", ...@@ -607,10 +607,6 @@ const base::Feature kVrBrowsingFeedback{"VrBrowsingFeedback",
const base::Feature kWebApkAdaptiveIcon{"WebApkAdaptiveIcon", const base::Feature kWebApkAdaptiveIcon{"WebApkAdaptiveIcon",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
static jboolean JNI_ChromeFeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
static jboolean JNI_ChromeFeatureList_IsEnabled( static jboolean JNI_ChromeFeatureList_IsEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jstring>& jfeature_name) { const JavaParamRef<jstring>& jfeature_name) {
......
...@@ -10,7 +10,6 @@ import org.chromium.base.FeatureList; ...@@ -10,7 +10,6 @@ import org.chromium.base.FeatureList;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
import java.util.Map; import java.util.Map;
...@@ -71,25 +70,10 @@ public abstract class ChromeFeatureList { ...@@ -71,25 +70,10 @@ public abstract class ChromeFeatureList {
* none of the methods in this class that require native access should be called (except * none of the methods in this class that require native access should be called (except
* in tests if test features have been set). * in tests if test features have been set).
*/ */
// TODO(crbug.com/1060097): Migrate callers to the FeatureList equivalent function.
@Deprecated
public static boolean isInitialized() { public static boolean isInitialized() {
if (FeatureList.hasTestFeatures()) return true; return FeatureList.isInitialized();
return isNativeInitialized();
}
/**
* @return Whether the native FeatureList is initialized or not.
*/
private static boolean isNativeInitialized() {
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return ChromeFeatureListJni.get().isInitialized();
} }
/* /*
...@@ -99,7 +83,7 @@ public abstract class ChromeFeatureList { ...@@ -99,7 +83,7 @@ public abstract class ChromeFeatureList {
* @return Whether the feature is enabled or not. * @return Whether the feature is enabled or not.
*/ */
private static boolean isEnabledInNative(String featureName) { private static boolean isEnabledInNative(String featureName) {
assert isNativeInitialized(); assert FeatureList.isNativeInitialized();
return ChromeFeatureListJni.get().isEnabled(featureName); return ChromeFeatureListJni.get().isEnabled(featureName);
} }
...@@ -139,7 +123,7 @@ public abstract class ChromeFeatureList { ...@@ -139,7 +123,7 @@ public abstract class ChromeFeatureList {
*/ */
public static String getFieldTrialParamByFeature(String featureName, String paramName) { public static String getFieldTrialParamByFeature(String featureName, String paramName) {
if (FeatureList.hasTestFeatures()) return ""; if (FeatureList.hasTestFeatures()) return "";
assert isInitialized(); assert FeatureList.isInitialized();
return ChromeFeatureListJni.get().getFieldTrialParamByFeature(featureName, paramName); return ChromeFeatureListJni.get().getFieldTrialParamByFeature(featureName, paramName);
} }
...@@ -158,7 +142,7 @@ public abstract class ChromeFeatureList { ...@@ -158,7 +142,7 @@ public abstract class ChromeFeatureList {
public static int getFieldTrialParamByFeatureAsInt( public static int getFieldTrialParamByFeatureAsInt(
String featureName, String paramName, int defaultValue) { String featureName, String paramName, int defaultValue) {
if (FeatureList.hasTestFeatures()) return defaultValue; if (FeatureList.hasTestFeatures()) return defaultValue;
assert isInitialized(); assert FeatureList.isInitialized();
return ChromeFeatureListJni.get().getFieldTrialParamByFeatureAsInt( return ChromeFeatureListJni.get().getFieldTrialParamByFeatureAsInt(
featureName, paramName, defaultValue); featureName, paramName, defaultValue);
} }
...@@ -178,7 +162,7 @@ public abstract class ChromeFeatureList { ...@@ -178,7 +162,7 @@ public abstract class ChromeFeatureList {
public static double getFieldTrialParamByFeatureAsDouble( public static double getFieldTrialParamByFeatureAsDouble(
String featureName, String paramName, double defaultValue) { String featureName, String paramName, double defaultValue) {
if (FeatureList.hasTestFeatures()) return defaultValue; if (FeatureList.hasTestFeatures()) return defaultValue;
assert isInitialized(); assert FeatureList.isInitialized();
return ChromeFeatureListJni.get().getFieldTrialParamByFeatureAsDouble( return ChromeFeatureListJni.get().getFieldTrialParamByFeatureAsDouble(
featureName, paramName, defaultValue); featureName, paramName, defaultValue);
} }
...@@ -198,7 +182,7 @@ public abstract class ChromeFeatureList { ...@@ -198,7 +182,7 @@ public abstract class ChromeFeatureList {
public static boolean getFieldTrialParamByFeatureAsBoolean( public static boolean getFieldTrialParamByFeatureAsBoolean(
String featureName, String paramName, boolean defaultValue) { String featureName, String paramName, boolean defaultValue) {
if (FeatureList.hasTestFeatures()) return defaultValue; if (FeatureList.hasTestFeatures()) return defaultValue;
assert isInitialized(); assert FeatureList.isInitialized();
return ChromeFeatureListJni.get().getFieldTrialParamByFeatureAsBoolean( return ChromeFeatureListJni.get().getFieldTrialParamByFeatureAsBoolean(
featureName, paramName, defaultValue); featureName, paramName, defaultValue);
} }
...@@ -437,7 +421,6 @@ public abstract class ChromeFeatureList { ...@@ -437,7 +421,6 @@ public abstract class ChromeFeatureList {
@NativeMethods @NativeMethods
interface Natives { interface Natives {
boolean isInitialized();
boolean isEnabled(String featureName); boolean isEnabled(String featureName);
String getFieldTrialParamByFeature(String featureName, String paramName); String getFieldTrialParamByFeature(String featureName, String paramName);
int getFieldTrialParamByFeatureAsInt( int getFieldTrialParamByFeatureAsInt(
......
...@@ -8,7 +8,6 @@ import org.chromium.base.FeatureList; ...@@ -8,7 +8,6 @@ import org.chromium.base.FeatureList;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
/** /**
* Provides an API for querying the status of Site Settings features. * Provides an API for querying the status of Site Settings features.
...@@ -34,31 +33,12 @@ public class SiteSettingsFeatureList { ...@@ -34,31 +33,12 @@ public class SiteSettingsFeatureList {
public static boolean isEnabled(String featureName) { public static boolean isEnabled(String featureName) {
Boolean testValue = FeatureList.getTestValueForFeature(featureName); Boolean testValue = FeatureList.getTestValueForFeature(featureName);
if (testValue != null) return testValue; if (testValue != null) return testValue;
assert isNativeInitialized(); assert FeatureList.isNativeInitialized();
return SiteSettingsFeatureListJni.get().isEnabled(featureName); return SiteSettingsFeatureListJni.get().isEnabled(featureName);
} }
/**
* @return Whether the native FeatureList is initialized or not.
*/
private static boolean isNativeInitialized() {
if (FeatureList.hasTestFeatures()) return true;
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return SiteSettingsFeatureListJni.get().isInitialized();
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
boolean isInitialized();
boolean isEnabled(String featureName); boolean isEnabled(String featureName);
} }
} }
...@@ -36,10 +36,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) { ...@@ -36,10 +36,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
} // namespace } // namespace
static jboolean JNI_SiteSettingsFeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
static jboolean JNI_SiteSettingsFeatureList_IsEnabled( static jboolean JNI_SiteSettingsFeatureList_IsEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jstring>& jfeature_name) { const JavaParamRef<jstring>& jfeature_name) {
......
...@@ -36,10 +36,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) { ...@@ -36,10 +36,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
} // namespace } // namespace
static jboolean JNI_ContentSettingsFeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
static jboolean JNI_ContentSettingsFeatureList_IsEnabled( static jboolean JNI_ContentSettingsFeatureList_IsEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jstring>& jfeature_name) { const JavaParamRef<jstring>& jfeature_name) {
......
...@@ -8,7 +8,6 @@ import org.chromium.base.FeatureList; ...@@ -8,7 +8,6 @@ import org.chromium.base.FeatureList;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
/** /**
* Provides an API for querying the status of Content Settings features. * Provides an API for querying the status of Content Settings features.
...@@ -24,12 +23,14 @@ public class ContentSettingsFeatureList { ...@@ -24,12 +23,14 @@ public class ContentSettingsFeatureList {
private ContentSettingsFeatureList() {} private ContentSettingsFeatureList() {}
/** /**
* @deprecated Use {@link FeatureList#isInitialized()} instead
* @return Whether the native FeatureList has been initialized. If this method returns false, * @return Whether the native FeatureList has been initialized. If this method returns false,
* none of the methods in this class that require native access should be called. * none of the methods in this class that require native access should be called.
*/ */
// TODO(crbug.com/1060097): Migrate callers to the FeatureList equivalent function.
@Deprecated
public static boolean isInitialized() { public static boolean isInitialized() {
if (FeatureList.hasTestFeatures()) return true; return FeatureList.isInitialized();
return isNativeInitialized();
} }
/** /**
...@@ -45,31 +46,12 @@ public class ContentSettingsFeatureList { ...@@ -45,31 +46,12 @@ public class ContentSettingsFeatureList {
public static boolean isEnabled(String featureName) { public static boolean isEnabled(String featureName) {
Boolean testValue = FeatureList.getTestValueForFeature(featureName); Boolean testValue = FeatureList.getTestValueForFeature(featureName);
if (testValue != null) return testValue; if (testValue != null) return testValue;
assert isNativeInitialized(); assert FeatureList.isNativeInitialized();
return ContentSettingsFeatureListJni.get().isEnabled(featureName); return ContentSettingsFeatureListJni.get().isEnabled(featureName);
} }
/**
* @return Whether the native FeatureList is initialized or not.
*/
private static boolean isNativeInitialized() {
if (FeatureList.hasTestFeatures()) return true;
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return ContentSettingsFeatureListJni.get().isInitialized();
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
boolean isInitialized();
boolean isEnabled(String featureName); boolean isEnabled(String featureName);
} }
} }
...@@ -667,6 +667,7 @@ _jar_excluded_patterns = [ ...@@ -667,6 +667,7 @@ _jar_excluded_patterns = [
"*/multidex/*.class", "*/multidex/*.class",
"*/process_launcher/*.class", "*/process_launcher/*.class",
"*/SysUtils*.class", "*/SysUtils*.class",
"org/chromium/base/FeatureList*.class",
"org/chromium/base/memory/MemoryPressureMonitor*.class", "org/chromium/base/memory/MemoryPressureMonitor*.class",
] ]
......
...@@ -38,10 +38,6 @@ const base::Feature kIntentBlockExternalFormRedirectsNoGesture{ ...@@ -38,10 +38,6 @@ const base::Feature kIntentBlockExternalFormRedirectsNoGesture{
"IntentBlockExternalFormRedirectsNoGesture", "IntentBlockExternalFormRedirectsNoGesture",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
static jboolean JNI_ExternalIntentsFeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
static jboolean JNI_ExternalIntentsFeatureList_IsEnabled( static jboolean JNI_ExternalIntentsFeatureList_IsEnabled(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jstring>& jfeature_name) { const base::android::JavaParamRef<jstring>& jfeature_name) {
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
package org.chromium.components.external_intents; package org.chromium.components.external_intents;
import org.chromium.base.FeatureList;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
/** /**
* Java accessor for base/feature_list.h state. * Java accessor for base/feature_list.h state.
...@@ -22,22 +22,6 @@ public abstract class ExternalIntentsFeatureList { ...@@ -22,22 +22,6 @@ public abstract class ExternalIntentsFeatureList {
/** Prevent instantiation. */ /** Prevent instantiation. */
private ExternalIntentsFeatureList() {} private ExternalIntentsFeatureList() {}
/**
* @return Whether the native FeatureList is initialized or not.
*/
private static boolean isNativeInitialized() {
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return ExternalIntentsFeatureListJni.get().isInitialized();
}
/** /**
* Returns whether the specified feature is enabled or not. * Returns whether the specified feature is enabled or not.
* *
...@@ -54,7 +38,7 @@ public abstract class ExternalIntentsFeatureList { ...@@ -54,7 +38,7 @@ public abstract class ExternalIntentsFeatureList {
* @return Whether the feature is enabled or not. * @return Whether the feature is enabled or not.
*/ */
public static boolean isEnabled(String featureName) { public static boolean isEnabled(String featureName) {
assert isNativeInitialized(); assert FeatureList.isNativeInitialized();
return ExternalIntentsFeatureListJni.get().isEnabled(featureName); return ExternalIntentsFeatureListJni.get().isEnabled(featureName);
} }
...@@ -64,7 +48,6 @@ public abstract class ExternalIntentsFeatureList { ...@@ -64,7 +48,6 @@ public abstract class ExternalIntentsFeatureList {
@NativeMethods @NativeMethods
interface Natives { interface Natives {
boolean isInitialized();
boolean isEnabled(String featureName); boolean isEnabled(String featureName);
} }
} }
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
package org.chromium.components.subresource_filter; package org.chromium.components.subresource_filter;
import org.chromium.base.FeatureList;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
/** /**
* Provides an API for querying the status of subresource_filter component Features. * Provides an API for querying the status of subresource_filter component Features.
...@@ -31,29 +31,12 @@ public class SubresourceFilterFeatureList { ...@@ -31,29 +31,12 @@ public class SubresourceFilterFeatureList {
* @return Whether the feature is enabled or not. * @return Whether the feature is enabled or not.
*/ */
public static boolean isEnabled(String featureName) { public static boolean isEnabled(String featureName) {
assert isNativeInitialized(); assert FeatureList.isNativeInitialized();
return SubresourceFilterFeatureListJni.get().isEnabled(featureName); return SubresourceFilterFeatureListJni.get().isEnabled(featureName);
} }
/**
* @return Whether the native FeatureList is initialized or not.
*/
private static boolean isNativeInitialized() {
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return SubresourceFilterFeatureListJni.get().isInitialized();
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
boolean isInitialized();
boolean isEnabled(String featureName); boolean isEnabled(String featureName);
} }
} }
...@@ -35,10 +35,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) { ...@@ -35,10 +35,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
} // namespace } // namespace
static jboolean JNI_SubresourceFilterFeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
static jboolean JNI_SubresourceFilterFeatureList_IsEnabled( static jboolean JNI_SubresourceFilterFeatureList_IsEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jstring>& jfeature_name) { const JavaParamRef<jstring>& jfeature_name) {
......
...@@ -35,10 +35,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) { ...@@ -35,10 +35,6 @@ const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
} // namespace } // namespace
static jboolean JNI_DeviceFeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
static jboolean JNI_DeviceFeatureList_IsEnabled( static jboolean JNI_DeviceFeatureList_IsEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jstring>& jfeature_name) { const JavaParamRef<jstring>& jfeature_name) {
......
...@@ -8,7 +8,6 @@ import org.chromium.base.FeatureList; ...@@ -8,7 +8,6 @@ import org.chromium.base.FeatureList;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
/** /**
* Provides an API for querying the status of Device Service Features. * Provides an API for querying the status of Device Service Features.
...@@ -33,31 +32,12 @@ public class DeviceFeatureList { ...@@ -33,31 +32,12 @@ public class DeviceFeatureList {
public static boolean isEnabled(String featureName) { public static boolean isEnabled(String featureName) {
Boolean testValue = FeatureList.getTestValueForFeature(featureName); Boolean testValue = FeatureList.getTestValueForFeature(featureName);
if (testValue != null) return testValue; if (testValue != null) return testValue;
assert isNativeInitialized(); assert FeatureList.isNativeInitialized();
return DeviceFeatureListJni.get().isEnabled(featureName); return DeviceFeatureListJni.get().isEnabled(featureName);
} }
/**
* @return Whether the native FeatureList is initialized or not.
*/
private static boolean isNativeInitialized() {
if (FeatureList.hasTestFeatures()) return true;
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return DeviceFeatureListJni.get().isInitialized();
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
boolean isInitialized();
boolean isEnabled(String featureName); boolean isEnabled(String featureName);
} }
} }
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