OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef BASE_MULTIPROCESS_TEST_H__ | 5 #ifndef BASE_MULTIPROCESS_TEST_H__ |
6 #define BASE_MULTIPROCESS_TEST_H__ | 6 #define BASE_MULTIPROCESS_TEST_H__ |
7 | 7 |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 #endif | 74 #endif |
75 } | 75 } |
76 | 76 |
77 #if defined(OS_POSIX) | 77 #if defined(OS_POSIX) |
78 base::ProcessHandle SpawnChild( | 78 base::ProcessHandle SpawnChild( |
79 const std::wstring& procname, | 79 const std::wstring& procname, |
80 const base::file_handle_mapping_vector& fds_to_map, | 80 const base::file_handle_mapping_vector& fds_to_map, |
81 bool debug_on_start) { | 81 bool debug_on_start) { |
82 return SpawnChildImpl(procname, fds_to_map, debug_on_start); | 82 return SpawnChildImpl(procname, fds_to_map, debug_on_start); |
83 } | 83 } |
84 | |
85 #endif | 84 #endif |
86 | 85 |
87 private: | 86 private: |
88 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
89 base::ProcessHandle SpawnChildImpl( | 88 base::ProcessHandle SpawnChildImpl( |
90 const std::wstring& procname, | 89 const std::wstring& procname, |
91 bool debug_on_start) { | 90 bool debug_on_start) { |
92 CommandLine cl; | 91 CommandLine cl(*CommandLine::ForCurrentProcess()); |
93 base::ProcessHandle handle = static_cast<base::ProcessHandle>(NULL); | 92 base::ProcessHandle handle = static_cast<base::ProcessHandle>(NULL); |
94 std::wstring clstr = cl.command_line_string(); | 93 cl.AppendSwitchWithValue(kRunClientProcess, procname); |
95 CommandLine::AppendSwitchWithValue(&clstr, kRunClientProcess, procname); | |
96 | 94 |
97 if (debug_on_start) { | 95 if (debug_on_start) |
98 CommandLine::AppendSwitch(&clstr, switches::kDebugOnStart); | 96 cl.AppendSwitch(switches::kDebugOnStart); |
99 } | |
100 | 97 |
101 base::LaunchApp(clstr, false, true, &handle); | 98 base::LaunchApp(cl, false, true, &handle); |
102 return handle; | 99 return handle; |
103 } | 100 } |
104 #elif defined(OS_POSIX) | 101 #elif defined(OS_POSIX) |
| 102 // TODO(port): with the CommandLine refactoring, this code is very similar |
| 103 // to the Windows code. Investigate whether this can be made shorter. |
105 base::ProcessHandle SpawnChildImpl( | 104 base::ProcessHandle SpawnChildImpl( |
106 const std::wstring& procname, | 105 const std::wstring& procname, |
107 const base::file_handle_mapping_vector& fds_to_map, | 106 const base::file_handle_mapping_vector& fds_to_map, |
108 bool debug_on_start) { | 107 bool debug_on_start) { |
109 CommandLine cl; | 108 CommandLine cl(*CommandLine::ForCurrentProcess()); |
110 base::ProcessHandle handle = static_cast<base::ProcessHandle>(NULL); | 109 base::ProcessHandle handle = static_cast<base::ProcessHandle>(NULL); |
| 110 cl.AppendSwitchWithValue(kRunClientProcess, procname); |
111 | 111 |
112 std::vector<std::string> clvec(cl.argv()); | 112 if (debug_on_start) |
113 std::wstring wswitchstr = | 113 cl.AppendSwitch(switches::kDebugOnStart); |
114 CommandLine::PrefixedSwitchStringWithValue(kRunClientProcess, | |
115 procname); | |
116 if (debug_on_start) { | |
117 CommandLine::AppendSwitch(&wswitchstr, switches::kDebugOnStart); | |
118 } | |
119 | 114 |
120 std::string switchstr = WideToUTF8(wswitchstr); | 115 base::LaunchApp(cl.argv(), fds_to_map, false, &handle); |
121 clvec.push_back(switchstr.c_str()); | |
122 base::LaunchApp(clvec, fds_to_map, false, &handle); | |
123 return handle; | 116 return handle; |
124 } | 117 } |
125 #endif | 118 #endif |
126 }; | 119 }; |
127 | 120 |
128 #endif // BASE_MULTIPROCESS_TEST_H__ | 121 #endif // BASE_MULTIPROCESS_TEST_H__ |
OLD | NEW |