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 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } // namespace | 200 } // namespace |
201 | 201 |
202 ChildThread* ChildThread::Get() { | 202 ChildThread* ChildThread::Get() { |
203 return ChildThreadImpl::current(); | 203 return ChildThreadImpl::current(); |
204 } | 204 } |
205 | 205 |
206 ChildThreadImpl::Options::Options() | 206 ChildThreadImpl::Options::Options() |
207 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 207 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
208 switches::kProcessChannelID)), | 208 switches::kProcessChannelID)), |
209 use_mojo_channel(false), | 209 use_mojo_channel(false), |
210 in_browser_process(false) { | 210 in_browser_process(false), |
| 211 task_runner(base::MessageLoopProxy::current()) { |
211 } | 212 } |
212 | 213 |
213 ChildThreadImpl::Options::~Options() { | 214 ChildThreadImpl::Options::~Options() { |
214 } | 215 } |
215 | 216 |
216 ChildThreadImpl::Options::Builder::Builder() { | 217 ChildThreadImpl::Options::Builder::Builder() { |
217 } | 218 } |
218 | 219 |
219 ChildThreadImpl::Options::Builder& | 220 ChildThreadImpl::Options::Builder& |
220 ChildThreadImpl::Options::Builder::InBrowserProcess(bool in_browser_process) { | 221 ChildThreadImpl::Options::Builder::InBrowserProcess(bool in_browser_process) { |
(...skipping 14 matching lines...) Expand all Loading... |
235 return *this; | 236 return *this; |
236 } | 237 } |
237 | 238 |
238 ChildThreadImpl::Options::Builder& | 239 ChildThreadImpl::Options::Builder& |
239 ChildThreadImpl::Options::Builder::AddStartupFilter( | 240 ChildThreadImpl::Options::Builder::AddStartupFilter( |
240 IPC::MessageFilter* filter) { | 241 IPC::MessageFilter* filter) { |
241 options_.startup_filters.push_back(filter); | 242 options_.startup_filters.push_back(filter); |
242 return *this; | 243 return *this; |
243 } | 244 } |
244 | 245 |
| 246 ChildThreadImpl::Options::Builder& |
| 247 ChildThreadImpl::Options::Builder::WithTaskRunner( |
| 248 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 249 options_.task_runner = task_runner; |
| 250 return *this; |
| 251 } |
| 252 |
245 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { | 253 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { |
246 return options_; | 254 return options_; |
247 } | 255 } |
248 | 256 |
249 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( | 257 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( |
250 IPC::Sender* sender) | 258 IPC::Sender* sender) |
251 : sender_(sender) {} | 259 : sender_(sender) {} |
252 | 260 |
253 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { | 261 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { |
254 return sender_->Send(msg); | 262 return sender_->Send(msg); |
255 } | 263 } |
256 | 264 |
257 ChildThreadImpl::ChildThreadImpl() | 265 ChildThreadImpl::ChildThreadImpl() |
258 : router_(this), | 266 : ChildThreadImpl(Options::Builder().Build()) { |
259 in_browser_process_(false), | |
260 channel_connected_factory_(this) { | |
261 Init(Options::Builder().Build()); | |
262 } | 267 } |
263 | 268 |
264 ChildThreadImpl::ChildThreadImpl(const Options& options) | 269 ChildThreadImpl::ChildThreadImpl(const Options& options) |
265 : router_(this), | 270 : router_(this), |
| 271 task_runner_(options.task_runner), |
266 in_browser_process_(options.in_browser_process), | 272 in_browser_process_(options.in_browser_process), |
267 channel_connected_factory_(this) { | 273 channel_connected_factory_(this) { |
268 Init(options); | 274 Init(options); |
269 } | 275 } |
270 | 276 |
271 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 277 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
272 bool create_pipe_now = true; | 278 bool create_pipe_now = true; |
273 if (use_mojo_channel) { | 279 if (use_mojo_channel) { |
274 VLOG(1) << "Mojo is enabled on child"; | 280 VLOG(1) << "Mojo is enabled on child"; |
275 channel_->Init(IPC::ChannelMojo::CreateClientFactory(channel_name_), | 281 channel_->Init(IPC::ChannelMojo::CreateClientFactory(channel_name_), |
(...skipping 25 matching lines...) Expand all Loading... |
301 IPC::Logging::GetInstance()->SetIPCSender(this); | 307 IPC::Logging::GetInstance()->SetIPCSender(this); |
302 #endif | 308 #endif |
303 | 309 |
304 mojo_application_.reset(new MojoApplication); | 310 mojo_application_.reset(new MojoApplication); |
305 | 311 |
306 sync_message_filter_ = | 312 sync_message_filter_ = |
307 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 313 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
308 thread_safe_sender_ = new ThreadSafeSender( | 314 thread_safe_sender_ = new ThreadSafeSender( |
309 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); | 315 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); |
310 | 316 |
311 resource_dispatcher_.reset(new ResourceDispatcher( | 317 resource_dispatcher_.reset(new ResourceDispatcher(this, GetTaskRunner())); |
312 this, message_loop()->task_runner())); | |
313 websocket_dispatcher_.reset(new WebSocketDispatcher); | 318 websocket_dispatcher_.reset(new WebSocketDispatcher); |
314 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 319 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
315 | 320 |
316 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 321 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
317 resource_message_filter_ = | 322 resource_message_filter_ = |
318 new ChildResourceMessageFilter(resource_dispatcher()); | 323 new ChildResourceMessageFilter(resource_dispatcher()); |
319 | 324 |
320 service_worker_message_filter_ = | 325 service_worker_message_filter_ = |
321 new ServiceWorkerMessageFilter(thread_safe_sender_.get()); | 326 new ServiceWorkerMessageFilter(thread_safe_sender_.get()); |
322 | 327 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 bool ChildThreadImpl::Send(IPC::Message* msg) { | 472 bool ChildThreadImpl::Send(IPC::Message* msg) { |
468 DCHECK(base::MessageLoop::current() == message_loop()); | 473 DCHECK(base::MessageLoop::current() == message_loop()); |
469 if (!channel_) { | 474 if (!channel_) { |
470 delete msg; | 475 delete msg; |
471 return false; | 476 return false; |
472 } | 477 } |
473 | 478 |
474 return channel_->Send(msg); | 479 return channel_->Send(msg); |
475 } | 480 } |
476 | 481 |
| 482 scoped_refptr<base::SingleThreadTaskRunner> ChildThreadImpl::GetTaskRunner() { |
| 483 return task_runner_; |
| 484 } |
| 485 |
477 #if defined(OS_WIN) | 486 #if defined(OS_WIN) |
478 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { | 487 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
479 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); | 488 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
480 } | 489 } |
481 | 490 |
482 void ChildThreadImpl::ReleaseCachedFonts() { | 491 void ChildThreadImpl::ReleaseCachedFonts() { |
483 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); | 492 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
484 } | 493 } |
485 #endif | 494 #endif |
486 | 495 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 // doesn't cause such issues. TODO(gab): Remove this once the experiment is | 694 // doesn't cause such issues. TODO(gab): Remove this once the experiment is |
686 // over (http://crbug.com/458594). | 695 // over (http://crbug.com/458594). |
687 base::FieldTrial* trial = | 696 base::FieldTrial* trial = |
688 base::FieldTrialList::Find("BackgroundRendererProcesses"); | 697 base::FieldTrialList::Find("BackgroundRendererProcesses"); |
689 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") | 698 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") |
690 base::Process::Current().SetProcessBackgrounded(background); | 699 base::Process::Current().SetProcessBackgrounded(background); |
691 #endif // OS_WIN | 700 #endif // OS_WIN |
692 } | 701 } |
693 | 702 |
694 } // namespace content | 703 } // namespace content |
OLD | NEW |