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

Side by Side Diff: content/common/associated_interface_provider_impl.cc

Issue 2352533003: [Autofill] Migrate ChromePasswordManagerClient<-->PasswordGenerationAgent IPCs to mojo. (Closed)
Patch Set: Rebase only Created 4 years, 2 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 "content/common/associated_interface_provider_impl.h" 5 #include "content/common/associated_interface_provider_impl.h"
6 #include "mojo/public/cpp/bindings/associated_binding.h"
7 #include "mojo/public/cpp/bindings/binding.h"
6 8
7 namespace content { 9 namespace content {
8 10
11 class AssociatedInterfaceProviderImpl::LocalProvider
12 : public mojom::RouteProvider,
13 mojom::AssociatedInterfaceProvider {
14 public:
15 explicit LocalProvider(mojom::AssociatedInterfaceProviderAssociatedPtr* proxy)
16 : route_provider_binding_(this),
17 associated_interface_provider_binding_(this) {
18 route_provider_binding_.Bind(mojo::GetProxy(&route_provider_ptr_));
19 route_provider_ptr_->GetRoute(
20 0, mojo::GetProxy(proxy, route_provider_ptr_.associated_group()));
21 }
22
23 ~LocalProvider() override {}
24
25 void SetBinderForName(
26 const std::string& name,
27 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) {
28 binders_[name] = binder;
29 }
30
31 private:
32 // mojom::RouteProvider:
33 void GetRoute(
34 int32_t routing_id,
35 mojom::AssociatedInterfaceProviderAssociatedRequest request) override {
36 DCHECK(request.is_pending());
37 associated_interface_provider_binding_.Bind(std::move(request));
38 }
39
40 // mojom::AssociatedInterfaceProvider:
41 void GetAssociatedInterface(
42 const std::string& name,
43 mojom::AssociatedInterfaceAssociatedRequest request) override {
44 auto it = binders_.find(name);
45 if (it != binders_.end())
46 it->second.Run(request.PassHandle());
47 }
48
49 using BinderMap =
50 std::map<std::string,
51 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>>;
52 BinderMap binders_;
53
54 mojom::RouteProviderPtr route_provider_ptr_;
55 mojo::Binding<mojom::RouteProvider> route_provider_binding_;
56
57 mojo::AssociatedBinding<mojom::AssociatedInterfaceProvider>
58 associated_interface_provider_binding_;
59 };
60
9 AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl( 61 AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl(
10 mojom::AssociatedInterfaceProviderAssociatedPtr proxy) 62 mojom::AssociatedInterfaceProviderAssociatedPtr proxy)
11 : proxy_(std::move(proxy)) { 63 : proxy_(std::move(proxy)) {
64 DCHECK(proxy_.is_bound());
12 } 65 }
13 66
67 AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl()
68 : local_provider_(new LocalProvider(&proxy_)) {}
69
14 AssociatedInterfaceProviderImpl::~AssociatedInterfaceProviderImpl() {} 70 AssociatedInterfaceProviderImpl::~AssociatedInterfaceProviderImpl() {}
15 71
16 void AssociatedInterfaceProviderImpl::GetInterface( 72 void AssociatedInterfaceProviderImpl::GetInterface(
17 const std::string& name, 73 const std::string& name,
18 mojo::ScopedInterfaceEndpointHandle handle) { 74 mojo::ScopedInterfaceEndpointHandle handle) {
19 mojom::AssociatedInterfaceAssociatedRequest request; 75 mojom::AssociatedInterfaceAssociatedRequest request;
20 request.Bind(std::move(handle)); 76 request.Bind(std::move(handle));
21 return proxy_->GetAssociatedInterface(name, std::move(request)); 77 return proxy_->GetAssociatedInterface(name, std::move(request));
22 } 78 }
23 79
24 mojo::AssociatedGroup* AssociatedInterfaceProviderImpl::GetAssociatedGroup() { 80 mojo::AssociatedGroup* AssociatedInterfaceProviderImpl::GetAssociatedGroup() {
25 return proxy_.associated_group(); 81 return proxy_.associated_group();
26 } 82 }
27 83
84 void AssociatedInterfaceProviderImpl::OverrideBinderForTesting(
85 const std::string& name,
86 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) {
87 DCHECK(local_provider_);
88 local_provider_->SetBinderForName(name, binder);
89 }
90
28 } // namespace content 91 } // namespace content
OLDNEW
« no previous file with comments | « content/common/associated_interface_provider_impl.h ('k') | content/public/common/associated_interface_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698