Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: base/test/android/multiprocess_test_client_service.cc

Issue 2549363004: Multiprocess test client: Android child process launcher rework. (Closed)
Patch Set: Removed unused include. Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_keys,
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> keys;
40 base::android::JavaIntArrayToIntVector(env, fds_to_map_keys, &keys);
41 std::vector<int> fds;
42 base::android::JavaIntArrayToIntVector(env, fds_to_map_fds, &fds);
43 CHECK(keys.size() == fds.size());
Robert Sesek 2016/12/22 23:21:54 nit: CHECK_EQ
Jay Civelli 2016/12/22 23:44:41 Done.
44
45 std::vector<base::ScopedFD> fd_scoped_fds;
Robert Sesek 2016/12/22 23:21:54 Unused variable.
Jay Civelli 2016/12/22 23:44:41 Done.
46 for (size_t i = 0; i < keys.size(); i++) {
47 base::GlobalDescriptors::GetInstance()->Set(keys[i], 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698