Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 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; | |
|
Maria
2016/06/17 17:09:24
final on both objects above?
Xi Han
2016/06/17 18:35:19
These two objects are initialized in onCreate(), n
| |
| 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) ; | |
|
Maria
2016/06/17 17:09:24
Do we need all this reflection here because we wan
Xi Han
2016/06/17 18:35:19
We only use Chrome's class loader to load ChildPro
| |
| 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(); | |
|
Maria
2016/06/17 17:09:24
you can pass e as the third parameter to log and i
Xi Han
2016/06/17 18:35:19
Good catch, thanks!
| |
| 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 } | |
| OLD | NEW |