| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "content/browser/browser_child_process_host_impl.h" | 12 #include "content/browser/browser_child_process_host_impl.h" |
| 13 #include "content/common/child_process_host_impl.h" | 13 #include "content/common/child_process_host_impl.h" |
| 14 #include "content/common/utility_messages.h" | 14 #include "content/common/utility_messages.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/browser/utility_process_host_client.h" | 16 #include "content/public/browser/utility_process_host_client.h" |
| 17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "ipc/ipc_switches.h" | 18 #include "ipc/ipc_switches.h" |
| 19 #include "ui/base/ui_base_switches.h" | 19 #include "ui/base/ui_base_switches.h" |
| 20 #include "webkit/plugins/plugin_switches.h" | 20 #include "webkit/plugins/plugin_switches.h" |
| 21 | 21 |
| 22 using content::BrowserThread; | |
| 23 using content::ChildProcessHost; | |
| 24 using content::UtilityProcessHostClient; | |
| 25 | |
| 26 namespace content { | 22 namespace content { |
| 27 | 23 |
| 28 UtilityProcessHost* UtilityProcessHost::Create( | 24 UtilityProcessHost* UtilityProcessHost::Create( |
| 29 UtilityProcessHostClient* client, | 25 UtilityProcessHostClient* client, |
| 30 BrowserThread::ID client_thread_id) { | 26 BrowserThread::ID client_thread_id) { |
| 31 return new UtilityProcessHostImpl(client, client_thread_id); | 27 return new UtilityProcessHostImpl(client, client_thread_id); |
| 32 } | 28 } |
| 33 | 29 |
| 34 } // namespace content | |
| 35 | |
| 36 UtilityProcessHostImpl::UtilityProcessHostImpl( | 30 UtilityProcessHostImpl::UtilityProcessHostImpl( |
| 37 UtilityProcessHostClient* client, | 31 UtilityProcessHostClient* client, |
| 38 BrowserThread::ID client_thread_id) | 32 BrowserThread::ID client_thread_id) |
| 39 : client_(client), | 33 : client_(client), |
| 40 client_thread_id_(client_thread_id), | 34 client_thread_id_(client_thread_id), |
| 41 is_batch_mode_(false), | 35 is_batch_mode_(false), |
| 42 no_sandbox_(false), | 36 no_sandbox_(false), |
| 43 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
| 44 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 38 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
| 45 #else | 39 #else |
| 46 child_flags_(ChildProcessHost::CHILD_NORMAL), | 40 child_flags_(ChildProcessHost::CHILD_NORMAL), |
| 47 #endif | 41 #endif |
| 48 use_linux_zygote_(false), | 42 use_linux_zygote_(false), |
| 49 started_(false) { | 43 started_(false) { |
| 50 process_.reset( | 44 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); |
| 51 new BrowserChildProcessHostImpl(content::PROCESS_TYPE_UTILITY, this)); | |
| 52 } | 45 } |
| 53 | 46 |
| 54 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 47 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 56 DCHECK(!is_batch_mode_); | 49 DCHECK(!is_batch_mode_); |
| 57 } | 50 } |
| 58 | 51 |
| 59 bool UtilityProcessHostImpl::Send(IPC::Message* message) { | 52 bool UtilityProcessHostImpl::Send(IPC::Message* message) { |
| 60 if (!StartProcess()) | 53 if (!StartProcess()) |
| 61 return false; | 54 return false; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 123 FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
| 131 if (exe_path.empty()) { | 124 if (exe_path.empty()) { |
| 132 NOTREACHED() << "Unable to get utility process binary name."; | 125 NOTREACHED() << "Unable to get utility process binary name."; |
| 133 return false; | 126 return false; |
| 134 } | 127 } |
| 135 | 128 |
| 136 CommandLine* cmd_line = new CommandLine(exe_path); | 129 CommandLine* cmd_line = new CommandLine(exe_path); |
| 137 cmd_line->AppendSwitchASCII(switches::kProcessType, | 130 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 138 switches::kUtilityProcess); | 131 switches::kUtilityProcess); |
| 139 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 132 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 140 std::string locale = | 133 std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
| 141 content::GetContentClient()->browser()->GetApplicationLocale(); | |
| 142 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 134 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
| 143 | 135 |
| 144 if (browser_command_line.HasSwitch(switches::kChromeFrame)) | 136 if (browser_command_line.HasSwitch(switches::kChromeFrame)) |
| 145 cmd_line->AppendSwitch(switches::kChromeFrame); | 137 cmd_line->AppendSwitch(switches::kChromeFrame); |
| 146 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) | 138 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) |
| 147 cmd_line->AppendSwitch(switches::kNoSandbox); | 139 cmd_line->AppendSwitch(switches::kNoSandbox); |
| 148 #if defined(OS_MACOSX) | 140 #if defined(OS_MACOSX) |
| 149 if (browser_command_line.HasSwitch(switches::kEnableSandboxLogging)) | 141 if (browser_command_line.HasSwitch(switches::kEnableSandboxLogging)) |
| 150 cmd_line->AppendSwitch(switches::kEnableSandboxLogging); | 142 cmd_line->AppendSwitch(switches::kEnableSandboxLogging); |
| 151 #endif | 143 #endif |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 message)); | 183 message)); |
| 192 return true; | 184 return true; |
| 193 } | 185 } |
| 194 | 186 |
| 195 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 187 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
| 196 BrowserThread::PostTask( | 188 BrowserThread::PostTask( |
| 197 client_thread_id_, FROM_HERE, | 189 client_thread_id_, FROM_HERE, |
| 198 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 190 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
| 199 exit_code)); | 191 exit_code)); |
| 200 } | 192 } |
| 193 |
| 194 } // namespace content |
| OLD | NEW |