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/common/child_thread.h" | 5 #include "content/common/child_thread.h" |
6 | 6 |
7 #include "base/allocator/allocator_extension.h" | 7 #include "base/allocator/allocator_extension.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 101 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
102 quota_dispatcher_.reset(new QuotaDispatcher()); | 102 quota_dispatcher_.reset(new QuotaDispatcher()); |
103 | 103 |
104 sync_message_filter_ = | 104 sync_message_filter_ = |
105 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 105 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
106 histogram_message_filter_ = new content::ChildHistogramMessageFilter(); | 106 histogram_message_filter_ = new content::ChildHistogramMessageFilter(); |
107 | 107 |
108 channel_->AddFilter(histogram_message_filter_.get()); | 108 channel_->AddFilter(histogram_message_filter_.get()); |
109 channel_->AddFilter(sync_message_filter_.get()); | 109 channel_->AddFilter(sync_message_filter_.get()); |
110 channel_->AddFilter(new ChildTraceMessageFilter()); | 110 channel_->AddFilter(new ChildTraceMessageFilter()); |
| 111 LOG(INFO) << "ChildThread::Init"; |
111 | 112 |
112 #if defined(OS_POSIX) | 113 #if defined(OS_POSIX) |
113 // Check that --process-type is specified so we don't do this in unit tests | 114 // Check that --process-type is specified so we don't do this in unit tests |
114 // and single-process mode. | 115 // and single-process mode. |
115 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) | 116 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) |
116 channel_->AddFilter(new SuicideOnChannelErrorFilter()); | 117 channel_->AddFilter(new SuicideOnChannelErrorFilter()); |
117 #endif | 118 #endif |
118 } | 119 } |
119 | 120 |
120 ChildThread::~ChildThread() { | 121 ChildThread::~ChildThread() { |
121 #ifdef IPC_MESSAGE_LOG_ENABLED | 122 #ifdef IPC_MESSAGE_LOG_ENABLED |
122 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 123 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
123 #endif | 124 #endif |
124 | 125 |
125 channel_->RemoveFilter(histogram_message_filter_.get()); | 126 channel_->RemoveFilter(histogram_message_filter_.get()); |
126 channel_->RemoveFilter(sync_message_filter_.get()); | 127 channel_->RemoveFilter(sync_message_filter_.get()); |
127 | 128 |
128 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 129 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
129 // reset it as it's not guaranteed to outlive this object. | 130 // reset it as it's not guaranteed to outlive this object. |
130 // NOTE: this also has the side-effect of not closing the main IPC channel to | 131 // NOTE: this also has the side-effect of not closing the main IPC channel to |
131 // the browser process. This is needed because this is the signal that the | 132 // the browser process. This is needed because this is the signal that the |
132 // browser uses to know that this process has died, so we need it to be alive | 133 // browser uses to know that this process has died, so we need it to be alive |
133 // until this process is shut down, and the OS closes the handle | 134 // until this process is shut down, and the OS closes the handle |
134 // automatically. We used to watch the object handle on Windows to do this, | 135 // automatically. We used to watch the object handle on Windows to do this, |
135 // but it wasn't possible to do so on POSIX. | 136 // but it wasn't possible to do so on POSIX. |
136 channel_->ClearIPCTaskRunner(); | 137 channel_->ClearIPCTaskRunner(); |
137 } | 138 } |
138 | 139 |
| 140 void ChildThread::OnChannelConnected(int32 peer_pid) { |
| 141 LOG(INFO) << "ChildThread::OnChannelConnected"; |
| 142 } |
| 143 |
139 void ChildThread::OnChannelError() { | 144 void ChildThread::OnChannelError() { |
140 LOG(INFO) << "ChildThread::OnChannelError"; | 145 LOG(INFO) << "ChildThread::OnChannelError"; |
141 set_on_channel_error_called(true); | 146 set_on_channel_error_called(true); |
142 MessageLoop::current()->Quit(); | 147 MessageLoop::current()->Quit(); |
143 } | 148 } |
144 | 149 |
145 bool ChildThread::Send(IPC::Message* msg) { | 150 bool ChildThread::Send(IPC::Message* msg) { |
146 DCHECK(MessageLoop::current() == message_loop()); | 151 DCHECK(MessageLoop::current() == message_loop()); |
147 if (!channel_.get()) { | 152 if (!channel_.get()) { |
148 delete msg; | 153 delete msg; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 332 } |
328 | 333 |
329 // The child process shutdown sequence is a request response based mechanism, | 334 // The child process shutdown sequence is a request response based mechanism, |
330 // where we send out an initial feeler request to the child process host | 335 // where we send out an initial feeler request to the child process host |
331 // instance in the browser to verify if it's ok to shutdown the child process. | 336 // instance in the browser to verify if it's ok to shutdown the child process. |
332 // The browser then sends back a response if it's ok to shutdown. This avoids | 337 // The browser then sends back a response if it's ok to shutdown. This avoids |
333 // race conditions if the process refcount is 0 but there's an IPC message | 338 // race conditions if the process refcount is 0 but there's an IPC message |
334 // inflight that would addref it. | 339 // inflight that would addref it. |
335 Send(new ChildProcessHostMsg_ShutdownRequest); | 340 Send(new ChildProcessHostMsg_ShutdownRequest); |
336 } | 341 } |
OLD | NEW |