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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 ChildThreadImpl::ChildThreadImpl(const Options& options) | 266 ChildThreadImpl::ChildThreadImpl(const Options& options) |
265 : router_(this), | 267 : router_(this), |
266 browser_process_io_runner_(options.browser_process_io_runner), | 268 browser_process_io_runner_(options.browser_process_io_runner), |
267 channel_connected_factory_(this) { | 269 channel_connected_factory_(this) { |
268 Init(options); | 270 Init(options); |
269 } | 271 } |
270 | 272 |
271 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { | 273 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { |
272 if (IsInBrowserProcess()) | 274 if (IsInBrowserProcess()) |
273 return browser_process_io_runner_; | 275 return browser_process_io_runner_; |
274 return ChildProcess::current()->io_message_loop_proxy(); | 276 return ChildProcess::current()->io_task_runner(); |
275 } | 277 } |
276 | 278 |
277 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 279 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
278 bool create_pipe_now = true; | 280 bool create_pipe_now = true; |
279 if (use_mojo_channel) { | 281 if (use_mojo_channel) { |
280 VLOG(1) << "Mojo is enabled on child"; | 282 VLOG(1) << "Mojo is enabled on child"; |
281 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); | 283 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); |
282 DCHECK(io_task_runner); | 284 DCHECK(io_task_runner); |
283 channel_->Init(IPC::ChannelMojo::CreateClientFactory( | 285 channel_->Init(IPC::ChannelMojo::CreateClientFactory( |
284 nullptr, io_task_runner, channel_name_), | 286 nullptr, io_task_runner, channel_name_), |
(...skipping 10 matching lines...) Expand all Loading... | |
295 | 297 |
296 g_lazy_tls.Pointer()->Set(this); | 298 g_lazy_tls.Pointer()->Set(this); |
297 on_channel_error_called_ = false; | 299 on_channel_error_called_ = false; |
298 message_loop_ = base::MessageLoop::current(); | 300 message_loop_ = base::MessageLoop::current(); |
299 #ifdef IPC_MESSAGE_LOG_ENABLED | 301 #ifdef IPC_MESSAGE_LOG_ENABLED |
300 // We must make sure to instantiate the IPC Logger *before* we create the | 302 // We must make sure to instantiate the IPC Logger *before* we create the |
301 // channel, otherwise we can get a callback on the IO thread which creates | 303 // channel, otherwise we can get a callback on the IO thread which creates |
302 // the logger, and the logger does not like being created on the IO thread. | 304 // the logger, and the logger does not like being created on the IO thread. |
303 IPC::Logging::GetInstance(); | 305 IPC::Logging::GetInstance(); |
304 #endif | 306 #endif |
305 channel_ = IPC::SyncChannel::Create( | 307 channel_ = |
306 this, ChildProcess::current()->io_message_loop_proxy(), | 308 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
307 ChildProcess::current()->GetShutDownEvent()); | 309 ChildProcess::current()->GetShutDownEvent()); |
308 #ifdef IPC_MESSAGE_LOG_ENABLED | 310 #ifdef IPC_MESSAGE_LOG_ENABLED |
309 if (!IsInBrowserProcess()) | 311 if (!IsInBrowserProcess()) |
310 IPC::Logging::GetInstance()->SetIPCSender(this); | 312 IPC::Logging::GetInstance()->SetIPCSender(this); |
311 #endif | 313 #endif |
312 | 314 |
313 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); | 315 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); |
314 | 316 |
315 sync_message_filter_ = | 317 sync_message_filter_ = |
316 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 318 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
317 thread_safe_sender_ = new ThreadSafeSender( | 319 thread_safe_sender_ = new ThreadSafeSender( |
318 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); | 320 base::ThreadTaskRunnerHandle::Get().get(), sync_message_filter_.get()); |
no sievers
2015/05/20 23:02:38
You can actually use message_loop_.task_runner() w
Sami
2015/05/21 11:39:48
Thanks for the tip, done.
| |
319 | 321 |
320 resource_dispatcher_.reset(new ResourceDispatcher( | 322 resource_dispatcher_.reset(new ResourceDispatcher( |
321 this, message_loop()->task_runner())); | 323 this, message_loop()->task_runner())); |
322 websocket_dispatcher_.reset(new WebSocketDispatcher); | 324 websocket_dispatcher_.reset(new WebSocketDispatcher); |
323 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 325 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
324 | 326 |
325 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 327 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
326 resource_message_filter_ = | 328 resource_message_filter_ = |
327 new ChildResourceMessageFilter(resource_dispatcher()); | 329 new ChildResourceMessageFilter(resource_dispatcher()); |
328 | 330 |
(...skipping 22 matching lines...) Expand all Loading... | |
351 channel_->AddFilter(push_dispatcher_->GetFilter()); | 353 channel_->AddFilter(push_dispatcher_->GetFilter()); |
352 channel_->AddFilter(service_worker_message_filter_->GetFilter()); | 354 channel_->AddFilter(service_worker_message_filter_->GetFilter()); |
353 channel_->AddFilter(geofencing_message_filter_->GetFilter()); | 355 channel_->AddFilter(geofencing_message_filter_->GetFilter()); |
354 channel_->AddFilter(bluetooth_message_filter_->GetFilter()); | 356 channel_->AddFilter(bluetooth_message_filter_->GetFilter()); |
355 channel_->AddFilter(navigator_connect_dispatcher_->GetFilter()); | 357 channel_->AddFilter(navigator_connect_dispatcher_->GetFilter()); |
356 | 358 |
357 if (!IsInBrowserProcess()) { | 359 if (!IsInBrowserProcess()) { |
358 // In single process mode, browser-side tracing will cover the whole | 360 // In single process mode, browser-side tracing will cover the whole |
359 // process including renderers. | 361 // process including renderers. |
360 channel_->AddFilter(new tracing::ChildTraceMessageFilter( | 362 channel_->AddFilter(new tracing::ChildTraceMessageFilter( |
361 ChildProcess::current()->io_message_loop_proxy())); | 363 ChildProcess::current()->io_task_runner())); |
362 } | 364 } |
363 | 365 |
364 // In single process mode we may already have a power monitor | 366 // In single process mode we may already have a power monitor |
365 if (!base::PowerMonitor::Get()) { | 367 if (!base::PowerMonitor::Get()) { |
366 scoped_ptr<PowerMonitorBroadcastSource> power_monitor_source( | 368 scoped_ptr<PowerMonitorBroadcastSource> power_monitor_source( |
367 new PowerMonitorBroadcastSource()); | 369 new PowerMonitorBroadcastSource()); |
368 channel_->AddFilter(power_monitor_source->GetMessageFilter()); | 370 channel_->AddFilter(power_monitor_source->GetMessageFilter()); |
369 | 371 |
370 power_monitor_.reset(new base::PowerMonitor( | 372 power_monitor_.reset(new base::PowerMonitor( |
371 power_monitor_source.Pass())); | 373 power_monitor_source.Pass())); |
(...skipping 16 matching lines...) Expand all Loading... | |
388 int connection_timeout = kConnectionTimeoutS; | 390 int connection_timeout = kConnectionTimeoutS; |
389 std::string connection_override = | 391 std::string connection_override = |
390 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 392 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
391 switches::kIPCConnectionTimeout); | 393 switches::kIPCConnectionTimeout); |
392 if (!connection_override.empty()) { | 394 if (!connection_override.empty()) { |
393 int temp; | 395 int temp; |
394 if (base::StringToInt(connection_override, &temp)) | 396 if (base::StringToInt(connection_override, &temp)) |
395 connection_timeout = temp; | 397 connection_timeout = temp; |
396 } | 398 } |
397 | 399 |
398 base::MessageLoop::current()->PostDelayedTask( | 400 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
no sievers
2015/05/20 23:02:38
nit: Maybe just do message_loop_->task_runner() he
Sami
2015/05/21 11:39:48
Done.
| |
399 FROM_HERE, | 401 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, |
400 base::Bind(&ChildThreadImpl::EnsureConnected, | 402 channel_connected_factory_.GetWeakPtr()), |
401 channel_connected_factory_.GetWeakPtr()), | |
402 base::TimeDelta::FromSeconds(connection_timeout)); | 403 base::TimeDelta::FromSeconds(connection_timeout)); |
403 | 404 |
404 #if defined(OS_ANDROID) | 405 #if defined(OS_ANDROID) |
405 { | 406 { |
406 base::AutoLock lock(g_lazy_child_thread_lock.Get()); | 407 base::AutoLock lock(g_lazy_child_thread_lock.Get()); |
407 g_child_thread = this; | 408 g_child_thread = this; |
408 g_child_thread_initialized = true; | 409 g_child_thread_initialized = true; |
409 } | 410 } |
410 // Signalling without locking is fine here because only | 411 // Signalling without locking is fine here because only |
411 // one thread can wait on the condition variable. | 412 // one thread can wait on the condition variable. |
412 g_lazy_child_thread_cv.Get().Signal(); | 413 g_lazy_child_thread_cv.Get().Signal(); |
413 #endif | 414 #endif |
414 | 415 |
415 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 416 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
416 trace_memory_controller_.reset(new base::trace_event::TraceMemoryController( | 417 trace_memory_controller_.reset(new base::trace_event::TraceMemoryController( |
417 message_loop_->message_loop_proxy(), ::HeapProfilerWithPseudoStackStart, | 418 message_loop_->task_runner(), ::HeapProfilerWithPseudoStackStart, |
418 ::HeapProfilerStop, ::GetHeapProfile)); | 419 ::HeapProfilerStop, ::GetHeapProfile)); |
419 #endif | 420 #endif |
420 | 421 |
421 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(); | 422 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(); |
422 | 423 |
423 shared_bitmap_manager_.reset( | 424 shared_bitmap_manager_.reset( |
424 new ChildSharedBitmapManager(thread_safe_sender())); | 425 new ChildSharedBitmapManager(thread_safe_sender())); |
425 | 426 |
426 gpu_memory_buffer_manager_.reset( | 427 gpu_memory_buffer_manager_.reset( |
427 new ChildGpuMemoryBufferManager(thread_safe_sender())); | 428 new ChildGpuMemoryBufferManager(thread_safe_sender())); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 | 680 |
680 void ChildThreadImpl::OnProcessBackgrounded(bool background) { | 681 void ChildThreadImpl::OnProcessBackgrounded(bool background) { |
681 // Set timer slack to maximum on main thread when in background. | 682 // Set timer slack to maximum on main thread when in background. |
682 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; | 683 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
683 if (background) | 684 if (background) |
684 timer_slack = base::TIMER_SLACK_MAXIMUM; | 685 timer_slack = base::TIMER_SLACK_MAXIMUM; |
685 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 686 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
686 } | 687 } |
687 | 688 |
688 } // namespace content | 689 } // namespace content |
OLD | NEW |