| OLD | NEW |
| 1 // Copyright (c) 2011 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 "content/browser/utility_process_host.h" | 5 #include "content/browser/utility_process_host.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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 UtilityProcessHost::UtilityProcessHost(Client* client, | 37 UtilityProcessHost::UtilityProcessHost(Client* client, |
| 38 BrowserThread::ID client_thread_id) | 38 BrowserThread::ID client_thread_id) |
| 39 : BrowserChildProcessHost(content::PROCESS_TYPE_UTILITY), | 39 : BrowserChildProcessHost(content::PROCESS_TYPE_UTILITY), |
| 40 client_(client), | 40 client_(client), |
| 41 client_thread_id_(client_thread_id), | 41 client_thread_id_(client_thread_id), |
| 42 is_batch_mode_(false), | 42 is_batch_mode_(false), |
| 43 no_sandbox_(false), | 43 no_sandbox_(false), |
| 44 #if defined(OS_LINUX) | 44 #if defined(OS_LINUX) |
| 45 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 45 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
| 46 use_linux_zygote_(true), |
| 46 #else | 47 #else |
| 47 child_flags_(ChildProcessHost::CHILD_NORMAL), | 48 child_flags_(ChildProcessHost::CHILD_NORMAL), |
| 49 use_linux_zygote_(false), |
| 48 #endif | 50 #endif |
| 49 started_(false) { | 51 started_(false) { |
| 50 } | 52 } |
| 51 | 53 |
| 52 UtilityProcessHost::~UtilityProcessHost() { | 54 UtilityProcessHost::~UtilityProcessHost() { |
| 53 DCHECK(!is_batch_mode_); | 55 DCHECK(!is_batch_mode_); |
| 54 } | 56 } |
| 55 | 57 |
| 56 bool UtilityProcessHost::Send(IPC::Message* message) { | 58 bool UtilityProcessHost::Send(IPC::Message* message) { |
| 57 if (!StartProcess()) | 59 if (!StartProcess()) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 110 |
| 109 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 111 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 110 if (browser_command_line.HasSwitch(switches::kChromeFrame)) | 112 if (browser_command_line.HasSwitch(switches::kChromeFrame)) |
| 111 cmd_line->AppendSwitch(switches::kChromeFrame); | 113 cmd_line->AppendSwitch(switches::kChromeFrame); |
| 112 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) | 114 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) |
| 113 cmd_line->AppendSwitch(switches::kNoSandbox); | 115 cmd_line->AppendSwitch(switches::kNoSandbox); |
| 114 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading)) | 116 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading)) |
| 115 cmd_line->AppendSwitch(switches::kDebugPluginLoading); | 117 cmd_line->AppendSwitch(switches::kDebugPluginLoading); |
| 116 | 118 |
| 117 #if defined(OS_POSIX) | 119 #if defined(OS_POSIX) |
| 118 // TODO(port): Sandbox this on Linux. Also, zygote this to work with | 120 // TODO(port): Sandbox extension unpacking on Linux. |
| 119 // Linux updating. | |
| 120 bool has_cmd_prefix = browser_command_line.HasSwitch( | 121 bool has_cmd_prefix = browser_command_line.HasSwitch( |
| 121 switches::kUtilityCmdPrefix); | 122 switches::kUtilityCmdPrefix); |
| 122 if (has_cmd_prefix) { | 123 if (has_cmd_prefix) { |
| 123 // launch the utility child process with some prefix (usually "xterm -e gdb | 124 // launch the utility child process with some prefix (usually "xterm -e gdb |
| 124 // --args"). | 125 // --args"). |
| 125 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( | 126 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( |
| 126 switches::kUtilityCmdPrefix)); | 127 switches::kUtilityCmdPrefix)); |
| 127 } | 128 } |
| 128 | 129 |
| 129 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir_); | 130 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir_); |
| 130 #endif | 131 #endif |
| 131 | 132 |
| 133 bool use_zygote = false; |
| 134 |
| 135 #if defined(OS_LINUX) |
| 136 use_zygote = !no_sandbox_ && use_linux_zygote_; |
| 137 #endif |
| 138 |
| 132 Launch( | 139 Launch( |
| 133 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
| 134 exposed_dir_, | 141 exposed_dir_, |
| 135 #elif defined(OS_POSIX) | 142 #elif defined(OS_POSIX) |
| 136 false, | 143 use_zygote, |
| 137 env_, | 144 env_, |
| 138 #endif | 145 #endif |
| 139 cmd_line); | 146 cmd_line); |
| 140 | 147 |
| 141 return true; | 148 return true; |
| 142 } | 149 } |
| 143 | 150 |
| 144 bool UtilityProcessHost::OnMessageReceived(const IPC::Message& message) { | 151 bool UtilityProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 145 BrowserThread::PostTask( | 152 BrowserThread::PostTask( |
| 146 client_thread_id_, FROM_HERE, | 153 client_thread_id_, FROM_HERE, |
| 147 base::IgnoreReturn<bool>( | 154 base::IgnoreReturn<bool>( |
| 148 base::Bind(&Client::OnMessageReceived, client_.get(), message))); | 155 base::Bind(&Client::OnMessageReceived, client_.get(), message))); |
| 149 return true; | 156 return true; |
| 150 } | 157 } |
| 151 | 158 |
| 152 void UtilityProcessHost::OnProcessCrashed(int exit_code) { | 159 void UtilityProcessHost::OnProcessCrashed(int exit_code) { |
| 153 BrowserThread::PostTask( | 160 BrowserThread::PostTask( |
| 154 client_thread_id_, FROM_HERE, | 161 client_thread_id_, FROM_HERE, |
| 155 base::Bind(&Client::OnProcessCrashed, client_.get(), exit_code)); | 162 base::Bind(&Client::OnProcessCrashed, client_.get(), exit_code)); |
| 156 } | 163 } |
| OLD | NEW |