Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: content/common/child_thread.cc

Issue 14335017: content: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/child_process.cc ('k') | content/common/fileapi/webblobregistry_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 ChildThread::ChildThread(const std::string& channel_name) 91 ChildThread::ChildThread(const std::string& channel_name)
92 : channel_name_(channel_name), 92 : channel_name_(channel_name),
93 channel_connected_factory_(this) { 93 channel_connected_factory_(this) {
94 Init(); 94 Init();
95 } 95 }
96 96
97 void ChildThread::Init() { 97 void ChildThread::Init() {
98 on_channel_error_called_ = false; 98 on_channel_error_called_ = false;
99 message_loop_ = MessageLoop::current(); 99 message_loop_ = base::MessageLoop::current();
100 channel_.reset(new IPC::SyncChannel(channel_name_, 100 channel_.reset(
101 IPC::Channel::MODE_CLIENT, this, 101 new IPC::SyncChannel(channel_name_,
102 ChildProcess::current()->io_message_loop_proxy(), true, 102 IPC::Channel::MODE_CLIENT,
103 ChildProcess::current()->GetShutDownEvent())); 103 this,
104 ChildProcess::current()->io_message_loop_proxy(),
105 true,
106 ChildProcess::current()->GetShutDownEvent()));
104 #ifdef IPC_MESSAGE_LOG_ENABLED 107 #ifdef IPC_MESSAGE_LOG_ENABLED
105 IPC::Logging::GetInstance()->SetIPCSender(this); 108 IPC::Logging::GetInstance()->SetIPCSender(this);
106 #endif 109 #endif
107 110
108 resource_dispatcher_.reset(new ResourceDispatcher(this)); 111 resource_dispatcher_.reset(new ResourceDispatcher(this));
109 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); 112 socket_stream_dispatcher_.reset(new SocketStreamDispatcher());
110 file_system_dispatcher_.reset(new FileSystemDispatcher()); 113 file_system_dispatcher_.reset(new FileSystemDispatcher());
111 quota_dispatcher_.reset(new QuotaDispatcher()); 114 quota_dispatcher_.reset(new QuotaDispatcher());
112 115
113 sync_message_filter_ = 116 sync_message_filter_ =
114 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); 117 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent());
115 thread_safe_sender_ = 118 thread_safe_sender_ =
116 new ThreadSafeSender(base::MessageLoopProxy::current(), 119 new ThreadSafeSender(base::MessageLoopProxy::current(),
117 sync_message_filter_); 120 sync_message_filter_);
118 histogram_message_filter_ = new ChildHistogramMessageFilter(); 121 histogram_message_filter_ = new ChildHistogramMessageFilter();
119 122
120 channel_->AddFilter(histogram_message_filter_.get()); 123 channel_->AddFilter(histogram_message_filter_.get());
121 channel_->AddFilter(sync_message_filter_.get()); 124 channel_->AddFilter(sync_message_filter_.get());
122 channel_->AddFilter(new components::ChildTraceMessageFilter( 125 channel_->AddFilter(new components::ChildTraceMessageFilter(
123 ChildProcess::current()->io_message_loop_proxy())); 126 ChildProcess::current()->io_message_loop_proxy()));
124 127
125 #if defined(OS_POSIX) 128 #if defined(OS_POSIX)
126 // Check that --process-type is specified so we don't do this in unit tests 129 // Check that --process-type is specified so we don't do this in unit tests
127 // and single-process mode. 130 // and single-process mode.
128 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) 131 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType))
129 channel_->AddFilter(new SuicideOnChannelErrorFilter()); 132 channel_->AddFilter(new SuicideOnChannelErrorFilter());
130 #endif 133 #endif
131 134
132 MessageLoop::current()->PostDelayedTask( 135 base::MessageLoop::current()->PostDelayedTask(
133 FROM_HERE, 136 FROM_HERE,
134 base::Bind(&ChildThread::EnsureConnected, 137 base::Bind(&ChildThread::EnsureConnected,
135 channel_connected_factory_.GetWeakPtr()), 138 channel_connected_factory_.GetWeakPtr()),
136 base::TimeDelta::FromSeconds(kConnectionTimeoutS)); 139 base::TimeDelta::FromSeconds(kConnectionTimeoutS));
137 } 140 }
138 141
139 ChildThread::~ChildThread() { 142 ChildThread::~ChildThread() {
140 #ifdef IPC_MESSAGE_LOG_ENABLED 143 #ifdef IPC_MESSAGE_LOG_ENABLED
141 IPC::Logging::GetInstance()->SetIPCSender(NULL); 144 IPC::Logging::GetInstance()->SetIPCSender(NULL);
142 #endif 145 #endif
(...skipping 11 matching lines...) Expand all
154 // but it wasn't possible to do so on POSIX. 157 // but it wasn't possible to do so on POSIX.
155 channel_->ClearIPCTaskRunner(); 158 channel_->ClearIPCTaskRunner();
156 } 159 }
157 160
158 void ChildThread::OnChannelConnected(int32 peer_pid) { 161 void ChildThread::OnChannelConnected(int32 peer_pid) {
159 channel_connected_factory_.InvalidateWeakPtrs(); 162 channel_connected_factory_.InvalidateWeakPtrs();
160 } 163 }
161 164
162 void ChildThread::OnChannelError() { 165 void ChildThread::OnChannelError() {
163 set_on_channel_error_called(true); 166 set_on_channel_error_called(true);
164 MessageLoop::current()->Quit(); 167 base::MessageLoop::current()->Quit();
165 } 168 }
166 169
167 bool ChildThread::Send(IPC::Message* msg) { 170 bool ChildThread::Send(IPC::Message* msg) {
168 DCHECK(MessageLoop::current() == message_loop()); 171 DCHECK(base::MessageLoop::current() == message_loop());
169 if (!channel_) { 172 if (!channel_) {
170 delete msg; 173 delete msg;
171 return false; 174 return false;
172 } 175 }
173 176
174 return channel_->Send(msg); 177 return channel_->Send(msg);
175 } 178 }
176 179
177 void ChildThread::AddRoute(int32 routing_id, IPC::Listener* listener) { 180 void ChildThread::AddRoute(int32 routing_id, IPC::Listener* listener) {
178 DCHECK(MessageLoop::current() == message_loop()); 181 DCHECK(base::MessageLoop::current() == message_loop());
179 182
180 router_.AddRoute(routing_id, listener); 183 router_.AddRoute(routing_id, listener);
181 } 184 }
182 185
183 void ChildThread::RemoveRoute(int32 routing_id) { 186 void ChildThread::RemoveRoute(int32 routing_id) {
184 DCHECK(MessageLoop::current() == message_loop()); 187 DCHECK(base::MessageLoop::current() == message_loop());
185 188
186 router_.RemoveRoute(routing_id); 189 router_.RemoveRoute(routing_id);
187 } 190 }
188 191
189 webkit_glue::ResourceLoaderBridge* ChildThread::CreateBridge( 192 webkit_glue::ResourceLoaderBridge* ChildThread::CreateBridge(
190 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { 193 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
191 return resource_dispatcher()->CreateBridge(request_info); 194 return resource_dispatcher()->CreateBridge(request_info);
192 } 195 }
193 196
194 base::SharedMemory* ChildThread::AllocateSharedMemory(size_t buf_size) { 197 base::SharedMemory* ChildThread::AllocateSharedMemory(size_t buf_size) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 return OnControlMessageReceived(msg); 269 return OnControlMessageReceived(msg);
267 270
268 return router_.OnMessageReceived(msg); 271 return router_.OnMessageReceived(msg);
269 } 272 }
270 273
271 bool ChildThread::OnControlMessageReceived(const IPC::Message& msg) { 274 bool ChildThread::OnControlMessageReceived(const IPC::Message& msg) {
272 return false; 275 return false;
273 } 276 }
274 277
275 void ChildThread::OnShutdown() { 278 void ChildThread::OnShutdown() {
276 MessageLoop::current()->Quit(); 279 base::MessageLoop::current()->Quit();
277 } 280 }
278 281
279 #if defined(IPC_MESSAGE_LOG_ENABLED) 282 #if defined(IPC_MESSAGE_LOG_ENABLED)
280 void ChildThread::OnSetIPCLoggingEnabled(bool enable) { 283 void ChildThread::OnSetIPCLoggingEnabled(bool enable) {
281 if (enable) 284 if (enable)
282 IPC::Logging::GetInstance()->Enable(); 285 IPC::Logging::GetInstance()->Enable();
283 else 286 else
284 IPC::Logging::GetInstance()->Disable(); 287 IPC::Logging::GetInstance()->Disable();
285 } 288 }
286 #endif // IPC_MESSAGE_LOG_ENABLED 289 #endif // IPC_MESSAGE_LOG_ENABLED
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 ChildProcess::current()->main_thread() : NULL; 329 ChildProcess::current()->main_thread() : NULL;
327 } 330 }
328 331
329 bool ChildThread::IsWebFrameValid(WebKit::WebFrame* frame) { 332 bool ChildThread::IsWebFrameValid(WebKit::WebFrame* frame) {
330 // Return false so that it is overridden in any process in which it is used. 333 // Return false so that it is overridden in any process in which it is used.
331 return false; 334 return false;
332 } 335 }
333 336
334 void ChildThread::OnProcessFinalRelease() { 337 void ChildThread::OnProcessFinalRelease() {
335 if (on_channel_error_called_) { 338 if (on_channel_error_called_) {
336 MessageLoop::current()->Quit(); 339 base::MessageLoop::current()->Quit();
337 return; 340 return;
338 } 341 }
339 342
340 // The child process shutdown sequence is a request response based mechanism, 343 // The child process shutdown sequence is a request response based mechanism,
341 // where we send out an initial feeler request to the child process host 344 // where we send out an initial feeler request to the child process host
342 // instance in the browser to verify if it's ok to shutdown the child process. 345 // instance in the browser to verify if it's ok to shutdown the child process.
343 // The browser then sends back a response if it's ok to shutdown. This avoids 346 // The browser then sends back a response if it's ok to shutdown. This avoids
344 // race conditions if the process refcount is 0 but there's an IPC message 347 // race conditions if the process refcount is 0 but there's an IPC message
345 // inflight that would addref it. 348 // inflight that would addref it.
346 Send(new ChildProcessHostMsg_ShutdownRequest); 349 Send(new ChildProcessHostMsg_ShutdownRequest);
347 } 350 }
348 351
349 void ChildThread::EnsureConnected() { 352 void ChildThread::EnsureConnected() {
350 LOG(INFO) << "ChildThread::EnsureConnected()"; 353 LOG(INFO) << "ChildThread::EnsureConnected()";
351 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); 354 base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
352 } 355 }
353 356
354 } // namespace content 357 } // namespace content
OLDNEW
« no previous file with comments | « content/common/child_process.cc ('k') | content/common/fileapi/webblobregistry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698