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..180aed506f0d3fb3556f30afec9d5305b01eaec7 |
--- /dev/null |
+++ b/chrome/android/webapk/libs/common/src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService.java |
@@ -0,0 +1,79 @@ |
+// 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 Chrome's ClassLoader to create an |
pkotwicz
2016/06/15 17:51:00
Nit: an -> a
|
+ * {@link ChildProcessServiceImpl} object which loads Chrome's native libraries, initializes JNI |
+ * and creates renderer processes. |
pkotwicz
2016/06/15 17:51:01
Nit: Replace "creates renderer processes" with "cr
Xi Han
2016/06/15 18:11:48
Yes, this is more accurate. Thanks.
|
+ */ |
+public class WebApkSandboxedProcessService extends Service { |
+ private static final String CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME = |
+ "org.chromium.content.app.ChildProcessServiceImpl"; |
+ private static final String TAG = "cr_WebApkSandboxedProcessService"; |
+ |
+ private Class<?> mChildProcessServiceImplClass; |
+ private Object mChildProcessServiceImplInstance; |
+ |
+ @Override |
+ public void onCreate() { |
+ super.onCreate(); |
+ |
+ try { |
+ Context hostBrowserContext = |
+ WebApkUtils.getHostBrowserContext(getApplicationContext()); |
+ ClassLoader classLoader = hostBrowserContext.getClassLoader(); |
+ mChildProcessServiceImplClass = |
+ classLoader.loadClass(CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME); |
+ mChildProcessServiceImplInstance = mChildProcessServiceImplClass.newInstance(); |
+ |
+ Method createMethod = mChildProcessServiceImplClass.getMethod("create", |
+ Context.class, Context.class); |
+ createMethod.invoke(mChildProcessServiceImplInstance, getApplicationContext(), |
+ hostBrowserContext); |
+ } 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(); |
+ } |
+ } |
+} |