OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/utility_process_host_impl.h" | 5 #include "content/browser/utility_process_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (is_batch_mode_) | 104 if (is_batch_mode_) |
105 return true; | 105 return true; |
106 // Name must be set or metrics_service will crash in any test which | 106 // Name must be set or metrics_service will crash in any test which |
107 // launches a UtilityProcessHost. | 107 // launches a UtilityProcessHost. |
108 process_->SetName(ASCIIToUTF16("utility process")); | 108 process_->SetName(ASCIIToUTF16("utility process")); |
109 | 109 |
110 std::string channel_id = process_->GetHost()->CreateChannel(); | 110 std::string channel_id = process_->GetHost()->CreateChannel(); |
111 if (channel_id.empty()) | 111 if (channel_id.empty()) |
112 return false; | 112 return false; |
113 | 113 |
114 FilePath exe_path = ChildProcessHost::GetChildPath(child_flags_); | 114 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 115 int child_flags = child_flags_; |
| 116 |
| 117 #if defined(OS_POSIX) |
| 118 bool has_cmd_prefix = browser_command_line.HasSwitch( |
| 119 switches::kUtilityCmdPrefix); |
| 120 |
| 121 // When running under gdb, forking /proc/self/exe ends up forking the gdb |
| 122 // executable instead of Chromium. It is almost safe to assume that no |
| 123 // updates will happen while a developer is running with |
| 124 // |switches::kUtilityCmdPrefix|. See ChildProcessHost::GetChildPath() for |
| 125 // a similar case with Valgrind. |
| 126 if (has_cmd_prefix) |
| 127 child_flags = ChildProcessHost::CHILD_NORMAL; |
| 128 #endif |
| 129 |
| 130 FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
115 if (exe_path.empty()) { | 131 if (exe_path.empty()) { |
116 NOTREACHED() << "Unable to get utility process binary name."; | 132 NOTREACHED() << "Unable to get utility process binary name."; |
117 return false; | 133 return false; |
118 } | 134 } |
119 | 135 |
120 CommandLine* cmd_line = new CommandLine(exe_path); | 136 CommandLine* cmd_line = new CommandLine(exe_path); |
121 cmd_line->AppendSwitchASCII(switches::kProcessType, | 137 cmd_line->AppendSwitchASCII(switches::kProcessType, |
122 switches::kUtilityProcess); | 138 switches::kUtilityProcess); |
123 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 139 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
124 std::string locale = | 140 std::string locale = |
125 content::GetContentClient()->browser()->GetApplicationLocale(); | 141 content::GetContentClient()->browser()->GetApplicationLocale(); |
126 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 142 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
127 | 143 |
128 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | |
129 if (browser_command_line.HasSwitch(switches::kChromeFrame)) | 144 if (browser_command_line.HasSwitch(switches::kChromeFrame)) |
130 cmd_line->AppendSwitch(switches::kChromeFrame); | 145 cmd_line->AppendSwitch(switches::kChromeFrame); |
131 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) | 146 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) |
132 cmd_line->AppendSwitch(switches::kNoSandbox); | 147 cmd_line->AppendSwitch(switches::kNoSandbox); |
133 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading)) | 148 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading)) |
134 cmd_line->AppendSwitch(switches::kDebugPluginLoading); | 149 cmd_line->AppendSwitch(switches::kDebugPluginLoading); |
135 | 150 |
136 #if defined(OS_POSIX) | 151 #if defined(OS_POSIX) |
137 // TODO(port): Sandbox this on Linux. Also, zygote this to work with | 152 // TODO(port): Sandbox this on Linux. Also, zygote this to work with |
138 // Linux updating. | 153 // Linux updating. |
139 bool has_cmd_prefix = browser_command_line.HasSwitch( | |
140 switches::kUtilityCmdPrefix); | |
141 if (has_cmd_prefix) { | 154 if (has_cmd_prefix) { |
142 // launch the utility child process with some prefix (usually "xterm -e gdb | 155 // launch the utility child process with some prefix (usually "xterm -e gdb |
143 // --args"). | 156 // --args"). |
144 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( | 157 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( |
145 switches::kUtilityCmdPrefix)); | 158 switches::kUtilityCmdPrefix)); |
146 } | 159 } |
147 | 160 |
148 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir_); | 161 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir_); |
149 #endif | 162 #endif |
150 | 163 |
(...skipping 23 matching lines...) Expand all Loading... |
174 message)); | 187 message)); |
175 return true; | 188 return true; |
176 } | 189 } |
177 | 190 |
178 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 191 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
179 BrowserThread::PostTask( | 192 BrowserThread::PostTask( |
180 client_thread_id_, FROM_HERE, | 193 client_thread_id_, FROM_HERE, |
181 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 194 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
182 exit_code)); | 195 exit_code)); |
183 } | 196 } |
OLD | NEW |