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

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: Clean up. 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 an
pkotwicz 2016/06/15 17:51:00 Nit: an -> a
17 * {@link ChildProcessServiceImpl} object which loads Chrome's native libraries, initializes JNI
18 * 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.
19 */
20 public class WebApkSandboxedProcessService extends Service {
21 private static final String CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME =
22 "org.chromium.content.app.ChildProcessServiceImpl";
23 private static final String TAG = "cr_WebApkSandboxedProcessService";
24
25 private Class<?> mChildProcessServiceImplClass;
26 private Object mChildProcessServiceImplInstance;
27
28 @Override
29 public void onCreate() {
30 super.onCreate();
31
32 try {
33 Context hostBrowserContext =
34 WebApkUtils.getHostBrowserContext(getApplicationContext());
35 ClassLoader classLoader = hostBrowserContext.getClassLoader();
36 mChildProcessServiceImplClass =
37 classLoader.loadClass(CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME) ;
38 mChildProcessServiceImplInstance = mChildProcessServiceImplClass.new Instance();
39
40 Method createMethod = mChildProcessServiceImplClass.getMethod("creat e",
41 Context.class, Context.class);
42 createMethod.invoke(mChildProcessServiceImplInstance, getApplication Context(),
43 hostBrowserContext);
44 } catch (Exception e) {
45 Log.d(TAG, "Unable to create a ChildProcessServiceImpl for the WebAP K.");
46 e.printStackTrace();
47 }
48 }
49
50 @Override
51 public IBinder onBind(Intent intent) {
52 // We call stopSelf() to request that this service be stopped as soon as the client
53 // unbinds. Otherwise the system may keep it around and available for a reconnect. The
54 // child processes do not currently support reconnect; they must be init ialized from
55 // scratch every time.
56 stopSelf();
57 try {
58 Method bindMethod = mChildProcessServiceImplClass.getMethod(
59 "bind", Intent.class);
60 return (IBinder) bindMethod.invoke(mChildProcessServiceImplInstance, intent);
61 } catch (Exception e) {
62 Log.d(TAG, "Unable to bind to the WebApkSandboxedProcessService.");
63 e.printStackTrace();
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.d(TAG, "Unable to destroy the WebApkSandboxedProcessService.");
76 e.printStackTrace();
77 }
78 }
79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698