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