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

Side by Side Diff: content/child/child_thread_impl.cc

Issue 2485623002: discardable_memory: Using mojo IPC to replace Chrome IPC (Closed)
Patch Set: Update Created 4 years, 1 month 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
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/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
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
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 channel_connected_factory_->GetWeakPtr()), 565 channel_connected_factory_->GetWeakPtr()),
585 base::TimeDelta::FromSeconds(connection_timeout)); 566 base::TimeDelta::FromSeconds(connection_timeout));
586 567
587 #if defined(OS_ANDROID) 568 #if defined(OS_ANDROID)
588 g_quit_closure.Get().BindToMainThread(); 569 g_quit_closure.Get().BindToMainThread();
589 #endif 570 #endif
590 571
591 shared_bitmap_manager_.reset( 572 shared_bitmap_manager_.reset(
592 new ChildSharedBitmapManager(thread_safe_sender())); 573 new ChildSharedBitmapManager(thread_safe_sender()));
593 574
594 client_discardable_shared_memory_manager_delegate_ = 575 if (options.init_discardable_memory) {
595 base::MakeUnique<ClientDiscardableSharedMemoryManagerDelegate>( 576 discardable_memory::mojom::DiscardableSharedMemoryManagerPtr manager;
596 thread_safe_sender()); 577 ChildThread::Get()->GetRemoteInterfaces()->GetInterface(
597 discardable_shared_memory_manager_ = base::MakeUnique< 578 mojo::GetProxy(&manager));
598 discardable_memory::ClientDiscardableSharedMemoryManager>( 579 discardable_shared_memory_manager_ = base::MakeUnique<
599 client_discardable_shared_memory_manager_delegate_.get()); 580 discardable_memory::ClientDiscardableSharedMemoryManager>(
581 manager.PassInterface(), GetIOTaskRunner());
582 }
600 } 583 }
601 584
602 ChildThreadImpl::~ChildThreadImpl() { 585 ChildThreadImpl::~ChildThreadImpl() {
603 #ifdef IPC_MESSAGE_LOG_ENABLED 586 #ifdef IPC_MESSAGE_LOG_ENABLED
604 IPC::Logging::GetInstance()->SetIPCSender(NULL); 587 IPC::Logging::GetInstance()->SetIPCSender(NULL);
605 #endif 588 #endif
606 589
607 channel_->RemoveFilter(histogram_message_filter_.get()); 590 channel_->RemoveFilter(histogram_message_filter_.get());
608 channel_->RemoveFilter(sync_message_filter_.get()); 591 channel_->RemoveFilter(sync_message_filter_.get());
609 592
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 connected_to_browser_ = true; 900 connected_to_browser_ = true;
918 child_info_ = local_info; 901 child_info_ = local_info;
919 browser_info_ = remote_info; 902 browser_info_ = remote_info;
920 } 903 }
921 904
922 bool ChildThreadImpl::IsInBrowserProcess() const { 905 bool ChildThreadImpl::IsInBrowserProcess() const {
923 return static_cast<bool>(browser_process_io_runner_); 906 return static_cast<bool>(browser_process_io_runner_);
924 } 907 }
925 908
926 } // namespace content 909 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698