Commit 0a4dae2a authored by Paul Miller's avatar Paul Miller Committed by Commit Bot

Combine WebView's services

Combine the crash_receiver_service and variations_service processes into
a single webview_service process. This will save memory when crash and
variations services are used simultaneously.

Combine the crash/ and variations/ Java code into a single services/
directory.

Create ServiceInit.java for common initialization code and to ensure
ContextUtils.initApplicationContext() is called only once per service
process lifetime.

BUG=733857

Change-Id: I2588344d3d08d64f37cdd61d70d916438e32bcc4
Reviewed-on: https://chromium-review.googlesource.com/935902
Commit-Queue: Paul Miller <paulmiller@chromium.org>
Reviewed-by: default avatarGustav Sennton <gsennton@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539931}
parent cc1222ce
......@@ -857,15 +857,11 @@ android_library("android_webview_java") {
"java/src/org/chromium/android_webview/permission/AwGeolocationCallback.java",
"java/src/org/chromium/android_webview/permission/AwPermissionRequest.java",
"java/src/org/chromium/android_webview/policy/AwPolicyProvider.java",
"java/src/org/chromium/android_webview/variations/AwVariationsConfigurationService.java",
"java/src/org/chromium/android_webview/variations/AwVariationsSeedFetchService.java",
"java/src/org/chromium/android_webview/variations/AwVariationsSeedHandler.java",
"java/src/org/chromium/android_webview/variations/AwVariationsUtils.java",
]
deps = [
":android_webview_commandline_java",
":android_webview_crash_services_java",
":android_webview_platform_services_java",
":android_webview_services_java",
":resources",
":strings_grd",
":system_webview_manifest",
......@@ -878,7 +874,6 @@ android_library("android_webview_java") {
"//components/navigation_interception/android:navigation_interception_java",
"//components/policy/android:policy_java",
"//components/safe_browsing/android:safe_browsing_java",
"//components/variations/android:variations_java",
"//components/web_contents_delegate_android:web_contents_delegate_android_java",
"//components/web_restrictions:client_java",
"//content/public/android:content_java",
......@@ -986,13 +981,18 @@ android_library("android_webview_commandline_java") {
]
}
# Keep crash services separate from other WebView code to keep their deps clean
# Keep WebView's services separate from other WebView code to keep their deps clean
# (and make them easy to move).
android_library("android_webview_crash_services_java") {
android_library("android_webview_services_java") {
java_files = [
"java/src/org/chromium/android_webview/crash/AwMinidumpUploadJobService.java",
"java/src/org/chromium/android_webview/crash/AwMinidumpUploaderDelegate.java",
"java/src/org/chromium/android_webview/crash/CrashReceiverService.java",
"java/src/org/chromium/android_webview/services/AwMinidumpUploadJobService.java",
"java/src/org/chromium/android_webview/services/AwMinidumpUploaderDelegate.java",
"java/src/org/chromium/android_webview/services/AwVariationsConfigurationService.java",
"java/src/org/chromium/android_webview/services/AwVariationsSeedFetchService.java",
"java/src/org/chromium/android_webview/services/AwVariationsSeedHandler.java",
"java/src/org/chromium/android_webview/services/AwVariationsUtils.java",
"java/src/org/chromium/android_webview/services/CrashReceiverService.java",
"java/src/org/chromium/android_webview/services/ServiceInit.java",
]
deps = [
":android_webview_commandline_java",
......@@ -1001,6 +1001,7 @@ android_library("android_webview_crash_services_java") {
"//base:base_java",
"//components/background_task_scheduler:background_task_scheduler_java",
"//components/minidump_uploader:minidump_uploader_java",
"//components/variations/android:variations_java",
]
srcjar_deps = [ ":crash_receiver_aidl" ]
......@@ -1010,7 +1011,7 @@ android_library("android_webview_crash_services_java") {
android_aidl("crash_receiver_aidl") {
import_include = [ "java/src" ]
sources = [
"java/src/org/chromium/android_webview/crash/ICrashReceiverService.aidl",
"java/src/org/chromium/android_webview/services/ICrashReceiverService.aidl",
]
}
......
......@@ -13,9 +13,9 @@
</uses-sdk>
<uses-feature android:name="android.hardware.touchscreen"
android:required="false"/>
android:required="false" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:label="Android System WebView"
......@@ -40,20 +40,20 @@
android:exported="true"
android:authorities="{{ manifest_package }}.LicenseContentProvider" />
{% if donor_package is not defined %}
<service android:name="org.chromium.android_webview.variations.AwVariationsConfigurationService"
<service android:name="org.chromium.android_webview.services.AwVariationsConfigurationService"
android:exported="true"
android:process=":variations_service"/>
<service android:name="org.chromium.android_webview.variations.AwVariationsSeedFetchService"
android:process=":webview_service" />
<service android:name="org.chromium.android_webview.services.AwVariationsSeedFetchService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false"
android:process=":webview_service" />
<service android:name="org.chromium.android_webview.services.CrashReceiverService"
android:exported="true"
android:process=":variations_service"/>
<service android:name="org.chromium.android_webview.crash.CrashReceiverService"
android:exported="true"
android:process=":crash_receiver_service"/>
<service android:name="org.chromium.android_webview.crash.AwMinidumpUploadJobService"
android:process=":webview_service" />
<service android:name="org.chromium.android_webview.services.AwMinidumpUploadJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"
android:process=":crash_receiver_service"/>
android:process=":webview_service" />
{% endif %}
{% endmacro %}
{{ common(package|default('com.android.webview'), library|default('libwebviewchromium.so')) }}
......@@ -63,7 +63,7 @@
{% endif %}
{% set num_sandboxed_services = 20 %}
<meta-data android:name="org.chromium.content.browser.NUM_SANDBOXED_SERVICES"
android:value="{{ num_sandboxed_services }}"/>
android:value="{{ num_sandboxed_services }}" />
{% for i in range(num_sandboxed_services) %}
<service android:name="org.chromium.content.app.SandboxedProcessService{{ i }}"
android:process=":sandboxed_process{{ i }}"
......@@ -74,6 +74,6 @@
android:visibleToInstantApps="true" />
{% endfor %}
<meta-data android:name="org.chromium.content.browser.NUM_PRIVILEGED_SERVICES"
android:value="0"/>
android:value="0" />
</application>
</manifest>
......@@ -34,7 +34,7 @@ import org.chromium.android_webview.AwSwitches;
import org.chromium.android_webview.AwTracingController;
import org.chromium.android_webview.HttpAuthDatabase;
import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.android_webview.variations.AwVariationsSeedHandler;
import org.chromium.android_webview.services.AwVariationsSeedHandler;
import org.chromium.base.BuildConfig;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
......@@ -187,7 +187,7 @@ public class WebViewChromiumAwInit {
boolean enableVariations =
CommandLine.getInstance().hasSwitch(AwSwitches.ENABLE_WEBVIEW_VARIATIONS);
if (enableVariations) {
AwVariationsSeedHandler.bindToVariationsService();
AwVariationsSeedHandler.bindToVariationsService(webViewPackageName);
}
}
......
......@@ -16,9 +16,9 @@ import android.os.RemoteException;
import android.os.StrictMode;
import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.android_webview.crash.CrashReceiverService;
import org.chromium.android_webview.crash.ICrashReceiverService;
import org.chromium.android_webview.policy.AwPolicyProvider;
import org.chromium.android_webview.services.CrashReceiverService;
import org.chromium.android_webview.services.ICrashReceiverService;
import org.chromium.base.BuildInfo;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
......
// Copyright 2016 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.
package org.chromium.android_webview.crash;
package org.chromium.android_webview.services;
import android.os.PersistableBundle;
import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.base.ContextUtils;
import org.chromium.components.minidump_uploader.MinidumpUploadJobService;
import org.chromium.components.minidump_uploader.MinidumpUploader;
import org.chromium.components.minidump_uploader.MinidumpUploaderImpl;
......@@ -19,17 +17,11 @@ public class AwMinidumpUploadJobService extends MinidumpUploadJobService {
@Override
public void onCreate() {
super.onCreate();
// This overwrites the command line set by ChromeApplication.onCreate() to use a
// WebView-specific command line file. This is okay since this Service is not running in the
// same process as the main Chrome process.
CommandLineUtil.initCommandLine();
ServiceInit.init(getApplicationContext());
}
@Override
protected MinidumpUploader createMinidumpUploader(PersistableBundle unusedExtras) {
// Ensure we can use ContextUtils later on (from the minidump_uploader component).
ContextUtils.initApplicationContext(this.getApplicationContext());
return new MinidumpUploaderImpl(new AwMinidumpUploaderDelegate());
}
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.crash;
package org.chromium.android_webview.services;
import android.content.Context;
import android.net.ConnectivityManager;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.variations;
package org.chromium.android_webview.services;
import android.app.Service;
import android.app.job.JobInfo;
......@@ -19,11 +19,9 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.util.Base64;
import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.base.ContextUtils;
import org.chromium.base.FileUtils;
import org.chromium.base.Log;
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.components.background_task_scheduler.TaskIds;
......@@ -58,12 +56,7 @@ public class AwVariationsConfigurationService extends Service {
@Override
public void onCreate() {
super.onCreate();
// Ensure that ContextUtils.getApplicationContext() will return the current context in the
// following code for the function won't work when we use the standalone WebView package.
ContextUtils.initApplicationContext(this.getApplicationContext());
// Ensure that PathUtils.getDataDirectory() will return the app_webview directory in the
// following code.
PathUtils.setPrivateDataDirectorySuffix(AwBrowserProcess.WEBVIEW_DIR_BASENAME);
ServiceInit.init(getApplicationContext());
}
@Override
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.variations;
package org.chromium.android_webview.services;
import android.app.job.JobParameters;
import android.app.job.JobService;
......@@ -17,7 +17,6 @@ import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import org.chromium.android_webview.variations.AwVariationsUtils.SeedPreference;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
......@@ -42,8 +41,7 @@ public class AwVariationsSeedFetchService extends JobService {
@Override
public boolean onStartJob(JobParameters params) {
// Ensure we can use ContextUtils later on.
ContextUtils.initApplicationContext(this.getApplicationContext());
ServiceInit.init(getApplicationContext());
mFetchVariationsSeedTask = new FetchVariationsSeedTask(params);
mFetchVariationsSeedTask.execute();
return true;
......@@ -108,7 +106,7 @@ public class AwVariationsSeedFetchService extends JobService {
public void onServiceConnected(ComponentName className, IBinder service) {
Bundle bundle = new Bundle();
bundle.putByteArray(AwVariationsUtils.KEY_SEED_DATA, mSeedInfo.seedData);
ArrayList<String> list = new SeedPreference(mSeedInfo).toArrayList();
ArrayList<String> list = new AwVariationsUtils.SeedPreference(mSeedInfo).toArrayList();
bundle.putStringArrayList(AwVariationsUtils.KEY_SEED_PREF, list);
// Directly set members of AwVariationsConfigurationService to prevent a malicious app
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.variations;
package org.chromium.android_webview.services;
import android.content.ComponentName;
import android.content.Context;
......@@ -16,7 +16,6 @@ import android.os.Messenger;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.base.ContextUtils;
import org.chromium.base.FileUtils;
import org.chromium.base.Log;
......@@ -72,7 +71,7 @@ public class AwVariationsSeedHandler extends Handler {
/**
* Bind to AwVariationsConfigurationService in the current context to ask for a seed.
*/
public static void bindToVariationsService() {
public static void bindToVariationsService(String webViewPackageName) {
File appWebViewVariationsDir = null;
try {
appWebViewVariationsDir = getOrCreateVariationsDirectory();
......@@ -114,7 +113,6 @@ public class AwVariationsSeedHandler extends Handler {
};
Intent intent = new Intent();
String webViewPackageName = AwBrowserProcess.getWebViewPackageName();
intent.setClassName(webViewPackageName, AwVariationsConfigurationService.class.getName());
Context context = ContextUtils.getApplicationContext();
if (!context.bindService(intent, connection, Context.BIND_AUTO_CREATE)) {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.variations;
package org.chromium.android_webview.services;
import android.os.ParcelFileDescriptor;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.crash;
package org.chromium.android_webview.services;
import android.app.Service;
import android.app.job.JobInfo;
......@@ -37,8 +37,7 @@ public class CrashReceiverService extends Service {
@Override
public void onCreate() {
super.onCreate();
ContextUtils.initApplicationContext(this.getApplicationContext());
ServiceInit.init(getApplicationContext());
}
private final ICrashReceiverService.Stub mBinder = new ICrashReceiverService.Stub() {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.crash;
package org.chromium.android_webview.services;
interface ICrashReceiverService {
void transmitCrashes(in ParcelFileDescriptor[] fileDescriptors);
......
per-file *.aidl=set noparent
per-file *.aidl=file://ipc/SECURITY_OWNERS
This directory contains WebView services running in the WebView provider's
webview_service process. There is only one such process on a device. The native
library is not loaded in this process.
// Copyright 2018 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.
package org.chromium.android_webview.services;
import android.content.Context;
import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.base.ContextUtils;
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
/**
* Does initialization common to all WebView services.
*/
@VisibleForTesting
public class ServiceInit {
private static final String WEBVIEW_SERVICE_DIR_BASENAME = "webview";
private static boolean sInitDone;
public static void init(Context appContext) {
ThreadUtils.assertOnUiThread();
if (sInitDone) return;
ContextUtils.initApplicationContext(appContext);
// In Monochrome, ChromeApplication.attachBaseContext() will set Chrome's command line.
// initCommandLine() overwrites this with WebView's command line.
CommandLineUtil.initCommandLine();
// This is unrelated to the PathUtils directory set in WebView proper, because this code
// runs only in the service process.
PathUtils.setPrivateDataDirectorySuffix(WEBVIEW_SERVICE_DIR_BASENAME);
sInitDone = true;
}
}
......@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.test.variations;
package org.chromium.android_webview.test.services;
import static org.chromium.android_webview.variations.AwVariationsUtils.SEED_DATA_FILENAME;
import static org.chromium.android_webview.variations.AwVariationsUtils.SEED_PREF_FILENAME;
import static org.chromium.android_webview.services.AwVariationsUtils.SEED_DATA_FILENAME;
import static org.chromium.android_webview.services.AwVariationsUtils.SEED_PREF_FILENAME;
import android.os.ParcelFileDescriptor;
import android.support.test.InstrumentationRegistry;
......@@ -19,10 +19,10 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.variations.AwVariationsConfigurationService;
import org.chromium.android_webview.variations.AwVariationsSeedHandler;
import org.chromium.android_webview.variations.AwVariationsUtils;
import org.chromium.android_webview.variations.AwVariationsUtils.SeedPreference;
import org.chromium.android_webview.services.AwVariationsConfigurationService;
import org.chromium.android_webview.services.AwVariationsSeedHandler;
import org.chromium.android_webview.services.AwVariationsUtils;
import org.chromium.android_webview.services.AwVariationsUtils.SeedPreference;
import org.chromium.base.ContextUtils;
import org.chromium.base.PathUtils;
import org.chromium.base.test.BaseJUnit4ClassRunner;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.test.crash;
package org.chromium.android_webview.test.services;
import android.os.ParcelFileDescriptor;
import android.support.test.InstrumentationRegistry;
......@@ -13,7 +13,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.android_webview.crash.CrashReceiverService;
import org.chromium.android_webview.services.CrashReceiverService;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.BaseJUnit4ClassRunner;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.test.crash;
package org.chromium.android_webview.test.services;
import android.os.ParcelFileDescriptor;
import android.support.test.filters.MediumTest;
......@@ -13,8 +13,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.android_webview.PlatformServiceBridge;
import org.chromium.android_webview.crash.AwMinidumpUploaderDelegate;
import org.chromium.android_webview.crash.CrashReceiverService;
import org.chromium.android_webview.services.AwMinidumpUploaderDelegate;
import org.chromium.android_webview.services.CrashReceiverService;
import org.chromium.base.Callback;
import org.chromium.base.FileUtils;
import org.chromium.base.ThreadUtils;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.test.crash;
package org.chromium.android_webview.test.services;
import android.content.Context;
import android.support.test.filters.SmallTest;
......
......@@ -117,9 +117,9 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
apk_under_test = ":webview_instrumentation_apk"
android_manifest = "../javatests/AndroidManifest.xml"
deps = [
"//android_webview:android_webview_crash_services_java",
"//android_webview:android_webview_java",
"//android_webview:android_webview_platform_services_java",
"//android_webview:android_webview_services_java",
"//android_webview/test/embedded_test_server:aw_net_java_test_support",
"//base:base_java",
"//base:base_java_test_support",
......@@ -226,9 +226,10 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
"../javatests/src/org/chromium/android_webview/test/WebViewFindApisTestRule.java",
"../javatests/src/org/chromium/android_webview/test/WebViewModalDialogOverrideTest.java",
"../javatests/src/org/chromium/android_webview/test/WebViewWebVrTest.java",
"../javatests/src/org/chromium/android_webview/test/crash/CrashReceiverServiceTest.java",
"../javatests/src/org/chromium/android_webview/test/crash/MinidumpUploaderTest.java",
"../javatests/src/org/chromium/android_webview/test/crash/VisualStateCallbackTest.java",
"../javatests/src/org/chromium/android_webview/test/services/AwVariationsConfigurationServiceTest.java",
"../javatests/src/org/chromium/android_webview/test/services/CrashReceiverServiceTest.java",
"../javatests/src/org/chromium/android_webview/test/services/MinidumpUploaderTest.java",
"../javatests/src/org/chromium/android_webview/test/services/VisualStateCallbackTest.java",
"../javatests/src/org/chromium/android_webview/test/util/AwQuotaManagerBridgeTestUtil.java",
"../javatests/src/org/chromium/android_webview/test/util/AwTestTouchUtils.java",
"../javatests/src/org/chromium/android_webview/test/util/CommonResources.java",
......@@ -240,7 +241,6 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
"../javatests/src/org/chromium/android_webview/test/util/VideoSurfaceViewUtils.java",
"../javatests/src/org/chromium/android_webview/test/util/VideoTestUtil.java",
"../javatests/src/org/chromium/android_webview/test/util/VideoTestWebServer.java",
"../javatests/src/org/chromium/android_webview/test/variations/AwVariationsConfigurationServiceTest.java",
]
data = [
"data/",
......
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