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 |
11 #include "base/allocator/allocator_extension.h" | 11 #include "base/allocator/allocator_extension.h" |
12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/debug/leak_annotations.h" | 15 #include "base/debug/leak_annotations.h" |
16 #include "base/debug/profiler.h" | 16 #include "base/debug/profiler.h" |
17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/location.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/message_loop/message_loop.h" | |
20 #include "base/message_loop/timer_slack.h" | 20 #include "base/message_loop/timer_slack.h" |
21 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
22 #include "base/process/process.h" | 22 #include "base/process/process.h" |
23 #include "base/process/process_handle.h" | 23 #include "base/process/process_handle.h" |
| 24 #include "base/single_thread_task_runner.h" |
24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
26 #include "base/synchronization/condition_variable.h" | 27 #include "base/synchronization/condition_variable.h" |
27 #include "base/synchronization/lock.h" | 28 #include "base/synchronization/lock.h" |
| 29 #include "base/thread_task_runner_handle.h" |
28 #include "base/threading/thread_local.h" | 30 #include "base/threading/thread_local.h" |
29 #include "base/trace_event/memory_dump_manager.h" | 31 #include "base/trace_event/memory_dump_manager.h" |
30 #include "base/tracked_objects.h" | 32 #include "base/tracked_objects.h" |
31 #include "components/tracing/child_trace_message_filter.h" | 33 #include "components/tracing/child_trace_message_filter.h" |
32 #include "content/child/bluetooth/bluetooth_message_filter.h" | 34 #include "content/child/bluetooth/bluetooth_message_filter.h" |
33 #include "content/child/child_discardable_shared_memory_manager.h" | 35 #include "content/child/child_discardable_shared_memory_manager.h" |
34 #include "content/child/child_gpu_memory_buffer_manager.h" | 36 #include "content/child/child_gpu_memory_buffer_manager.h" |
35 #include "content/child/child_histogram_message_filter.h" | 37 #include "content/child/child_histogram_message_filter.h" |
36 #include "content/child/child_process.h" | 38 #include "content/child/child_process.h" |
37 #include "content/child/child_resource_message_filter.h" | 39 #include "content/child/child_resource_message_filter.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 ChildThreadImpl::ChildThreadImpl(const Options& options) | 287 ChildThreadImpl::ChildThreadImpl(const Options& options) |
286 : router_(this), | 288 : router_(this), |
287 browser_process_io_runner_(options.browser_process_io_runner), | 289 browser_process_io_runner_(options.browser_process_io_runner), |
288 channel_connected_factory_(this) { | 290 channel_connected_factory_(this) { |
289 Init(options); | 291 Init(options); |
290 } | 292 } |
291 | 293 |
292 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { | 294 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { |
293 if (IsInBrowserProcess()) | 295 if (IsInBrowserProcess()) |
294 return browser_process_io_runner_; | 296 return browser_process_io_runner_; |
295 return ChildProcess::current()->io_message_loop_proxy(); | 297 return ChildProcess::current()->io_task_runner(); |
296 } | 298 } |
297 | 299 |
298 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 300 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
299 bool create_pipe_now = true; | 301 bool create_pipe_now = true; |
300 if (use_mojo_channel) { | 302 if (use_mojo_channel) { |
301 VLOG(1) << "Mojo is enabled on child"; | 303 VLOG(1) << "Mojo is enabled on child"; |
302 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); | 304 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); |
303 DCHECK(io_task_runner); | 305 DCHECK(io_task_runner); |
304 channel_->Init(IPC::ChannelMojo::CreateClientFactory( | 306 channel_->Init(IPC::ChannelMojo::CreateClientFactory( |
305 nullptr, io_task_runner, channel_name_), | 307 nullptr, io_task_runner, channel_name_), |
(...skipping 10 matching lines...) Expand all Loading... |
316 | 318 |
317 g_lazy_tls.Pointer()->Set(this); | 319 g_lazy_tls.Pointer()->Set(this); |
318 on_channel_error_called_ = false; | 320 on_channel_error_called_ = false; |
319 message_loop_ = base::MessageLoop::current(); | 321 message_loop_ = base::MessageLoop::current(); |
320 #ifdef IPC_MESSAGE_LOG_ENABLED | 322 #ifdef IPC_MESSAGE_LOG_ENABLED |
321 // We must make sure to instantiate the IPC Logger *before* we create the | 323 // We must make sure to instantiate the IPC Logger *before* we create the |
322 // channel, otherwise we can get a callback on the IO thread which creates | 324 // channel, otherwise we can get a callback on the IO thread which creates |
323 // the logger, and the logger does not like being created on the IO thread. | 325 // the logger, and the logger does not like being created on the IO thread. |
324 IPC::Logging::GetInstance(); | 326 IPC::Logging::GetInstance(); |
325 #endif | 327 #endif |
326 channel_ = IPC::SyncChannel::Create( | 328 channel_ = |
327 this, ChildProcess::current()->io_message_loop_proxy(), | 329 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
328 ChildProcess::current()->GetShutDownEvent()); | 330 ChildProcess::current()->GetShutDownEvent()); |
329 #ifdef IPC_MESSAGE_LOG_ENABLED | 331 #ifdef IPC_MESSAGE_LOG_ENABLED |
330 if (!IsInBrowserProcess()) | 332 if (!IsInBrowserProcess()) |
331 IPC::Logging::GetInstance()->SetIPCSender(this); | 333 IPC::Logging::GetInstance()->SetIPCSender(this); |
332 #endif | 334 #endif |
333 | 335 |
334 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); | 336 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); |
335 | 337 |
336 sync_message_filter_ = | 338 sync_message_filter_ = |
337 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 339 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
338 thread_safe_sender_ = new ThreadSafeSender( | 340 thread_safe_sender_ = new ThreadSafeSender( |
339 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); | 341 message_loop_->task_runner(), sync_message_filter_.get()); |
340 | 342 |
341 resource_dispatcher_.reset(new ResourceDispatcher( | 343 resource_dispatcher_.reset(new ResourceDispatcher( |
342 this, message_loop()->task_runner())); | 344 this, message_loop()->task_runner())); |
343 websocket_dispatcher_.reset(new WebSocketDispatcher); | 345 websocket_dispatcher_.reset(new WebSocketDispatcher); |
344 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 346 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
345 | 347 |
346 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 348 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
347 resource_message_filter_ = | 349 resource_message_filter_ = |
348 new ChildResourceMessageFilter(resource_dispatcher()); | 350 new ChildResourceMessageFilter(resource_dispatcher()); |
349 | 351 |
(...skipping 22 matching lines...) Expand all Loading... |
372 channel_->AddFilter(push_dispatcher_->GetFilter()); | 374 channel_->AddFilter(push_dispatcher_->GetFilter()); |
373 channel_->AddFilter(service_worker_message_filter_->GetFilter()); | 375 channel_->AddFilter(service_worker_message_filter_->GetFilter()); |
374 channel_->AddFilter(geofencing_message_filter_->GetFilter()); | 376 channel_->AddFilter(geofencing_message_filter_->GetFilter()); |
375 channel_->AddFilter(bluetooth_message_filter_->GetFilter()); | 377 channel_->AddFilter(bluetooth_message_filter_->GetFilter()); |
376 channel_->AddFilter(navigator_connect_dispatcher_->GetFilter()); | 378 channel_->AddFilter(navigator_connect_dispatcher_->GetFilter()); |
377 | 379 |
378 if (!IsInBrowserProcess()) { | 380 if (!IsInBrowserProcess()) { |
379 // In single process mode, browser-side tracing will cover the whole | 381 // In single process mode, browser-side tracing will cover the whole |
380 // process including renderers. | 382 // process including renderers. |
381 channel_->AddFilter(new tracing::ChildTraceMessageFilter( | 383 channel_->AddFilter(new tracing::ChildTraceMessageFilter( |
382 ChildProcess::current()->io_message_loop_proxy())); | 384 ChildProcess::current()->io_task_runner())); |
383 } | 385 } |
384 | 386 |
385 // In single process mode we may already have a power monitor | 387 // In single process mode we may already have a power monitor |
386 if (!base::PowerMonitor::Get()) { | 388 if (!base::PowerMonitor::Get()) { |
387 scoped_ptr<PowerMonitorBroadcastSource> power_monitor_source( | 389 scoped_ptr<PowerMonitorBroadcastSource> power_monitor_source( |
388 new PowerMonitorBroadcastSource()); | 390 new PowerMonitorBroadcastSource()); |
389 channel_->AddFilter(power_monitor_source->GetMessageFilter()); | 391 channel_->AddFilter(power_monitor_source->GetMessageFilter()); |
390 | 392 |
391 power_monitor_.reset(new base::PowerMonitor( | 393 power_monitor_.reset(new base::PowerMonitor( |
392 power_monitor_source.Pass())); | 394 power_monitor_source.Pass())); |
(...skipping 16 matching lines...) Expand all Loading... |
409 int connection_timeout = kConnectionTimeoutS; | 411 int connection_timeout = kConnectionTimeoutS; |
410 std::string connection_override = | 412 std::string connection_override = |
411 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 413 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
412 switches::kIPCConnectionTimeout); | 414 switches::kIPCConnectionTimeout); |
413 if (!connection_override.empty()) { | 415 if (!connection_override.empty()) { |
414 int temp; | 416 int temp; |
415 if (base::StringToInt(connection_override, &temp)) | 417 if (base::StringToInt(connection_override, &temp)) |
416 connection_timeout = temp; | 418 connection_timeout = temp; |
417 } | 419 } |
418 | 420 |
419 base::MessageLoop::current()->PostDelayedTask( | 421 message_loop_->task_runner()->PostDelayedTask( |
420 FROM_HERE, | 422 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, |
421 base::Bind(&ChildThreadImpl::EnsureConnected, | 423 channel_connected_factory_.GetWeakPtr()), |
422 channel_connected_factory_.GetWeakPtr()), | |
423 base::TimeDelta::FromSeconds(connection_timeout)); | 424 base::TimeDelta::FromSeconds(connection_timeout)); |
424 | 425 |
425 #if defined(OS_ANDROID) | 426 #if defined(OS_ANDROID) |
426 g_quit_closure.Get().BindToMainThread(); | 427 g_quit_closure.Get().BindToMainThread(); |
427 #endif | 428 #endif |
428 | 429 |
429 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 430 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
430 trace_memory_controller_.reset(new base::trace_event::TraceMemoryController( | 431 trace_memory_controller_.reset(new base::trace_event::TraceMemoryController( |
431 message_loop_->message_loop_proxy(), ::HeapProfilerWithPseudoStackStart, | 432 message_loop_->task_runner(), ::HeapProfilerWithPseudoStackStart, |
432 ::HeapProfilerStop, ::GetHeapProfile)); | 433 ::HeapProfilerStop, ::GetHeapProfile)); |
433 #endif | 434 #endif |
434 | 435 |
435 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(); | 436 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(); |
436 | 437 |
437 shared_bitmap_manager_.reset( | 438 shared_bitmap_manager_.reset( |
438 new ChildSharedBitmapManager(thread_safe_sender())); | 439 new ChildSharedBitmapManager(thread_safe_sender())); |
439 | 440 |
440 gpu_memory_buffer_manager_.reset( | 441 gpu_memory_buffer_manager_.reset( |
441 new ChildGpuMemoryBufferManager(thread_safe_sender())); | 442 new ChildGpuMemoryBufferManager(thread_safe_sender())); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 | 674 |
674 void ChildThreadImpl::OnProcessBackgrounded(bool background) { | 675 void ChildThreadImpl::OnProcessBackgrounded(bool background) { |
675 // Set timer slack to maximum on main thread when in background. | 676 // Set timer slack to maximum on main thread when in background. |
676 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; | 677 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
677 if (background) | 678 if (background) |
678 timer_slack = base::TIMER_SLACK_MAXIMUM; | 679 timer_slack = base::TIMER_SLACK_MAXIMUM; |
679 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 680 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
680 } | 681 } |
681 | 682 |
682 } // namespace content | 683 } // namespace content |
OLD | NEW |