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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 return browser_process_io_runner_; | 322 return browser_process_io_runner_; |
323 return ChildProcess::current()->io_task_runner(); | 323 return ChildProcess::current()->io_task_runner(); |
324 } | 324 } |
325 | 325 |
326 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 326 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
327 bool create_pipe_now = true; | 327 bool create_pipe_now = true; |
328 if (use_mojo_channel) { | 328 if (use_mojo_channel) { |
329 VLOG(1) << "Mojo is enabled on child"; | 329 VLOG(1) << "Mojo is enabled on child"; |
330 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); | 330 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); |
331 DCHECK(io_task_runner); | 331 DCHECK(io_task_runner); |
332 channel_->Init(IPC::ChannelMojo::CreateClientFactory( | 332 channel_->Init( |
333 io_task_runner, channel_name_, attachment_broker_.get()), | 333 IPC::ChannelMojo::CreateClientFactory(io_task_runner, channel_name_), |
334 create_pipe_now); | 334 create_pipe_now); |
335 return; | 335 return; |
336 } | 336 } |
337 | 337 |
338 VLOG(1) << "Mojo is disabled on child"; | 338 VLOG(1) << "Mojo is disabled on child"; |
339 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now, | 339 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
340 attachment_broker_.get()); | |
341 } | 340 } |
342 | 341 |
343 void ChildThreadImpl::Init(const Options& options) { | 342 void ChildThreadImpl::Init(const Options& options) { |
344 channel_name_ = options.channel_name; | 343 channel_name_ = options.channel_name; |
345 | 344 |
346 g_lazy_tls.Pointer()->Set(this); | 345 g_lazy_tls.Pointer()->Set(this); |
347 on_channel_error_called_ = false; | 346 on_channel_error_called_ = false; |
348 message_loop_ = base::MessageLoop::current(); | 347 message_loop_ = base::MessageLoop::current(); |
349 #ifdef IPC_MESSAGE_LOG_ENABLED | 348 #ifdef IPC_MESSAGE_LOG_ENABLED |
350 // We must make sure to instantiate the IPC Logger *before* we create the | 349 // We must make sure to instantiate the IPC Logger *before* we create the |
351 // channel, otherwise we can get a callback on the IO thread which creates | 350 // channel, otherwise we can get a callback on the IO thread which creates |
352 // the logger, and the logger does not like being created on the IO thread. | 351 // the logger, and the logger does not like being created on the IO thread. |
353 IPC::Logging::GetInstance(); | 352 IPC::Logging::GetInstance(); |
354 #endif | 353 #endif |
| 354 |
| 355 #if defined(OS_WIN) |
| 356 // The only reason a global would already exist is if the thread is being run |
| 357 // in the browser process because of a command line switch. |
| 358 if (!IPC::AttachmentBroker::GetGlobal()) { |
| 359 attachment_broker_.reset(new IPC::AttachmentBrokerUnprivilegedWin()); |
| 360 IPC::AttachmentBroker::SetGlobal(attachment_broker_.get()); |
| 361 } |
| 362 #endif |
| 363 |
355 channel_ = | 364 channel_ = |
356 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), | 365 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
357 ChildProcess::current()->GetShutDownEvent()); | 366 ChildProcess::current()->GetShutDownEvent()); |
358 #ifdef IPC_MESSAGE_LOG_ENABLED | 367 #ifdef IPC_MESSAGE_LOG_ENABLED |
359 if (!IsInBrowserProcess()) | 368 if (!IsInBrowserProcess()) |
360 IPC::Logging::GetInstance()->SetIPCSender(this); | 369 IPC::Logging::GetInstance()->SetIPCSender(this); |
361 #endif | 370 #endif |
362 | 371 |
363 #if defined(OS_WIN) | |
364 attachment_broker_.reset(new IPC::AttachmentBrokerUnprivilegedWin()); | |
365 #endif | |
366 | |
367 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); | 372 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); |
368 | 373 |
369 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 374 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
370 thread_safe_sender_ = new ThreadSafeSender( | 375 thread_safe_sender_ = new ThreadSafeSender( |
371 message_loop_->task_runner(), sync_message_filter_.get()); | 376 message_loop_->task_runner(), sync_message_filter_.get()); |
372 | 377 |
373 resource_dispatcher_.reset(new ResourceDispatcher( | 378 resource_dispatcher_.reset(new ResourceDispatcher( |
374 this, message_loop()->task_runner())); | 379 this, message_loop()->task_runner())); |
375 websocket_dispatcher_.reset(new WebSocketDispatcher); | 380 websocket_dispatcher_.reset(new WebSocketDispatcher); |
376 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 381 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 #if defined(OS_WIN) | 533 #if defined(OS_WIN) |
529 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { | 534 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
530 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); | 535 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
531 } | 536 } |
532 | 537 |
533 void ChildThreadImpl::ReleaseCachedFonts() { | 538 void ChildThreadImpl::ReleaseCachedFonts() { |
534 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); | 539 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
535 } | 540 } |
536 #endif | 541 #endif |
537 | 542 |
538 IPC::AttachmentBroker* ChildThreadImpl::GetAttachmentBroker() { | |
539 return attachment_broker_.get(); | |
540 } | |
541 | |
542 MessageRouter* ChildThreadImpl::GetRouter() { | 543 MessageRouter* ChildThreadImpl::GetRouter() { |
543 DCHECK(base::MessageLoop::current() == message_loop()); | 544 DCHECK(base::MessageLoop::current() == message_loop()); |
544 return &router_; | 545 return &router_; |
545 } | 546 } |
546 | 547 |
547 scoped_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 548 scoped_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
548 size_t buf_size) { | 549 size_t buf_size) { |
549 DCHECK(base::MessageLoop::current() == message_loop()); | 550 DCHECK(base::MessageLoop::current() == message_loop()); |
550 return AllocateSharedMemory(buf_size, this); | 551 return AllocateSharedMemory(buf_size, this); |
551 } | 552 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 708 |
708 void ChildThreadImpl::OnProcessBackgrounded(bool background) { | 709 void ChildThreadImpl::OnProcessBackgrounded(bool background) { |
709 // Set timer slack to maximum on main thread when in background. | 710 // Set timer slack to maximum on main thread when in background. |
710 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; | 711 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
711 if (background) | 712 if (background) |
712 timer_slack = base::TIMER_SLACK_MAXIMUM; | 713 timer_slack = base::TIMER_SLACK_MAXIMUM; |
713 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 714 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
714 } | 715 } |
715 | 716 |
716 } // namespace content | 717 } // namespace content |
OLD | NEW |