OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/test/multiprocess_test.h" | 5 #include "base/test/multiprocess_test.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 | 9 |
10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 #endif | 13 #endif |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 MultiProcessTest::MultiProcessTest() { | 17 MultiProcessTest::MultiProcessTest() { |
18 } | 18 } |
19 | 19 |
20 ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname, | 20 ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname, |
21 bool debug_on_start) { | 21 bool debug_on_start) { |
22 #if defined(OS_WIN) | |
23 return SpawnChildImpl(procname, debug_on_start); | |
24 #elif defined(OS_POSIX) | |
25 file_handle_mapping_vector empty_file_list; | 22 file_handle_mapping_vector empty_file_list; |
26 return SpawnChildImpl(procname, empty_file_list, debug_on_start); | 23 return SpawnChildImpl(procname, empty_file_list, debug_on_start); |
27 #endif | |
28 } | 24 } |
29 | 25 |
30 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
31 ProcessHandle MultiProcessTest::SpawnChild( | 27 ProcessHandle MultiProcessTest::SpawnChild( |
32 const std::string& procname, | 28 const std::string& procname, |
33 const file_handle_mapping_vector& fds_to_map, | 29 const file_handle_mapping_vector& fds_to_map, |
34 bool debug_on_start) { | 30 bool debug_on_start) { |
35 return SpawnChildImpl(procname, fds_to_map, debug_on_start); | 31 return SpawnChildImpl(procname, fds_to_map, debug_on_start); |
36 } | 32 } |
37 #endif | 33 #endif |
38 | 34 |
39 CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname, | 35 CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname, |
40 bool debug_on_start) { | 36 bool debug_on_start) { |
41 CommandLine cl(*CommandLine::ForCurrentProcess()); | 37 CommandLine cl(*CommandLine::ForCurrentProcess()); |
42 cl.AppendSwitchASCII(switches::kTestChildProcess, procname); | 38 cl.AppendSwitchASCII(switches::kTestChildProcess, procname); |
43 if (debug_on_start) | 39 if (debug_on_start) |
44 cl.AppendSwitch(switches::kDebugOnStart); | 40 cl.AppendSwitch(switches::kDebugOnStart); |
45 return cl; | 41 return cl; |
46 } | 42 } |
47 | 43 |
48 #if defined(OS_WIN) | |
49 | |
50 ProcessHandle MultiProcessTest::SpawnChildImpl(const std::string& procname, | |
51 bool debug_on_start) { | |
52 ProcessHandle handle = static_cast<ProcessHandle>(NULL); | |
53 LaunchApp(MakeCmdLine(procname, debug_on_start), | |
54 false, true, &handle); | |
55 return handle; | |
56 } | |
57 | |
58 #elif defined(OS_POSIX) | |
59 | |
60 // TODO(port): with the CommandLine refactoring, this code is very similar | |
61 // to the Windows code. Investigate whether this can be made shorter. | |
62 ProcessHandle MultiProcessTest::SpawnChildImpl( | 44 ProcessHandle MultiProcessTest::SpawnChildImpl( |
63 const std::string& procname, | 45 const std::string& procname, |
64 const file_handle_mapping_vector& fds_to_map, | 46 const file_handle_mapping_vector& fds_to_map, |
65 bool debug_on_start) { | 47 bool debug_on_start) { |
66 ProcessHandle handle = kNullProcessHandle; | 48 ProcessHandle handle = kNullProcessHandle; |
67 LaunchApp(MakeCmdLine(procname, debug_on_start).argv(), | 49 base::LaunchOptions options; |
68 fds_to_map, false, &handle); | 50 options.process_handle = &handle; |
| 51 #if defined(OS_WIN) |
| 52 options.start_hidden = true; |
| 53 #else |
| 54 options.fds_to_remap = &fds_to_map; |
| 55 #endif |
| 56 base::LaunchProcess(MakeCmdLine(procname, debug_on_start), options); |
69 return handle; | 57 return handle; |
70 } | 58 } |
71 | 59 |
72 #endif | |
73 | |
74 } // namespace base | 60 } // namespace base |
OLD | NEW |