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.h" | 5 #include "content/child/child_thread.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "base/tracked_objects.h" | 27 #include "base/tracked_objects.h" |
28 #include "components/tracing/child_trace_message_filter.h" | 28 #include "components/tracing/child_trace_message_filter.h" |
29 #include "content/child/child_histogram_message_filter.h" | 29 #include "content/child/child_histogram_message_filter.h" |
30 #include "content/child/child_process.h" | 30 #include "content/child/child_process.h" |
31 #include "content/child/child_resource_message_filter.h" | 31 #include "content/child/child_resource_message_filter.h" |
32 #include "content/child/child_shared_bitmap_manager.h" | 32 #include "content/child/child_shared_bitmap_manager.h" |
33 #include "content/child/fileapi/file_system_dispatcher.h" | 33 #include "content/child/fileapi/file_system_dispatcher.h" |
34 #include "content/child/fileapi/webfilesystem_impl.h" | 34 #include "content/child/fileapi/webfilesystem_impl.h" |
35 #include "content/child/mojo/mojo_application.h" | 35 #include "content/child/mojo/mojo_application.h" |
36 #include "content/child/power_monitor_broadcast_source.h" | 36 #include "content/child/power_monitor_broadcast_source.h" |
37 #include "content/child/process_background_message_filter.h" | |
38 #include "content/child/quota_dispatcher.h" | 37 #include "content/child/quota_dispatcher.h" |
39 #include "content/child/quota_message_filter.h" | 38 #include "content/child/quota_message_filter.h" |
40 #include "content/child/resource_dispatcher.h" | 39 #include "content/child/resource_dispatcher.h" |
41 #include "content/child/service_worker/service_worker_message_filter.h" | 40 #include "content/child/service_worker/service_worker_message_filter.h" |
42 #include "content/child/socket_stream_dispatcher.h" | 41 #include "content/child/socket_stream_dispatcher.h" |
43 #include "content/child/thread_safe_sender.h" | 42 #include "content/child/thread_safe_sender.h" |
44 #include "content/child/websocket_dispatcher.h" | 43 #include "content/child/websocket_dispatcher.h" |
45 #include "content/common/child_process_messages.h" | 44 #include "content/common/child_process_messages.h" |
46 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
47 #include "ipc/ipc_logging.h" | 46 #include "ipc/ipc_logging.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); | 275 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); |
277 | 276 |
278 resource_dispatcher_.reset(new ResourceDispatcher(this)); | 277 resource_dispatcher_.reset(new ResourceDispatcher(this)); |
279 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); | 278 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); |
280 websocket_dispatcher_.reset(new WebSocketDispatcher); | 279 websocket_dispatcher_.reset(new WebSocketDispatcher); |
281 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 280 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
282 | 281 |
283 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 282 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
284 resource_message_filter_ = | 283 resource_message_filter_ = |
285 new ChildResourceMessageFilter(resource_dispatcher()); | 284 new ChildResourceMessageFilter(resource_dispatcher()); |
286 process_background_message_filter_ = new ProcessBackgroundMessageFilter(); | |
287 | 285 |
288 service_worker_message_filter_ = | 286 service_worker_message_filter_ = |
289 new ServiceWorkerMessageFilter(thread_safe_sender_.get()); | 287 new ServiceWorkerMessageFilter(thread_safe_sender_.get()); |
290 | 288 |
291 quota_message_filter_ = | 289 quota_message_filter_ = |
292 new QuotaMessageFilter(thread_safe_sender_.get()); | 290 new QuotaMessageFilter(thread_safe_sender_.get()); |
293 quota_dispatcher_.reset(new QuotaDispatcher(thread_safe_sender_.get(), | 291 quota_dispatcher_.reset(new QuotaDispatcher(thread_safe_sender_.get(), |
294 quota_message_filter_.get())); | 292 quota_message_filter_.get())); |
295 | 293 |
296 channel_->AddFilter(histogram_message_filter_.get()); | 294 channel_->AddFilter(histogram_message_filter_.get()); |
297 channel_->AddFilter(sync_message_filter_.get()); | 295 channel_->AddFilter(sync_message_filter_.get()); |
298 channel_->AddFilter(resource_message_filter_.get()); | 296 channel_->AddFilter(resource_message_filter_.get()); |
299 channel_->AddFilter(process_background_message_filter_.get()); | |
300 channel_->AddFilter(quota_message_filter_->GetFilter()); | 297 channel_->AddFilter(quota_message_filter_->GetFilter()); |
301 channel_->AddFilter(service_worker_message_filter_->GetFilter()); | 298 channel_->AddFilter(service_worker_message_filter_->GetFilter()); |
302 | 299 |
303 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { | 300 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { |
304 // In single process mode, browser-side tracing will cover the whole | 301 // In single process mode, browser-side tracing will cover the whole |
305 // process including renderers. | 302 // process including renderers. |
306 channel_->AddFilter(new tracing::ChildTraceMessageFilter( | 303 channel_->AddFilter(new tracing::ChildTraceMessageFilter( |
307 ChildProcess::current()->io_message_loop_proxy())); | 304 ChildProcess::current()->io_message_loop_proxy())); |
308 } | 305 } |
309 | 306 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 new ChildSharedBitmapManager(thread_safe_sender())); | 359 new ChildSharedBitmapManager(thread_safe_sender())); |
363 } | 360 } |
364 | 361 |
365 ChildThread::~ChildThread() { | 362 ChildThread::~ChildThread() { |
366 #ifdef IPC_MESSAGE_LOG_ENABLED | 363 #ifdef IPC_MESSAGE_LOG_ENABLED |
367 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 364 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
368 #endif | 365 #endif |
369 | 366 |
370 channel_->RemoveFilter(histogram_message_filter_.get()); | 367 channel_->RemoveFilter(histogram_message_filter_.get()); |
371 channel_->RemoveFilter(sync_message_filter_.get()); | 368 channel_->RemoveFilter(sync_message_filter_.get()); |
372 channel_->RemoveFilter(process_background_message_filter_.get()); | |
373 | 369 |
374 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 370 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
375 // reset it as it's not guaranteed to outlive this object. | 371 // reset it as it's not guaranteed to outlive this object. |
376 // NOTE: this also has the side-effect of not closing the main IPC channel to | 372 // NOTE: this also has the side-effect of not closing the main IPC channel to |
377 // the browser process. This is needed because this is the signal that the | 373 // the browser process. This is needed because this is the signal that the |
378 // browser uses to know that this process has died, so we need it to be alive | 374 // browser uses to know that this process has died, so we need it to be alive |
379 // until this process is shut down, and the OS closes the handle | 375 // until this process is shut down, and the OS closes the handle |
380 // automatically. We used to watch the object handle on Windows to do this, | 376 // automatically. We used to watch the object handle on Windows to do this, |
381 // but it wasn't possible to do so on POSIX. | 377 // but it wasn't possible to do so on POSIX. |
382 channel_->ClearIPCTaskRunner(); | 378 channel_->ClearIPCTaskRunner(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) | 469 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) |
474 #if defined(IPC_MESSAGE_LOG_ENABLED) | 470 #if defined(IPC_MESSAGE_LOG_ENABLED) |
475 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, | 471 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, |
476 OnSetIPCLoggingEnabled) | 472 OnSetIPCLoggingEnabled) |
477 #endif | 473 #endif |
478 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, | 474 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, |
479 OnSetProfilerStatus) | 475 OnSetProfilerStatus) |
480 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, | 476 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, |
481 OnGetChildProfilerData) | 477 OnGetChildProfilerData) |
482 IPC_MESSAGE_HANDLER(ChildProcessMsg_DumpHandles, OnDumpHandles) | 478 IPC_MESSAGE_HANDLER(ChildProcessMsg_DumpHandles, OnDumpHandles) |
| 479 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded, |
| 480 OnProcessBackgrounded) |
483 #if defined(USE_TCMALLOC) | 481 #if defined(USE_TCMALLOC) |
484 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetTcmallocStats, OnGetTcmallocStats) | 482 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetTcmallocStats, OnGetTcmallocStats) |
485 #endif | 483 #endif |
486 IPC_MESSAGE_UNHANDLED(handled = false) | 484 IPC_MESSAGE_UNHANDLED(handled = false) |
487 IPC_END_MESSAGE_MAP() | 485 IPC_END_MESSAGE_MAP() |
488 | 486 |
489 if (handled) | 487 if (handled) |
490 return true; | 488 return true; |
491 | 489 |
492 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 490 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // race conditions if the process refcount is 0 but there's an IPC message | 579 // race conditions if the process refcount is 0 but there's an IPC message |
582 // inflight that would addref it. | 580 // inflight that would addref it. |
583 Send(new ChildProcessHostMsg_ShutdownRequest); | 581 Send(new ChildProcessHostMsg_ShutdownRequest); |
584 } | 582 } |
585 | 583 |
586 void ChildThread::EnsureConnected() { | 584 void ChildThread::EnsureConnected() { |
587 VLOG(0) << "ChildThread::EnsureConnected()"; | 585 VLOG(0) << "ChildThread::EnsureConnected()"; |
588 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | 586 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); |
589 } | 587 } |
590 | 588 |
| 589 void ChildThread::OnProcessBackgrounded(bool background) { |
| 590 // Set timer slack to maximum on main thread when in background. |
| 591 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
| 592 if (background) |
| 593 timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 594 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
| 595 } |
| 596 |
591 } // namespace content | 597 } // namespace content |
OLD | NEW |