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

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
« no previous file with comments | « net/dns/host_resolver_mojo.h ('k') | net/dns/host_resolver_mojo_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
eroman 2015/02/12 23:39:50 int
Sam McNally 2015/02/13 00:50:58 This is implementing the mojo interface.
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;
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_FAILED;
eroman 2015/02/12 23:39:50 Return ERR_DNS_CACHE_MISS instead. That way consum
Sam McNally 2015/02/13 00:50:58 Done.
66 }
67
68 void HostResolverMojo::CancelRequest(RequestHandle req) {
69 DCHECK(thread_checker_.CalledOnValidThread());
70 delete static_cast<Job*>(req);
eroman 2015/02/12 23:39:50 What is the mechanism through which the mojo side
Sam McNally 2015/02/13 00:50:58 It closes the mojo pipe, which the other side dete
71 }
72
73 HostResolverMojo::Job::Job(
74 AddressList* addresses,
75 const CompletionCallback& callback,
76 mojo::InterfaceRequest<interfaces::HostResolverRequestClient> request)
77 : addresses_(addresses),
78 callback_(callback),
79 binding_(this, request.Pass()) {
80 binding_.set_error_handler(this);
81 }
82
83 void HostResolverMojo::Job::ReportResult(
84 int32_t error,
eroman 2015/02/12 23:39:50 int
Sam McNally 2015/02/13 00:50:58 This is implementing the mojo interface.
85 interfaces::AddressListPtr address_list) {
86 if (error == OK) {
87 if (address_list)
88 *addresses_ = address_list->To<AddressList>();
89 else
90 error = ERR_FAILED;
eroman 2015/02/12 23:39:50 why mask the error? Wouldn't it be sufficient to p
Sam McNally 2015/02/13 00:50:58 It was only when the error was OK, but no results
91 }
92 callback_.Run(error);
93 delete this;
94 }
95
96 void HostResolverMojo::Job::OnConnectionError() {
97 ReportResult(ERR_FAILED, interfaces::AddressListPtr());
98 }
99
100 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_mojo.h ('k') | net/dns/host_resolver_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698