Commit cfd87c24 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: remove native side of AwSafeBrowsingConfigHelper

This removes the native side of AwSafeBrowsingConfigHelper and the
related AwContentsStatics methods. The native AwSafeBrowsingConfigHelper
previously only maintained a global variable to keep track of manifest
opt-in. However, we currently only set/get that value from the Java
side. Therefore, we can remove the native side and keep track of this
value in a static Java variable.

This appears to be the culprit for some startup delay, so this is
expected to improve startup time as well.

R=torne@chromium.org

      conditions (including manifest opt-in/out)
      (seems to be a noticeable startup win, net reduction of 23 ms locally)

Bug: 859696
Test: manual - use SuperSafeBrowsing test app, check a variety of opt-in
Test: tools/perf/run_benchmark system_health.webview_startup --browser android-webview-google
Change-Id: I520c405027991101b5c8c23c58853c6b7c73c2b3
Reviewed-on: https://chromium-review.googlesource.com/1123887
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572366}
parent 0e3be792
...@@ -524,8 +524,6 @@ source_set("common") { ...@@ -524,8 +524,6 @@ source_set("common") {
"browser/aw_resource_context.h", "browser/aw_resource_context.h",
"browser/aw_safe_browsing_blocking_page.cc", "browser/aw_safe_browsing_blocking_page.cc",
"browser/aw_safe_browsing_blocking_page.h", "browser/aw_safe_browsing_blocking_page.h",
"browser/aw_safe_browsing_config_helper.cc",
"browser/aw_safe_browsing_config_helper.h",
"browser/aw_safe_browsing_resource_throttle.cc", "browser/aw_safe_browsing_resource_throttle.cc",
"browser/aw_safe_browsing_resource_throttle.h", "browser/aw_safe_browsing_resource_throttle.h",
"browser/aw_safe_browsing_ui_manager.cc", "browser/aw_safe_browsing_ui_manager.cc",
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "android_webview/browser/aw_browser_context.h" #include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_contents.h" #include "android_webview/browser/aw_contents.h"
#include "android_webview/browser/aw_contents_io_thread_client.h" #include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_safe_browsing_config_helper.h"
#include "android_webview/browser/aw_safe_browsing_whitelist_manager.h" #include "android_webview/browser/aw_safe_browsing_whitelist_manager.h"
#include "android_webview/browser/net/aw_url_request_context_getter.h" #include "android_webview/browser/net/aw_url_request_context_getter.h"
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
...@@ -97,21 +96,6 @@ ScopedJavaLocalRef<jstring> JNI_AwContentsStatics_GetProductVersion( ...@@ -97,21 +96,6 @@ ScopedJavaLocalRef<jstring> JNI_AwContentsStatics_GetProductVersion(
env, version_info::GetVersionNumber()); env, version_info::GetVersionNumber());
} }
// static
jboolean JNI_AwContentsStatics_GetSafeBrowsingEnabledByManifest(
JNIEnv* env,
const JavaParamRef<jclass>&) {
return AwSafeBrowsingConfigHelper::GetSafeBrowsingEnabledByManifest();
}
// static
void JNI_AwContentsStatics_SetSafeBrowsingEnabledByManifest(
JNIEnv* env,
const JavaParamRef<jclass>&,
jboolean enable) {
AwSafeBrowsingConfigHelper::SetSafeBrowsingEnabledByManifest(enable);
}
// static // static
void JNI_AwContentsStatics_SetSafeBrowsingWhitelist( void JNI_AwContentsStatics_SetSafeBrowsingWhitelist(
JNIEnv* env, JNIEnv* env,
......
// Copyright 2017 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 "android_webview/browser/aw_safe_browsing_config_helper.h"
#include "base/android/scoped_java_ref.h"
#include "base/lazy_instance.h"
#include "base/synchronization/lock.h"
namespace {
// g_safebrowsing_enabled_by_manifest can be set and read from different
// threads.
base::LazyInstance<base::Lock>::Leaky g_safebrowsing_enabled_by_manifest_lock =
LAZY_INSTANCE_INITIALIZER;
bool g_safebrowsing_enabled_by_manifest = false;
} // namespace
namespace android_webview {
// static
void AwSafeBrowsingConfigHelper::SetSafeBrowsingEnabledByManifest(
bool enabled) {
base::AutoLock lock(g_safebrowsing_enabled_by_manifest_lock.Get());
g_safebrowsing_enabled_by_manifest = enabled;
}
// static
bool AwSafeBrowsingConfigHelper::GetSafeBrowsingEnabledByManifest() {
base::AutoLock lock(g_safebrowsing_enabled_by_manifest_lock.Get());
return g_safebrowsing_enabled_by_manifest;
}
} // namespace android_webview
// Copyright 2017 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.
#ifndef ANDROID_WEBVIEW_BROWSER_AW_SAFE_BROWSING_CONFIG_HELPER_H_
#define ANDROID_WEBVIEW_BROWSER_AW_SAFE_BROWSING_CONFIG_HELPER_H_
#include "base/macros.h"
namespace android_webview {
class AwSafeBrowsingConfigHelper {
public:
static bool GetSafeBrowsingEnabledByManifest();
static void SetSafeBrowsingEnabledByManifest(bool enabled);
private:
AwSafeBrowsingConfigHelper();
DISALLOW_COPY_AND_ASSIGN(AwSafeBrowsingConfigHelper);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_AW_SAFE_BROWSING_CONFIG_HELPER_H_
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "android_webview/browser/aw_contents_client_bridge.h" #include "android_webview/browser/aw_contents_client_bridge.h"
#include "android_webview/browser/aw_contents_io_thread_client.h" #include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_resource_context.h" #include "android_webview/browser/aw_resource_context.h"
#include "android_webview/browser/aw_safe_browsing_config_helper.h"
#include "android_webview/browser/aw_safe_browsing_resource_throttle.h" #include "android_webview/browser/aw_safe_browsing_resource_throttle.h"
#include "android_webview/browser/net/aw_web_resource_request.h" #include "android_webview/browser/net/aw_web_resource_request.h"
#include "android_webview/browser/renderer_host/auto_login_parser.h" #include "android_webview/browser/renderer_host/auto_login_parser.h"
......
...@@ -84,15 +84,6 @@ public class AwContentsStatics { ...@@ -84,15 +84,6 @@ public class AwContentsStatics {
nativeSetServiceWorkerIoThreadClient(ioThreadClient, browserContext); nativeSetServiceWorkerIoThreadClient(ioThreadClient, browserContext);
} }
// Can be called from any thread.
public static boolean getSafeBrowsingEnabledByManifest() {
return nativeGetSafeBrowsingEnabledByManifest();
}
public static void setSafeBrowsingEnabledByManifest(boolean enable) {
nativeSetSafeBrowsingEnabledByManifest(enable);
}
@CalledByNative @CalledByNative
private static void safeBrowsingWhitelistAssigned(Callback<Boolean> callback, boolean success) { private static void safeBrowsingWhitelistAssigned(Callback<Boolean> callback, boolean success) {
if (callback == null) return; if (callback == null) return;
...@@ -152,8 +143,6 @@ public class AwContentsStatics { ...@@ -152,8 +143,6 @@ public class AwContentsStatics {
private static native String nativeGetProductVersion(); private static native String nativeGetProductVersion();
private static native void nativeSetServiceWorkerIoThreadClient( private static native void nativeSetServiceWorkerIoThreadClient(
AwContentsIoThreadClient ioThreadClient, AwBrowserContext browserContext); AwContentsIoThreadClient ioThreadClient, AwBrowserContext browserContext);
private static native boolean nativeGetSafeBrowsingEnabledByManifest();
private static native void nativeSetSafeBrowsingEnabledByManifest(boolean enable);
private static native void nativeSetSafeBrowsingWhitelist( private static native void nativeSetSafeBrowsingWhitelist(
String[] urls, Callback<Boolean> callback); String[] urls, Callback<Boolean> callback);
private static native void nativeSetCheckClearTextPermitted(boolean permitted); private static native void nativeSetCheckClearTextPermitted(boolean permitted);
......
...@@ -27,6 +27,7 @@ public class AwSafeBrowsingConfigHelper { ...@@ -27,6 +27,7 @@ public class AwSafeBrowsingConfigHelper {
private static final boolean DEFAULT_USER_OPT_IN = false; private static final boolean DEFAULT_USER_OPT_IN = false;
private static volatile Boolean sSafeBrowsingUserOptIn; private static volatile Boolean sSafeBrowsingUserOptIn;
private static volatile boolean sEnabledByManifest;
// Used to record the UMA histogram SafeBrowsing.WebView.AppOptIn. Since these values are // Used to record the UMA histogram SafeBrowsing.WebView.AppOptIn. Since these values are
// persisted to logs, they should never be renumbered nor reused. // persisted to logs, they should never be renumbered nor reused.
...@@ -60,6 +61,14 @@ public class AwSafeBrowsingConfigHelper { ...@@ -60,6 +61,14 @@ public class AwSafeBrowsingConfigHelper {
"SafeBrowsing.WebView.UserOptIn", value, UserOptIn.COUNT); "SafeBrowsing.WebView.UserOptIn", value, UserOptIn.COUNT);
} }
public static void setSafeBrowsingEnabledByManifest(boolean enabled) {
sEnabledByManifest = enabled;
}
public static boolean getSafeBrowsingEnabledByManifest() {
return sEnabledByManifest;
}
// Should only be called once during startup. Calling this multiple times will skew UMA metrics. // Should only be called once during startup. Calling this multiple times will skew UMA metrics.
public static void maybeEnableSafeBrowsingFromManifest(final Context appContext) { public static void maybeEnableSafeBrowsingFromManifest(final Context appContext) {
try (ScopedSysTraceEvent e = ScopedSysTraceEvent.scoped( try (ScopedSysTraceEvent e = ScopedSysTraceEvent.scoped(
...@@ -75,7 +84,7 @@ public class AwSafeBrowsingConfigHelper { ...@@ -75,7 +84,7 @@ public class AwSafeBrowsingConfigHelper {
// If the app specifies something, fallback to the app's preference, otherwise check for // If the app specifies something, fallback to the app's preference, otherwise check for
// the existence of the CLI switch. // the existence of the CLI switch.
AwContentsStatics.setSafeBrowsingEnabledByManifest( setSafeBrowsingEnabledByManifest(
appOptIn == null ? !isDisabledByCommandLine() : appOptIn); appOptIn == null ? !isDisabledByCommandLine() : appOptIn);
Callback<Boolean> cb = verifyAppsValue -> { Callback<Boolean> cb = verifyAppsValue -> {
......
...@@ -84,7 +84,7 @@ public class AwServiceWorkerController { ...@@ -84,7 +84,7 @@ public class AwServiceWorkerController {
@Override @Override
public boolean getSafeBrowsingEnabled() { public boolean getSafeBrowsingEnabled() {
return AwContentsStatics.getSafeBrowsingEnabledByManifest(); return AwSafeBrowsingConfigHelper.getSafeBrowsingEnabledByManifest();
} }
} }
......
...@@ -110,7 +110,7 @@ public class AwSettings { ...@@ -110,7 +110,7 @@ public class AwSettings {
// Although this bit is stored on AwSettings it is actually controlled via the CookieManager. // Although this bit is stored on AwSettings it is actually controlled via the CookieManager.
private boolean mAcceptThirdPartyCookies; private boolean mAcceptThirdPartyCookies;
// if null, default to AwContentsStatics.getSafeBrowsingEnabledByManifest() // if null, default to AwSafeBrowsingConfigHelper.getSafeBrowsingEnabledByManifest()
private Boolean mSafeBrowsingEnabled; private Boolean mSafeBrowsingEnabled;
private final boolean mSupportLegacyQuirks; private final boolean mSupportLegacyQuirks;
...@@ -378,7 +378,7 @@ public class AwSettings { ...@@ -378,7 +378,7 @@ public class AwSettings {
if (userOptIn != null && !userOptIn) return false; if (userOptIn != null && !userOptIn) return false;
if (mSafeBrowsingEnabled == null) { if (mSafeBrowsingEnabled == null) {
return AwContentsStatics.getSafeBrowsingEnabledByManifest(); return AwSafeBrowsingConfigHelper.getSafeBrowsingEnabledByManifest();
} }
return mSafeBrowsingEnabled; return mSafeBrowsingEnabled;
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "android_webview/browser/aw_content_browser_client.h" #include "android_webview/browser/aw_content_browser_client.h"
#include "android_webview/browser/aw_media_url_interceptor.h" #include "android_webview/browser/aw_media_url_interceptor.h"
#include "android_webview/browser/aw_safe_browsing_config_helper.h"
#include "android_webview/browser/browser_view_renderer.h" #include "android_webview/browser/browser_view_renderer.h"
#include "android_webview/browser/command_line_helper.h" #include "android_webview/browser/command_line_helper.h"
#include "android_webview/browser/deferred_gpu_command_service.h" #include "android_webview/browser/deferred_gpu_command_service.h"
......
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