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