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

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: . 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
12 namespace {
13
14 class ForwardingInterfaceProvider : public mojom::InterfaceProvider {
15 public:
16 ForwardingInterfaceProvider(
17 const shell::InterfaceProvider::ForwardCallback& callback,
18 mojom::InterfaceProviderRequest request)
19 : callback_(callback), binding_(this, std::move(request)) {}
20 ~ForwardingInterfaceProvider() override {}
21
22 private:
23 // mojom::InterfaceProvider:
24 void GetInterface(const mojo::String& interface_name,
25 mojo::ScopedMessagePipeHandle request_handle) override {
26 callback_.Run(interface_name, std::move(request_handle));
27 }
28
29 shell::InterfaceProvider::ForwardCallback callback_;
30 mojo::StrongBinding<mojom::InterfaceProvider> binding_;
31
32 DISALLOW_COPY_AND_ASSIGN(ForwardingInterfaceProvider);
33 };
34
35 } // namespace
36
9 InterfaceProvider::InterfaceProvider() : weak_factory_(this) { 37 InterfaceProvider::InterfaceProvider() : weak_factory_(this) {
10 pending_request_ = GetProxy(&interface_provider_); 38 pending_request_ = GetProxy(&interface_provider_);
11 } 39 }
40
12 InterfaceProvider::~InterfaceProvider() {} 41 InterfaceProvider::~InterfaceProvider() {}
13 42
14 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) { 43 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) {
15 DCHECK(pending_request_.is_pending()); 44 DCHECK(pending_request_.is_pending());
16 mojo::FuseInterface(std::move(pending_request_), 45 mojo::FuseInterface(std::move(pending_request_),
17 interface_provider.PassInterface()); 46 interface_provider.PassInterface());
18 } 47 }
19 48
49 void InterfaceProvider::Forward(const ForwardCallback& callback) {
50 DCHECK(pending_request_.is_pending());
51
52 // Owns itself.
53 new ForwardingInterfaceProvider(callback, std::move(pending_request_));
54 }
55
20 void InterfaceProvider::SetConnectionLostClosure( 56 void InterfaceProvider::SetConnectionLostClosure(
21 const base::Closure& connection_lost_closure) { 57 const base::Closure& connection_lost_closure) {
22 interface_provider_.set_connection_error_handler(connection_lost_closure); 58 interface_provider_.set_connection_error_handler(connection_lost_closure);
23 } 59 }
24 60
25 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() { 61 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() {
26 return weak_factory_.GetWeakPtr(); 62 return weak_factory_.GetWeakPtr();
27 } 63 }
28 64
29 void InterfaceProvider::GetInterface( 65 void InterfaceProvider::GetInterface(
30 const std::string& name, 66 const std::string& name,
31 mojo::ScopedMessagePipeHandle request_handle) { 67 mojo::ScopedMessagePipeHandle request_handle) {
32 // Local binders can be registered via TestApi. 68 // Local binders can be registered via TestApi.
33 auto it = binders_.find(name); 69 auto it = binders_.find(name);
34 if (it != binders_.end()) { 70 if (it != binders_.end()) {
35 it->second.Run(std::move(request_handle)); 71 it->second.Run(std::move(request_handle));
36 return; 72 return;
37 } 73 }
38 interface_provider_->GetInterface(name, std::move(request_handle)); 74 interface_provider_->GetInterface(name, std::move(request_handle));
39 } 75 }
40 76
41 void InterfaceProvider::ClearBinders() { 77 void InterfaceProvider::ClearBinders() {
42 binders_.clear(); 78 binders_.clear();
43 } 79 }
44 80
45 } // namespace shell 81 } // namespace shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698