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 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter); | 283 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter); |
284 }; | 284 }; |
285 | 285 |
286 } // namespace | 286 } // namespace |
287 | 287 |
288 ChildThread* ChildThread::Get() { | 288 ChildThread* ChildThread::Get() { |
289 return ChildThreadImpl::current(); | 289 return ChildThreadImpl::current(); |
290 } | 290 } |
291 | 291 |
292 ChildThreadImpl::Options::Options() | 292 ChildThreadImpl::Options::Options() |
293 : auto_start_service_manager_connection(true), connect_to_browser(false) {} | 293 : auto_start_service_manager_connection(true), |
| 294 connect_to_browser(false), |
| 295 init_discardable_memory(false) {} |
294 | 296 |
295 ChildThreadImpl::Options::Options(const Options& other) = default; | 297 ChildThreadImpl::Options::Options(const Options& other) = default; |
296 | 298 |
297 ChildThreadImpl::Options::~Options() { | 299 ChildThreadImpl::Options::~Options() { |
298 } | 300 } |
299 | 301 |
300 ChildThreadImpl::Options::Builder::Builder() { | 302 ChildThreadImpl::Options::Builder::Builder() { |
301 } | 303 } |
302 | 304 |
303 ChildThreadImpl::Options::Builder& | 305 ChildThreadImpl::Options::Builder& |
304 ChildThreadImpl::Options::Builder::InBrowserProcess( | 306 ChildThreadImpl::Options::Builder::InBrowserProcess( |
305 const InProcessChildThreadParams& params) { | 307 const InProcessChildThreadParams& params) { |
306 options_.browser_process_io_runner = params.io_runner(); | 308 options_.browser_process_io_runner = params.io_runner(); |
307 options_.in_process_service_request_token = params.service_request_token(); | 309 options_.in_process_service_request_token = params.service_request_token(); |
308 return *this; | 310 return *this; |
309 } | 311 } |
310 | 312 |
311 ChildThreadImpl::Options::Builder& | 313 ChildThreadImpl::Options::Builder& |
312 ChildThreadImpl::Options::Builder::AutoStartServiceManagerConnection( | 314 ChildThreadImpl::Options::Builder::AutoStartServiceManagerConnection( |
313 bool auto_start) { | 315 bool auto_start) { |
314 options_.auto_start_service_manager_connection = auto_start; | 316 options_.auto_start_service_manager_connection = auto_start; |
315 return *this; | 317 return *this; |
316 } | 318 } |
317 | 319 |
318 ChildThreadImpl::Options::Builder& | 320 ChildThreadImpl::Options::Builder& |
319 ChildThreadImpl::Options::Builder::ConnectToBrowser( | 321 ChildThreadImpl::Options::Builder::InitDiscardableMemory( |
320 bool connect_to_browser) { | 322 bool discardable_memory) { |
| 323 options_.init_discardable_memory = discardable_memory; |
| 324 return *this; |
| 325 } |
| 326 |
| 327 ChildThreadImpl::Options::Builder& |
| 328 ChildThreadImpl::Options::Builder::ConnectToBrowser(bool connect_to_browser) { |
321 options_.connect_to_browser = connect_to_browser; | 329 options_.connect_to_browser = connect_to_browser; |
322 return *this; | 330 return *this; |
323 } | 331 } |
324 | 332 |
325 ChildThreadImpl::Options::Builder& | 333 ChildThreadImpl::Options::Builder& |
326 ChildThreadImpl::Options::Builder::AddStartupFilter( | 334 ChildThreadImpl::Options::Builder::AddStartupFilter( |
327 IPC::MessageFilter* filter) { | 335 IPC::MessageFilter* filter) { |
328 options_.startup_filters.push_back(filter); | 336 options_.startup_filters.push_back(filter); |
329 return *this; | 337 return *this; |
330 } | 338 } |
(...skipping 16 matching lines...) Expand all Loading... |
347 #if defined(OS_ANDROID) | 355 #if defined(OS_ANDROID) |
348 if (!handled && msg.is_sync()) { | 356 if (!handled && msg.is_sync()) { |
349 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 357 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
350 reply->set_reply_error(); | 358 reply->set_reply_error(); |
351 Send(reply); | 359 Send(reply); |
352 } | 360 } |
353 #endif | 361 #endif |
354 return handled; | 362 return handled; |
355 } | 363 } |
356 | 364 |
357 class ChildThreadImpl::ClientDiscardableSharedMemoryManagerDelegate | |
358 : public discardable_memory::ClientDiscardableSharedMemoryManager:: | |
359 Delegate { | |
360 public: | |
361 explicit ClientDiscardableSharedMemoryManagerDelegate( | |
362 scoped_refptr<ThreadSafeSender> sender) | |
363 : sender_(sender) {} | |
364 ~ClientDiscardableSharedMemoryManagerDelegate() override {} | |
365 | |
366 void AllocateLockedDiscardableSharedMemory( | |
367 size_t size, | |
368 discardable_memory::DiscardableSharedMemoryId id, | |
369 base::SharedMemoryHandle* handle) override { | |
370 sender_->Send( | |
371 new ChildProcessHostMsg_SyncAllocateLockedDiscardableSharedMemory( | |
372 size, id, handle)); | |
373 } | |
374 | |
375 void DeletedDiscardableSharedMemory( | |
376 discardable_memory::DiscardableSharedMemoryId id) override { | |
377 sender_->Send(new ChildProcessHostMsg_DeletedDiscardableSharedMemory(id)); | |
378 } | |
379 | |
380 private: | |
381 scoped_refptr<ThreadSafeSender> sender_; | |
382 }; | |
383 | |
384 ChildThreadImpl::ChildThreadImpl() | 365 ChildThreadImpl::ChildThreadImpl() |
385 : route_provider_binding_(this), | 366 : route_provider_binding_(this), |
386 associated_interface_provider_bindings_( | 367 associated_interface_provider_bindings_( |
387 mojo::BindingSetDispatchMode::WITH_CONTEXT), | 368 mojo::BindingSetDispatchMode::WITH_CONTEXT), |
388 router_(this), | 369 router_(this), |
389 channel_connected_factory_( | 370 channel_connected_factory_( |
390 new base::WeakPtrFactory<ChildThreadImpl>(this)), | 371 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
391 weak_factory_(this) { | 372 weak_factory_(this) { |
392 Init(Options::Builder().Build()); | 373 Init(Options::Builder().Build()); |
393 } | 374 } |
394 | 375 |
395 ChildThreadImpl::ChildThreadImpl(const Options& options) | 376 ChildThreadImpl::ChildThreadImpl(const Options& options) |
396 : route_provider_binding_(this), | 377 : route_provider_binding_(this), |
397 associated_interface_provider_bindings_( | 378 associated_interface_provider_bindings_( |
398 mojo::BindingSetDispatchMode::WITH_CONTEXT), | 379 mojo::BindingSetDispatchMode::WITH_CONTEXT), |
399 router_(this), | 380 router_(this), |
400 browser_process_io_runner_(options.browser_process_io_runner), | 381 browser_process_io_runner_(options.browser_process_io_runner), |
401 channel_connected_factory_( | 382 channel_connected_factory_( |
402 new base::WeakPtrFactory<ChildThreadImpl>(this)), | 383 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
403 weak_factory_(this) { | 384 weak_factory_(this) { |
404 Init(options); | 385 Init(options); |
405 } | 386 } |
406 | 387 |
407 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { | 388 scoped_refptr<base::SingleThreadTaskRunner> ChildThreadImpl::GetIOTaskRunner() { |
408 if (IsInBrowserProcess()) | 389 if (IsInBrowserProcess()) |
409 return browser_process_io_runner_; | 390 return browser_process_io_runner_; |
410 return ChildProcess::current()->io_task_runner(); | 391 return ChildProcess::current()->io_task_runner(); |
411 } | 392 } |
412 | 393 |
413 void ChildThreadImpl::ConnectChannel() { | 394 void ChildThreadImpl::ConnectChannel() { |
414 std::string channel_token; | 395 std::string channel_token; |
415 mojo::ScopedMessagePipeHandle handle; | 396 mojo::ScopedMessagePipeHandle handle; |
416 if (!IsInBrowserProcess()) { | 397 if (!IsInBrowserProcess()) { |
417 channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 398 channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 channel_connected_factory_->GetWeakPtr()), | 566 channel_connected_factory_->GetWeakPtr()), |
586 base::TimeDelta::FromSeconds(connection_timeout)); | 567 base::TimeDelta::FromSeconds(connection_timeout)); |
587 | 568 |
588 #if defined(OS_ANDROID) | 569 #if defined(OS_ANDROID) |
589 g_quit_closure.Get().BindToMainThread(); | 570 g_quit_closure.Get().BindToMainThread(); |
590 #endif | 571 #endif |
591 | 572 |
592 shared_bitmap_manager_.reset( | 573 shared_bitmap_manager_.reset( |
593 new ChildSharedBitmapManager(thread_safe_sender())); | 574 new ChildSharedBitmapManager(thread_safe_sender())); |
594 | 575 |
595 client_discardable_shared_memory_manager_delegate_ = | 576 if (options.init_discardable_memory) { |
596 base::MakeUnique<ClientDiscardableSharedMemoryManagerDelegate>( | 577 discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager; |
597 thread_safe_sender()); | 578 ChildThread::Get()->GetRemoteInterfaces()->GetInterface( |
598 discardable_shared_memory_manager_ = base::MakeUnique< | 579 mojo::GetProxy(&manager)); |
599 discardable_memory::ClientDiscardableSharedMemoryManager>( | 580 discardable_shared_memory_manager_ = base::MakeUnique< |
600 client_discardable_shared_memory_manager_delegate_.get()); | 581 discardable_memory::ClientDiscardableSharedMemoryManager>( |
| 582 manager.PassInterface(), GetIOTaskRunner().get()); |
| 583 } |
601 } | 584 } |
602 | 585 |
603 ChildThreadImpl::~ChildThreadImpl() { | 586 ChildThreadImpl::~ChildThreadImpl() { |
604 #ifdef IPC_MESSAGE_LOG_ENABLED | 587 #ifdef IPC_MESSAGE_LOG_ENABLED |
605 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 588 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
606 #endif | 589 #endif |
607 | 590 |
608 channel_->RemoveFilter(histogram_message_filter_.get()); | 591 channel_->RemoveFilter(histogram_message_filter_.get()); |
609 channel_->RemoveFilter(sync_message_filter_.get()); | 592 channel_->RemoveFilter(sync_message_filter_.get()); |
610 | 593 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 connected_to_browser_ = true; | 901 connected_to_browser_ = true; |
919 child_info_ = local_info; | 902 child_info_ = local_info; |
920 browser_info_ = remote_info; | 903 browser_info_ = remote_info; |
921 } | 904 } |
922 | 905 |
923 bool ChildThreadImpl::IsInBrowserProcess() const { | 906 bool ChildThreadImpl::IsInBrowserProcess() const { |
924 return static_cast<bool>(browser_process_io_runner_); | 907 return static_cast<bool>(browser_process_io_runner_); |
925 } | 908 } |
926 | 909 |
927 } // namespace content | 910 } // namespace content |
OLD | NEW |