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

Side by Side Diff: services/shell/public/cpp/lib/interface_provider.cc

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/shell/public/cpp/interface_provider.h" 5 #include "services/shell/public/cpp/interface_provider.h"
6 6
7 #include "base/macros.h"
8 #include "mojo/public/cpp/bindings/strong_binding.h"
9
7 namespace shell { 10 namespace shell {
8 11
9 InterfaceProvider::InterfaceProvider() : weak_factory_(this) { 12 InterfaceProvider::InterfaceProvider() : weak_factory_(this) {
10 pending_request_ = GetProxy(&interface_provider_); 13 pending_request_ = GetProxy(&interface_provider_);
11 } 14 }
15
12 InterfaceProvider::~InterfaceProvider() {} 16 InterfaceProvider::~InterfaceProvider() {}
13 17
14 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) { 18 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) {
15 DCHECK(pending_request_.is_pending()); 19 DCHECK(pending_request_.is_pending());
20 DCHECK(forward_callback_.is_null());
16 mojo::FuseInterface(std::move(pending_request_), 21 mojo::FuseInterface(std::move(pending_request_),
17 interface_provider.PassInterface()); 22 interface_provider.PassInterface());
18 } 23 }
19 24
25 void InterfaceProvider::Forward(const ForwardCallback& callback) {
26 DCHECK(pending_request_.is_pending());
27 DCHECK(forward_callback_.is_null());
28 interface_provider_.reset();
29 pending_request_.PassMessagePipe().reset();
30 forward_callback_ = callback;
31 }
32
20 void InterfaceProvider::SetConnectionLostClosure( 33 void InterfaceProvider::SetConnectionLostClosure(
21 const base::Closure& connection_lost_closure) { 34 const base::Closure& connection_lost_closure) {
22 interface_provider_.set_connection_error_handler(connection_lost_closure); 35 interface_provider_.set_connection_error_handler(connection_lost_closure);
23 } 36 }
24 37
25 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() { 38 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() {
26 return weak_factory_.GetWeakPtr(); 39 return weak_factory_.GetWeakPtr();
27 } 40 }
28 41
29 void InterfaceProvider::GetInterface( 42 void InterfaceProvider::GetInterface(
30 const std::string& name, 43 const std::string& name,
31 mojo::ScopedMessagePipeHandle request_handle) { 44 mojo::ScopedMessagePipeHandle request_handle) {
32 // Local binders can be registered via TestApi. 45 // Local binders can be registered via TestApi.
33 auto it = binders_.find(name); 46 auto it = binders_.find(name);
34 if (it != binders_.end()) { 47 if (it != binders_.end()) {
35 it->second.Run(std::move(request_handle)); 48 it->second.Run(std::move(request_handle));
36 return; 49 return;
37 } 50 }
38 interface_provider_->GetInterface(name, std::move(request_handle)); 51
52 if (!forward_callback_.is_null()) {
53 DCHECK(!interface_provider_.is_bound());
54 forward_callback_.Run(name, std::move(request_handle));
55 } else {
56 DCHECK(interface_provider_.is_bound());
57 interface_provider_->GetInterface(name, std::move(request_handle));
58 }
39 } 59 }
40 60
41 void InterfaceProvider::ClearBinders() { 61 void InterfaceProvider::ClearBinders() {
42 binders_.clear(); 62 binders_.clear();
43 } 63 }
44 64
45 } // namespace shell 65 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/lib/connector_impl.cc ('k') | services/shell/public/cpp/lib/interface_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698