Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: chrome/android/webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService.java

Issue 2049843004: Upstream: Renderers are running in WebAPKs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService.java
diff --git a/chrome/android/webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService.java b/chrome/android/webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService.java
new file mode 100644
index 0000000000000000000000000000000000000000..778f35b9093c1487cec749297d4e6db8d484ea0f
--- /dev/null
+++ b/chrome/android/webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService.java
@@ -0,0 +1,101 @@
+// 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.webapk.lib.common;
+
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+import android.util.Log;
+
+import java.lang.reflect.Method;
+
+/**
+ * Child process service hosted by WebAPKs. This class uses BaseDexClassLoader to load Chrome's
+ * {@link ChildProcessServiceImpl} which loads Chrome's native libraries, initializes JNI and
+ * creates renderer processes.
pkotwicz 2016/06/15 14:13:50 Nit: Can you please update the comment? This class
Xi Han 2016/06/15 17:10:39 Done.
+ */
+public class WebApkSandboxedProcessService extends Service {
+ private static final String CHILD_PROCESS_SERVICE_IMPL =
pkotwicz 2016/06/15 14:13:50 Nit: Rename to CHILD_PROCESS_SERVICE_IMPL_CLASS_NA
Xi Han 2016/06/15 17:10:39 Done.
+ "org.chromium.content.app.ChildProcessServiceImpl";
+ private static final String TAG = "cr_WebApkSandboxedProcessService";
+
+ private Class<?> mChildProcessServiceImplClass;
+ private Object mChildProcessServiceImplInstance;
+ private static ClassLoader sClassLoader;
+
+ /**
+ * Gets/creates ClassLoader for loading {@link CHILD_PROCESS_SERVICE_IMPL}.
+ * @param context WebAPK's context.
+ * @return The ClassLoader.
+ */
+ private static ClassLoader getClassLoaderInstance(Context context) {
+ if (sClassLoader == null) {
+ sClassLoader = createClassLoader(context);
+ }
+ return sClassLoader;
+ }
+
+ /**
+ * Creates ClassLoader for loading {@link CHILD_PROCESS_SERVICE_IMPL}.
+ * @param context WebAPK's context.
+ * @return The ClassLoader.
+ */
+ private static ClassLoader createClassLoader(Context context) {
+ Context remoteContext = WebApkUtils.getHostBrowserContext(context);
+ return remoteContext.getClassLoader();
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+
+ try {
pkotwicz 2016/06/15 14:13:50 Can you just do: Context hostBrowserContext = WebA
Xi Han 2016/06/15 17:10:39 You are right, removed since we have to call the W
pkotwicz 2016/06/15 17:51:00 Thank you for making this change!
+ ClassLoader classLoader = getClassLoaderInstance(
+ getApplicationContext());
+ mChildProcessServiceImplClass =
+ classLoader.loadClass(CHILD_PROCESS_SERVICE_IMPL);
+ mChildProcessServiceImplInstance = mChildProcessServiceImplClass.newInstance();
+
+ Method createMethod = mChildProcessServiceImplClass.getMethod("create",
+ Context.class, Context.class);
+ createMethod.invoke(mChildProcessServiceImplInstance, getApplicationContext(),
+ WebApkUtils.getHostBrowserContext(getApplicationContext()));
+ } catch (Exception e) {
+ Log.d(TAG, "Unable to create a ChildProcessServiceImpl for the WebAPK.");
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // We call stopSelf() to request that this service be stopped as soon as the client
+ // unbinds. Otherwise the system may keep it around and available for a reconnect. The
+ // child processes do not currently support reconnect; they must be initialized from
+ // scratch every time.
+ stopSelf();
+ try {
+ Method bindMethod = mChildProcessServiceImplClass.getMethod(
+ "bind", Intent.class);
+ return (IBinder) bindMethod.invoke(mChildProcessServiceImplInstance, intent);
+ } catch (Exception e) {
+ Log.d(TAG, "Unable to bind to the WebApkSandboxedProcessService.");
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ try {
+ Method destroyMethod = mChildProcessServiceImplClass.getMethod("destroy");
+ destroyMethod.invoke(mChildProcessServiceImplInstance);
+ } catch (Exception e) {
+ Log.d(TAG, "Unable to destroy the WebApkSandboxedProcessService.");
+ e.printStackTrace();
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698