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

Side by Side Diff: net/dns/host_resolver_mojo.cc

Issue 904313003: Implement utility-side host resolver Mojo client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-proxy-resolver
Patch Set: Created 5 years, 10 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/dns/host_resolver_mojo.h"
6
7 #include "net/base/net_errors.h"
8 #include "net/base/net_log.h"
9 #include "net/dns/type_converters.h"
10 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
11 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
12
13 namespace net {
14
15 class HostResolverMojo::Job : public interfaces::HostResolverRequestClient,
16 public mojo::ErrorHandler {
17 public:
18 Job(AddressList* addresses,
19 const CompletionCallback& callback,
20 mojo::InterfaceRequest<interfaces::HostResolverRequestClient> request);
21
22 private:
23 // interfaces::HostResolverRequestClient override.
24 void ReportResult(int32_t error,
25 interfaces::AddressListPtr address_list) override;
26
27 // mojo::ErrorHandler override.
28 void OnConnectionError() override;
29
30 AddressList* addresses_;
31 CompletionCallback callback_;
32 mojo::Binding<interfaces::HostResolverRequestClient> binding_;
33 };
34
35 HostResolverMojo::HostResolverMojo(interfaces::HostResolverPtr resolver,
36 mojo::ErrorHandler* error_handler)
37 : resolver_(resolver.Pass()) {
38 if (error_handler)
39 resolver_.set_error_handler(error_handler);
40 }
41
42 HostResolverMojo::~HostResolverMojo() = default;
43
44 int HostResolverMojo::Resolve(const RequestInfo& info,
45 RequestPriority priority,
46 AddressList* addresses,
47 const CompletionCallback& callback,
48 RequestHandle* request_handle,
49 const BoundNetLog& source_net_log) {
50 DCHECK(thread_checker_.CalledOnValidThread());
51 DVLOG(1) << "Resolve " << info.host_port_pair().ToString();
52 mojo::InterfacePtr<interfaces::HostResolverRequestClient> handle;
Anand Mistry (off Chromium) 2015/02/16 06:32:44 This is interfaces::HostResolverRequestClientPtr r
Sam McNally 2015/02/16 07:24:44 interfaces::HostResolverRequestClientPtr.
53 *request_handle = new Job(addresses, callback, mojo::GetProxy(&handle));
54 resolver_->Resolve(interfaces::HostResolverRequestInfo::From(info),
55 handle.Pass());
56 return ERR_IO_PENDING;
57 }
58
59 int HostResolverMojo::ResolveFromCache(const RequestInfo& info,
60 AddressList* addresses,
61 const BoundNetLog& source_net_log) {
62 DCHECK(thread_checker_.CalledOnValidThread());
63 DVLOG(1) << "ResolveFromCache " << info.host_port_pair().ToString();
64 // TODO(sammc): Support caching.
65 return ERR_DNS_CACHE_MISS;
66 }
67
68 void HostResolverMojo::CancelRequest(RequestHandle req) {
69 DCHECK(thread_checker_.CalledOnValidThread());
70 // Deleting the Job closes the HostResolverRequestClient connection,
71 // signalling cancellation of the request.
72 delete static_cast<Job*>(req);
73 }
74
75 HostResolverMojo::Job::Job(
76 AddressList* addresses,
77 const CompletionCallback& callback,
78 mojo::InterfaceRequest<interfaces::HostResolverRequestClient> request)
79 : addresses_(addresses),
80 callback_(callback),
81 binding_(this, request.Pass()) {
82 binding_.set_error_handler(this);
83 }
84
85 void HostResolverMojo::Job::ReportResult(
86 int32_t error,
87 interfaces::AddressListPtr address_list) {
88 if (error == OK && address_list)
89 *addresses_ = address_list->To<AddressList>();
90 callback_.Run(error);
91 delete this;
92 }
93
94 void HostResolverMojo::Job::OnConnectionError() {
95 ReportResult(ERR_FAILED, interfaces::AddressListPtr());
96 }
97
98 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698