| 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/child/child_thread_impl.h" | 5 #include "content/child/child_thread_impl.h" |
| 6 | 6 |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "content/child/thread_safe_sender.h" | 49 #include "content/child/thread_safe_sender.h" |
| 50 #include "content/child/websocket_dispatcher.h" | 50 #include "content/child/websocket_dispatcher.h" |
| 51 #include "content/common/child_process_messages.h" | 51 #include "content/common/child_process_messages.h" |
| 52 #include "content/common/in_process_child_thread_params.h" | 52 #include "content/common/in_process_child_thread_params.h" |
| 53 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
| 54 #include "ipc/ipc_logging.h" | 54 #include "ipc/ipc_logging.h" |
| 55 #include "ipc/ipc_switches.h" | 55 #include "ipc/ipc_switches.h" |
| 56 #include "ipc/ipc_sync_channel.h" | 56 #include "ipc/ipc_sync_channel.h" |
| 57 #include "ipc/ipc_sync_message_filter.h" | 57 #include "ipc/ipc_sync_message_filter.h" |
| 58 #include "ipc/mojo/ipc_channel_mojo.h" | 58 #include "ipc/mojo/ipc_channel_mojo.h" |
| 59 #include "ipc/mojo/scoped_ipc_support.h" | |
| 60 | 59 |
| 61 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 62 #include "content/common/handle_enumerator_win.h" | 61 #include "content/common/handle_enumerator_win.h" |
| 63 #endif | 62 #endif |
| 64 | 63 |
| 65 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 64 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
| 66 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 65 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
| 67 #endif | 66 #endif |
| 68 | 67 |
| 69 using tracked_objects::ThreadData; | 68 using tracked_objects::ThreadData; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 197 } |
| 199 | 198 |
| 200 #endif | 199 #endif |
| 201 | 200 |
| 202 } // namespace | 201 } // namespace |
| 203 | 202 |
| 204 ChildThread* ChildThread::Get() { | 203 ChildThread* ChildThread::Get() { |
| 205 return ChildThreadImpl::current(); | 204 return ChildThreadImpl::current(); |
| 206 } | 205 } |
| 207 | 206 |
| 208 // Mojo client channel delegate to be used in single process mode. | |
| 209 class ChildThreadImpl::SingleProcessChannelDelegate | |
| 210 : public IPC::ChannelMojo::Delegate { | |
| 211 public: | |
| 212 explicit SingleProcessChannelDelegate( | |
| 213 scoped_refptr<base::SequencedTaskRunner> io_runner) | |
| 214 : io_runner_(io_runner), weak_factory_(this) {} | |
| 215 | |
| 216 ~SingleProcessChannelDelegate() override {} | |
| 217 | |
| 218 base::WeakPtr<IPC::ChannelMojo::Delegate> ToWeakPtr() override { | |
| 219 return weak_factory_.GetWeakPtr(); | |
| 220 } | |
| 221 | |
| 222 scoped_refptr<base::TaskRunner> GetIOTaskRunner() override { | |
| 223 return io_runner_; | |
| 224 } | |
| 225 | |
| 226 void OnChannelCreated(base::WeakPtr<IPC::ChannelMojo> channel) override {} | |
| 227 | |
| 228 void DeleteSoon() { | |
| 229 io_runner_->PostTask( | |
| 230 FROM_HERE, | |
| 231 base::Bind(&base::DeletePointer<SingleProcessChannelDelegate>, | |
| 232 base::Unretained(this))); | |
| 233 } | |
| 234 | |
| 235 private: | |
| 236 scoped_refptr<base::SequencedTaskRunner> io_runner_; | |
| 237 base::WeakPtrFactory<IPC::ChannelMojo::Delegate> weak_factory_; | |
| 238 | |
| 239 DISALLOW_COPY_AND_ASSIGN(SingleProcessChannelDelegate); | |
| 240 }; | |
| 241 | |
| 242 void ChildThreadImpl::SingleProcessChannelDelegateDeleter::operator()( | |
| 243 SingleProcessChannelDelegate* delegate) const { | |
| 244 delegate->DeleteSoon(); | |
| 245 } | |
| 246 | |
| 247 ChildThreadImpl::Options::Options() | 207 ChildThreadImpl::Options::Options() |
| 248 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 208 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 249 switches::kProcessChannelID)), | 209 switches::kProcessChannelID)), |
| 250 use_mojo_channel(false) { | 210 use_mojo_channel(false) { |
| 251 } | 211 } |
| 252 | 212 |
| 253 ChildThreadImpl::Options::~Options() { | 213 ChildThreadImpl::Options::~Options() { |
| 254 } | 214 } |
| 255 | 215 |
| 256 ChildThreadImpl::Options::Builder::Builder() { | 216 ChildThreadImpl::Options::Builder::Builder() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 return browser_process_io_runner_; | 274 return browser_process_io_runner_; |
| 315 return ChildProcess::current()->io_message_loop_proxy(); | 275 return ChildProcess::current()->io_message_loop_proxy(); |
| 316 } | 276 } |
| 317 | 277 |
| 318 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 278 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
| 319 bool create_pipe_now = true; | 279 bool create_pipe_now = true; |
| 320 if (use_mojo_channel) { | 280 if (use_mojo_channel) { |
| 321 VLOG(1) << "Mojo is enabled on child"; | 281 VLOG(1) << "Mojo is enabled on child"; |
| 322 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); | 282 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); |
| 323 DCHECK(io_task_runner); | 283 DCHECK(io_task_runner); |
| 324 if (IsInBrowserProcess()) | 284 channel_->Init(IPC::ChannelMojo::CreateClientFactory( |
| 325 single_process_channel_delegate_.reset( | 285 nullptr, io_task_runner, channel_name_), |
| 326 new SingleProcessChannelDelegate(io_task_runner)); | 286 create_pipe_now); |
| 327 ipc_support_.reset(new IPC::ScopedIPCSupport(io_task_runner)); | |
| 328 channel_->Init( | |
| 329 IPC::ChannelMojo::CreateClientFactory( | |
| 330 single_process_channel_delegate_.get(), | |
| 331 channel_name_), | |
| 332 create_pipe_now); | |
| 333 return; | 287 return; |
| 334 } | 288 } |
| 335 | 289 |
| 336 VLOG(1) << "Mojo is disabled on child"; | 290 VLOG(1) << "Mojo is disabled on child"; |
| 337 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 291 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
| 338 } | 292 } |
| 339 | 293 |
| 340 void ChildThreadImpl::Init(const Options& options) { | 294 void ChildThreadImpl::Init(const Options& options) { |
| 341 channel_name_ = options.channel_name; | 295 channel_name_ = options.channel_name; |
| 342 | 296 |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 // doesn't cause such issues. TODO(gab): Remove this once the experiment is | 702 // doesn't cause such issues. TODO(gab): Remove this once the experiment is |
| 749 // over (http://crbug.com/458594). | 703 // over (http://crbug.com/458594). |
| 750 base::FieldTrial* trial = | 704 base::FieldTrial* trial = |
| 751 base::FieldTrialList::Find("BackgroundRendererProcesses"); | 705 base::FieldTrialList::Find("BackgroundRendererProcesses"); |
| 752 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") | 706 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") |
| 753 base::Process::Current().SetProcessBackgrounded(background); | 707 base::Process::Current().SetProcessBackgrounded(background); |
| 754 #endif // OS_WIN | 708 #endif // OS_WIN |
| 755 } | 709 } |
| 756 | 710 |
| 757 } // namespace content | 711 } // namespace content |
| OLD | NEW |