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