OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <vector> |
| 6 |
| 7 #include "base/android/jni_array.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/posix/global_descriptors.h" |
| 10 #include "jni/MainRunner_jni.h" |
| 11 |
| 12 extern int main(int argc, char** argv); |
| 13 |
| 14 namespace testing { |
| 15 namespace android { |
| 16 |
| 17 bool RegisterMainRunnerJni(JNIEnv* env) { |
| 18 return RegisterNativesImpl(env); |
| 19 } |
| 20 |
| 21 static jint RunMain( |
| 22 JNIEnv* env, |
| 23 const base::android::JavaParamRef<jclass>& jcaller, |
| 24 const base::android::JavaParamRef<jobjectArray>& command_line, |
| 25 const base::android::JavaParamRef<jintArray>& fds_to_map_keys, |
| 26 const base::android::JavaParamRef<jintArray>& fds_to_map_fds) { |
| 27 // Guards against process being reused. |
| 28 // In most cases, running main again will cause problems (static variables, |
| 29 // singletons, lazy instances won't be in the same state as a clean run). |
| 30 static bool alreadyRun = false; |
| 31 CHECK(!alreadyRun); |
| 32 alreadyRun = true; |
| 33 |
| 34 std::vector<int> keys; |
| 35 base::android::JavaIntArrayToIntVector(env, fds_to_map_keys, &keys); |
| 36 std::vector<int> fds; |
| 37 base::android::JavaIntArrayToIntVector(env, fds_to_map_fds, &fds); |
| 38 CHECK_EQ(keys.size(), fds.size()); |
| 39 |
| 40 for (size_t i = 0; i < keys.size(); i++) { |
| 41 base::GlobalDescriptors::GetInstance()->Set(keys[i], fds[i]); |
| 42 } |
| 43 |
| 44 std::vector<std::string> cpp_command_line; |
| 45 AppendJavaStringArrayToStringVector(env, command_line, &cpp_command_line); |
| 46 |
| 47 std::vector<char*> c_command_line; |
| 48 for (auto& entry : cpp_command_line) { |
| 49 c_command_line.push_back(&entry[0]); |
| 50 } |
| 51 |
| 52 return main(c_command_line.size(), &c_command_line[0]); |
| 53 } |
| 54 |
| 55 } // namespace android |
| 56 } // namespace testing |
OLD | NEW |