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

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 2245333005: Fix data races in MojoShellConnectionImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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
« no previous file with comments | « no previous file | content/common/mojo/mojo_shell_connection_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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 465
466 // Held by the RPH's BrowserContext's MojoShellConnection, ownership transferred 466 // Held by the RPH's BrowserContext's MojoShellConnection, ownership transferred
467 // back to RPH upon RPH destruction. 467 // back to RPH upon RPH destruction.
468 class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter { 468 class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
469 public: 469 public:
470 ConnectionFilterImpl( 470 ConnectionFilterImpl(
471 const shell::Identity& child_identity, 471 const shell::Identity& child_identity,
472 std::unique_ptr<shell::InterfaceRegistry> registry) 472 std::unique_ptr<shell::InterfaceRegistry> registry)
473 : child_identity_(child_identity), 473 : child_identity_(child_identity),
474 registry_(std::move(registry)), 474 registry_(std::move(registry)),
475 weak_factory_(this) {} 475 weak_factory_(this) {
476 // Registration of this filter may race with browser shutdown, in which case
477 // it's possible for this filter to be destroyed on the main thread. This
478 // is fine as long as the filter hasn't been used on the IO thread yet. We
479 // detach the ThreadChecker initially and the first use of the filter will
480 // bind it.
481 thread_checker_.DetachFromThread();
482 }
483
476 ~ConnectionFilterImpl() override { 484 ~ConnectionFilterImpl() override {
477 DCHECK_CURRENTLY_ON(BrowserThread::IO); 485 DCHECK(thread_checker_.CalledOnValidThread());
478 } 486 }
479 487
480 private: 488 private:
481 // ConnectionFilter: 489 // ConnectionFilter:
482 bool OnConnect(const shell::Identity& remote_identity, 490 bool OnConnect(const shell::Identity& remote_identity,
483 shell::InterfaceRegistry* registry, 491 shell::InterfaceRegistry* registry,
484 shell::Connector* connector) override { 492 shell::Connector* connector) override {
493 DCHECK(thread_checker_.CalledOnValidThread());
494 DCHECK_CURRENTLY_ON(BrowserThread::IO);
485 // We only fulfill connections from the renderer we host. 495 // We only fulfill connections from the renderer we host.
486 if (child_identity_.name() != remote_identity.name() || 496 if (child_identity_.name() != remote_identity.name() ||
487 child_identity_.instance() != remote_identity.instance()) { 497 child_identity_.instance() != remote_identity.instance()) {
488 return false; 498 return false;
489 } 499 }
490 500
491 std::set<std::string> interface_names; 501 std::set<std::string> interface_names;
492 registry_->GetInterfaceNames(&interface_names); 502 registry_->GetInterfaceNames(&interface_names);
493 for (auto& interface_name : interface_names) { 503 for (auto& interface_name : interface_names) {
494 // Note that the added callbacks may outlive this object, which is 504 // Note that the added callbacks may outlive this object, which is
495 // destroyed in RPH::Cleanup(). 505 // destroyed in RPH::Cleanup().
496 registry->AddInterface(interface_name, 506 registry->AddInterface(interface_name,
497 base::Bind(&ConnectionFilterImpl::GetInterface, 507 base::Bind(&ConnectionFilterImpl::GetInterface,
498 weak_factory_.GetWeakPtr(), 508 weak_factory_.GetWeakPtr(),
499 interface_name)); 509 interface_name));
500 } 510 }
501 return true; 511 return true;
502 } 512 }
503 513
504 void GetInterface(const std::string& interface_name, 514 void GetInterface(const std::string& interface_name,
505 mojo::ScopedMessagePipeHandle handle) { 515 mojo::ScopedMessagePipeHandle handle) {
516 DCHECK(thread_checker_.CalledOnValidThread());
517 DCHECK_CURRENTLY_ON(BrowserThread::IO);
506 shell::mojom::InterfaceProvider* provider = registry_.get(); 518 shell::mojom::InterfaceProvider* provider = registry_.get();
507 provider->GetInterface(interface_name, std::move(handle)); 519 provider->GetInterface(interface_name, std::move(handle));
508 } 520 }
509 521
522 base::ThreadChecker thread_checker_;
510 shell::Identity child_identity_; 523 shell::Identity child_identity_;
511 std::unique_ptr<shell::InterfaceRegistry> registry_; 524 std::unique_ptr<shell::InterfaceRegistry> registry_;
512 base::WeakPtrFactory<ConnectionFilterImpl> weak_factory_; 525 base::WeakPtrFactory<ConnectionFilterImpl> weak_factory_;
513 526
514 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); 527 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl);
515 }; 528 };
516 529
517 base::MessageLoop* 530 base::MessageLoop*
518 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { 531 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
519 return g_in_process_thread; 532 return g_in_process_thread;
(...skipping 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2838 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 2851 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2839 2852
2840 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 2853 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2841 // enough information here so that we can determine what the bad message was. 2854 // enough information here so that we can determine what the bad message was.
2842 base::debug::Alias(&error); 2855 base::debug::Alias(&error);
2843 bad_message::ReceivedBadMessage(process.get(), 2856 bad_message::ReceivedBadMessage(process.get(),
2844 bad_message::RPH_MOJO_PROCESS_ERROR); 2857 bad_message::RPH_MOJO_PROCESS_ERROR);
2845 } 2858 }
2846 2859
2847 } // namespace content 2860 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/common/mojo/mojo_shell_connection_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698