| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content_shell_apk; | 5 package org.chromium.content_shell_apk; |
| 6 | 6 |
| 7 import android.app.Service; | 7 import android.app.Service; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.os.Handler; | 9 import android.os.Handler; |
| 10 import android.os.HandlerThread; | 10 import android.os.HandlerThread; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 @Override | 62 @Override |
| 63 public IBinder onBind(Intent intent) { | 63 public IBinder onBind(Intent intent) { |
| 64 Messenger messenger = | 64 Messenger messenger = |
| 65 new Messenger(new Handler(mHandlerThread.getLooper(), mHandlerCa
llback)); | 65 new Messenger(new Handler(mHandlerThread.getLooper(), mHandlerCa
llback)); |
| 66 return messenger.getBinder(); | 66 return messenger.getBinder(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 private void doBindService(final Message msg) { | 69 private void doBindService(final Message msg) { |
| 70 String[] commandLine = { "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA
_DEBUGGER }; | 70 String[] commandLine = { "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA
_DEBUGGER }; |
| 71 ChildProcessCreationParams params = new ChildProcessCreationParams(getPa
ckageName(), false, | 71 final boolean bindToCaller = true; |
| 72 LibraryProcessType.PROCESS_CHILD); | 72 ChildProcessCreationParams params = new ChildProcessCreationParams( |
| 73 getPackageName(), false, LibraryProcessType.PROCESS_CHILD, bindT
oCaller); |
| 73 final ChildProcessConnection conn = ChildProcessLauncher.startForTesting
(this, commandLine, | 74 final ChildProcessConnection conn = ChildProcessLauncher.startForTesting
(this, commandLine, |
| 74 new FileDescriptorInfo[0], params); | 75 new FileDescriptorInfo[0], params); |
| 75 | 76 |
| 76 // Poll the connection until it is set up. The main test in ChildProcess
LauncherTest, which | 77 // Poll the connection until it is set up. The main test in ChildProcess
LauncherTest, which |
| 77 // has bound the connection to this service, manages the timeout via the
lifetime of this | 78 // has bound the connection to this service, manages the timeout via the
lifetime of this |
| 78 // service. | 79 // service. |
| 79 final Handler handler = new Handler(); | 80 final Handler handler = new Handler(); |
| 80 final Runnable task = new Runnable() { | 81 final Runnable task = new Runnable() { |
| 81 final Messenger mReplyTo = msg.replyTo; | 82 final Messenger mReplyTo = msg.replyTo; |
| 82 | 83 |
| 83 @Override | 84 @Override |
| 84 public void run() { | 85 public void run() { |
| 85 if (conn.getPid() != 0) { | 86 if (conn.getPid() != 0) { |
| 86 try { | 87 try { |
| 87 mReplyTo.send(Message.obtain(null, MSG_BIND_SERVICE_REPL
Y, conn.getPid(), | 88 mReplyTo.send(Message.obtain(null, MSG_BIND_SERVICE_REPL
Y, conn.getPid(), |
| 88 conn.getServiceNumber())); | 89 conn.getServiceNumber())); |
| 89 } catch (RemoteException ex) { | 90 } catch (RemoteException ex) { |
| 90 throw new RuntimeException(ex); | 91 throw new RuntimeException(ex); |
| 91 } | 92 } |
| 92 } else { | 93 } else { |
| 93 handler.postDelayed(this, 10 /* milliseconds */); | 94 handler.postDelayed(this, 10 /* milliseconds */); |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 }; | 97 }; |
| 97 handler.postDelayed(task, 10); | 98 handler.postDelayed(task, 10); |
| 98 } | 99 } |
| 99 } | 100 } |
| OLD | NEW |