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 #include "base/test/android/multiprocess_test_client_service.h" |
| 6 |
| 7 #include "base/android/jni_array.h" |
| 8 #include "base/files/scoped_file.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/native_library.h" |
| 11 #include "base/posix/global_descriptors.h" |
| 12 #include "jni/MultiprocessTestClientService_jni.h" |
| 13 |
| 14 extern int main(int argc, char** argv); |
| 15 |
| 16 namespace base { |
| 17 namespace android { |
| 18 |
| 19 bool RegisterMultiprocessTestClientServiceJni(JNIEnv* env) { |
| 20 return RegisterNativesImpl(env); |
| 21 } |
| 22 |
| 23 // static |
| 24 void RunMain(JNIEnv* env, |
| 25 const base::android::JavaParamRef<_jobject*>& jcaller, |
| 26 const base::android::JavaParamRef<jobjectArray>& command_line, |
| 27 const base::android::JavaParamRef<jintArray>& fds_to_map_ids, |
| 28 const base::android::JavaParamRef<jintArray>& fds_to_map_fds) { |
| 29 // Guards against process being reused. |
| 30 // Static variables, singletons, lazy instances make running code again in the |
| 31 // same child process difficult. |
| 32 static bool alreadyRun = false; |
| 33 CHECK(!alreadyRun); |
| 34 alreadyRun = true; |
| 35 |
| 36 std::vector<std::string> cpp_command_line; |
| 37 AppendJavaStringArrayToStringVector(env, command_line, &cpp_command_line); |
| 38 |
| 39 std::vector<int> fd_ids; |
| 40 base::android::JavaIntArrayToIntVector(env, fds_to_map_ids, &fd_ids); |
| 41 std::vector<int> fd_fds; |
| 42 base::android::JavaIntArrayToIntVector(env, fds_to_map_fds, &fd_fds); |
| 43 CHECK(fd_ids.size() == fd_fds.size()); |
| 44 |
| 45 std::vector<base::ScopedFD> fd_scoped_fds; |
| 46 for (size_t i = 0; i < fd_ids.size(); i++) { |
| 47 base::GlobalDescriptors::GetInstance()->Set(fd_ids[i], fd_fds[i]); |
| 48 } |
| 49 std::vector<char*> c_command_line; |
| 50 for (auto& entry : cpp_command_line) { |
| 51 c_command_line.push_back(&entry[0]); |
| 52 } |
| 53 |
| 54 int result = main(c_command_line.size(), &c_command_line[0]); |
| 55 |
| 56 Java_MultiprocessTestClientService_setMainReturnValue(env, jcaller, result); |
| 57 } |
| 58 |
| 59 } // namespace android |
| 60 } // namespace base |
OLD | NEW |