| 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; |
| 11 import android.os.IBinder; | 11 import android.os.IBinder; |
| 12 import android.os.Message; | 12 import android.os.Message; |
| 13 import android.os.Messenger; | 13 import android.os.Messenger; |
| 14 import android.os.RemoteException; | 14 import android.os.RemoteException; |
| 15 | 15 |
| 16 import org.chromium.base.BaseSwitches; | 16 import org.chromium.base.BaseSwitches; |
| 17 import org.chromium.base.CommandLine; | 17 import org.chromium.base.CommandLine; |
| 18 import org.chromium.base.library_loader.LibraryLoader; | 18 import org.chromium.base.library_loader.LibraryLoader; |
| 19 import org.chromium.base.library_loader.LibraryProcessType; | 19 import org.chromium.base.library_loader.LibraryProcessType; |
| 20 import org.chromium.base.library_loader.ProcessInitException; | 20 import org.chromium.base.library_loader.ProcessInitException; |
| 21 import org.chromium.base.process_launcher.ChildProcessCreationParams; | 21 import org.chromium.base.process_launcher.ChildProcessCreationParams; |
| 22 import org.chromium.base.process_launcher.FileDescriptorInfo; | 22 import org.chromium.base.process_launcher.FileDescriptorInfo; |
| 23 import org.chromium.content.browser.ChildProcessConnection; | 23 import org.chromium.content.browser.ChildProcessConnection; |
| 24 import org.chromium.content.browser.ChildProcessLauncherHelper; |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * A Service that assists the ChildProcessLauncherTest that responds to one mess
age, which | 27 * A Service that assists the ChildProcessLauncherTest that responds to one mess
age, which |
| 27 * starts a sandboxed service process via the ChildProcessLauncher. This is requ
ired to test | 28 * starts a sandboxed service process via the ChildProcessLauncher. This is requ
ired to test |
| 28 * the behavior when two independent processes in the same package try and bind
to the same | 29 * the behavior when two independent processes in the same package try and bind
to the same |
| 29 * sandboxed service process. | 30 * sandboxed service process. |
| 30 */ | 31 */ |
| 31 public class ChildProcessLauncherTestHelperService extends Service { | 32 public class ChildProcessLauncherTestHelperService extends Service { |
| 32 public static final int MSG_BIND_SERVICE = IBinder.FIRST_CALL_TRANSACTION +
1; | 33 public static final int MSG_BIND_SERVICE = IBinder.FIRST_CALL_TRANSACTION +
1; |
| 33 public static final int MSG_BIND_SERVICE_REPLY = MSG_BIND_SERVICE + 1; | 34 public static final int MSG_BIND_SERVICE_REPLY = MSG_BIND_SERVICE + 1; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 63 Messenger messenger = | 64 Messenger messenger = |
| 64 new Messenger(new Handler(mHandlerThread.getLooper(), mHandlerCa
llback)); | 65 new Messenger(new Handler(mHandlerThread.getLooper(), mHandlerCa
llback)); |
| 65 return messenger.getBinder(); | 66 return messenger.getBinder(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 private void doBindService(final Message msg) { | 69 private void doBindService(final Message msg) { |
| 69 String[] commandLine = { "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA
_DEBUGGER }; | 70 String[] commandLine = { "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA
_DEBUGGER }; |
| 70 final boolean bindToCaller = true; | 71 final boolean bindToCaller = true; |
| 71 ChildProcessCreationParams params = new ChildProcessCreationParams( | 72 ChildProcessCreationParams params = new ChildProcessCreationParams( |
| 72 getPackageName(), false, LibraryProcessType.PROCESS_CHILD, bindT
oCaller); | 73 getPackageName(), false, LibraryProcessType.PROCESS_CHILD, bindT
oCaller); |
| 73 final ChildProcessConnection conn = ChildProcessLauncherTestUtils.startI
nternalForTesting( | 74 final ChildProcessLauncherHelper processLauncher = |
| 74 this, commandLine, new FileDescriptorInfo[0], params); | 75 ChildProcessLauncherTestUtils.startForTesting( |
| 76 this, commandLine, new FileDescriptorInfo[0], params); |
| 75 | 77 |
| 76 // Poll the connection until it is set up. The main test in ChildProcess
LauncherTest, which | 78 // Poll the launcher until the connection is set up. The main test in |
| 77 // has bound the connection to this service, manages the timeout via the
lifetime of this | 79 // ChildProcessLauncherTest, which has bound the connection to this serv
ice, manages the |
| 78 // service. | 80 // timeout via the lifetime of this service. |
| 79 final Handler handler = new Handler(); | 81 final Handler handler = new Handler(); |
| 80 final Runnable task = new Runnable() { | 82 final Runnable task = new Runnable() { |
| 81 final Messenger mReplyTo = msg.replyTo; | 83 final Messenger mReplyTo = msg.replyTo; |
| 82 | 84 |
| 83 @Override | 85 @Override |
| 84 public void run() { | 86 public void run() { |
| 85 int pid = ChildProcessLauncherTestUtils.getConnectionPid(conn); | 87 ChildProcessConnection conn = processLauncher.getChildProcessCon
nection(); |
| 86 if (pid != 0) { | 88 if (conn != null) { |
| 89 int pid = ChildProcessLauncherTestUtils.getConnectionPid(con
n); |
| 90 assert pid != 0; |
| 87 try { | 91 try { |
| 88 mReplyTo.send(Message.obtain(null, MSG_BIND_SERVICE_REPL
Y, pid, | 92 mReplyTo.send(Message.obtain(null, MSG_BIND_SERVICE_REPL
Y, pid, |
| 89 ChildProcessLauncherTestUtils.getConnectionServi
ceNumber(conn))); | 93 ChildProcessLauncherTestUtils.getConnectionServi
ceNumber(conn))); |
| 90 } catch (RemoteException ex) { | 94 } catch (RemoteException ex) { |
| 91 throw new RuntimeException(ex); | 95 throw new RuntimeException(ex); |
| 92 } | 96 } |
| 93 } else { | 97 } else { |
| 94 handler.postDelayed(this, 10 /* milliseconds */); | 98 handler.postDelayed(this, 10 /* milliseconds */); |
| 95 } | 99 } |
| 96 } | 100 } |
| 97 }; | 101 }; |
| 98 handler.postDelayed(task, 10); | 102 handler.postDelayed(task, 10); |
| 99 } | 103 } |
| 100 } | 104 } |
| OLD | NEW |