OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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.base; | 5 package org.chromium.base; |
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.IBinder; | 10 import android.os.IBinder; |
11 import android.os.Process; | 11 import android.os.Process; |
12 | 12 |
13 import org.chromium.base.annotations.SuppressFBWarnings; | 13 import org.chromium.base.annotations.SuppressFBWarnings; |
14 import org.chromium.base.library_loader.LibraryLoader; | 14 import org.chromium.base.library_loader.LibraryLoader; |
15 import org.chromium.base.library_loader.LibraryProcessType; | 15 import org.chromium.base.library_loader.LibraryProcessType; |
16 import org.chromium.base.library_loader.ProcessInitException; | 16 import org.chromium.base.library_loader.ProcessInitException; |
| 17 import org.chromium.base.process_launcher.FileDescriptorInfo; |
17 import org.chromium.native_test.MainRunner; | 18 import org.chromium.native_test.MainRunner; |
18 | 19 |
19 import javax.annotation.concurrent.GuardedBy; | 20 import javax.annotation.concurrent.GuardedBy; |
20 | 21 |
21 /** | 22 /** |
22 * The service implementation used to host all multiprocess test client code. | 23 * The service implementation used to host all multiprocess test client code. |
23 */ | 24 */ |
24 public class MultiprocessTestClientService extends Service { | 25 public class MultiprocessTestClientService extends Service { |
25 private static final String TAG = "cr_TestClient"; | 26 private static final String TAG = "cr_TestClient"; |
26 | 27 |
27 private static boolean sAlreadyInitialized = false; | 28 private static boolean sAlreadyInitialized = false; |
28 | 29 |
29 private final Handler mHandler = new Handler(); | 30 private final Handler mHandler = new Handler(); |
30 | 31 |
31 private final Object mResultLock = new Object(); | 32 private final Object mResultLock = new Object(); |
32 | 33 |
33 @GuardedBy("mResultLock") | 34 @GuardedBy("mResultLock") |
34 private MainReturnCodeResult mResult; | 35 private MainReturnCodeResult mResult; |
35 | 36 |
36 private final ITestClient.Stub mBinder = new ITestClient.Stub() { | 37 private final ITestClient.Stub mBinder = new ITestClient.Stub() { |
37 @Override | 38 @Override |
38 public int launch(final String[] commandLine, FileDescriptorInfo[] fdsTo
Map) { | 39 public int launch(final String[] commandLine, FileDescriptorInfo[] fdsTo
Map) { |
39 final int[] fdKeys = new int[fdsToMap.length]; | 40 final int[] fdKeys = new int[fdsToMap.length]; |
40 final int[] fdFds = new int[fdsToMap.length]; | 41 final int[] fdFds = new int[fdsToMap.length]; |
41 for (int i = 0; i < fdsToMap.length; i++) { | 42 for (int i = 0; i < fdsToMap.length; i++) { |
42 fdKeys[i] = fdsToMap[i].key; | 43 fdKeys[i] = fdsToMap[i].id; |
43 // Take ownership of the file descriptor so they outlive the Fil
eDescriptorInfo | 44 // Take ownership of the file descriptor so they outlive the Fil
eDescriptorInfo |
44 // instances. Native code will own them. | 45 // instances. Native code will own them. |
45 fdFds[i] = fdsToMap[i].fd.detachFd(); | 46 fdFds[i] = fdsToMap[i].fd.detachFd(); |
46 } | 47 } |
47 // Don't run main directly, it would block and the response would no
t be returned. | 48 // Don't run main directly, it would block and the response would no
t be returned. |
48 // We post to the main thread as this thread does not have a Looper. | 49 // We post to the main thread as this thread does not have a Looper. |
49 mHandler.post(new Runnable() { | 50 mHandler.post(new Runnable() { |
50 @Override | 51 @Override |
51 public void run() { | 52 public void run() { |
52 int result = MainRunner.runMain(commandLine, fdKeys, fdFds); | 53 int result = MainRunner.runMain(commandLine, fdKeys, fdFds); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 mResultLock.notifyAll(); | 135 mResultLock.notifyAll(); |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 private static void markInitialized() { | 139 private static void markInitialized() { |
139 // We don't set sAlreadyInitialized directly in onCreate to avoid FindBu
gs complaining about | 140 // We don't set sAlreadyInitialized directly in onCreate to avoid FindBu
gs complaining about |
140 // a static member been set from a non-static function. | 141 // a static member been set from a non-static function. |
141 sAlreadyInitialized = true; | 142 sAlreadyInitialized = true; |
142 } | 143 } |
143 } | 144 } |
OLD | NEW |