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

Side by Side 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: Always check command line flags in getNum(Class)ofService(). 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.webapk.lib.common;
6
7 import android.app.Service;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.os.IBinder;
11 import android.util.Log;
12
13 import java.lang.reflect.Method;
14
15 /**
16 * Child process service hosted by WebAPKs. This class uses Chrome's ClassLoader to create a
17 * {@link ChildProcessServiceImpl} object which loads Chrome's native libraries, initializes JNI
18 * and creates the renderer.
19 */
20 public class WebApkSandboxedProcessService extends Service {
21 // Note: the {@link CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME} must sync with th e class name
22 // of Chrome's {@link ChildProcessServiceImpl}.
23 private static final String CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME =
24 "org.chromium.content.app.ChildProcessServiceImpl";
25 private static final String TAG = "cr_WebApkSandboxedProcessService";
26
27 private Class<?> mChildProcessServiceImplClass;
28 private Object mChildProcessServiceImplInstance;
29
30 @Override
31 public void onCreate() {
32 super.onCreate();
33
34 try {
35 Context hostBrowserContext =
36 WebApkUtils.getHostBrowserContext(getApplicationContext());
37 ClassLoader classLoader = hostBrowserContext.getClassLoader();
38 mChildProcessServiceImplClass =
39 classLoader.loadClass(CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME) ;
40 mChildProcessServiceImplInstance = mChildProcessServiceImplClass.new Instance();
41
42 Method createMethod = mChildProcessServiceImplClass.getMethod("creat e",
43 Context.class, Context.class);
44 createMethod.invoke(mChildProcessServiceImplInstance, getApplication Context(),
45 hostBrowserContext);
46 } catch (Exception e) {
47 Log.v(TAG, "Unable to create a ChildProcessServiceImpl for the WebAP K.", e);
48 }
49 }
50
51 @Override
52 public IBinder onBind(Intent intent) {
53 // We call stopSelf() to request that this service be stopped as soon as the client
54 // unbinds. Otherwise the system may keep it around and available for a reconnect. The
55 // child processes do not currently support reconnect; they must be init ialized from
56 // scratch every time.
57 stopSelf();
58 try {
59 Method bindMethod = mChildProcessServiceImplClass.getMethod(
60 "bind", Intent.class);
61 return (IBinder) bindMethod.invoke(mChildProcessServiceImplInstance, intent);
62 } catch (Exception e) {
63 Log.v(TAG, "Unable to bind to the WebApkSandboxedProcessService.", e );
64 }
65 return null;
66 }
67
68 @Override
69 public void onDestroy() {
70 super.onDestroy();
71 try {
72 Method destroyMethod = mChildProcessServiceImplClass.getMethod("dest roy");
73 destroyMethod.invoke(mChildProcessServiceImplInstance);
74 } catch (Exception e) {
75 Log.v(TAG, "Unable to destroy the WebApkSandboxedProcessService.", e );
76 }
77 }
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698