Index: net/dns/host_resolver_mojo.cc |
diff --git a/net/dns/host_resolver_mojo.cc b/net/dns/host_resolver_mojo.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c93f99f936ffe29b300d4aaf5350d94f4d889d91 |
--- /dev/null |
+++ b/net/dns/host_resolver_mojo.cc |
@@ -0,0 +1,100 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/dns/host_resolver_mojo.h" |
+ |
+#include "net/base/net_errors.h" |
+#include "net/base/net_log.h" |
+#include "net/dns/type_converters.h" |
+#include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
+#include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
+ |
+namespace net { |
+ |
+class HostResolverMojo::Job : public interfaces::HostResolverRequestClient, |
+ public mojo::ErrorHandler { |
+ public: |
+ Job(AddressList* addresses, |
+ const CompletionCallback& callback, |
+ mojo::InterfaceRequest<interfaces::HostResolverRequestClient> request); |
+ |
+ private: |
+ // interfaces::HostResolverRequestClient override. |
+ 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.
|
+ interfaces::AddressListPtr address_list) override; |
+ |
+ // mojo::ErrorHandler override. |
+ void OnConnectionError() override; |
+ |
+ AddressList* addresses_; |
+ CompletionCallback callback_; |
+ mojo::Binding<interfaces::HostResolverRequestClient> binding_; |
+}; |
+ |
+HostResolverMojo::HostResolverMojo(interfaces::HostResolverPtr resolver, |
+ mojo::ErrorHandler* error_handler) |
+ : resolver_(resolver.Pass()) { |
+ if (error_handler) |
+ resolver_.set_error_handler(error_handler); |
+} |
+ |
+HostResolverMojo::~HostResolverMojo() = default; |
+ |
+int HostResolverMojo::Resolve(const RequestInfo& info, |
+ RequestPriority priority, |
+ AddressList* addresses, |
+ const CompletionCallback& callback, |
+ RequestHandle* request_handle, |
+ const BoundNetLog& source_net_log) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ DVLOG(1) << "Resolve " << info.host_port_pair().ToString(); |
+ mojo::InterfacePtr<interfaces::HostResolverRequestClient> handle; |
+ *request_handle = new Job(addresses, callback, mojo::GetProxy(&handle)); |
+ resolver_->Resolve(interfaces::HostResolverRequestInfo::From(info), |
+ handle.Pass()); |
+ return ERR_IO_PENDING; |
+} |
+ |
+int HostResolverMojo::ResolveFromCache(const RequestInfo& info, |
+ AddressList* addresses, |
+ const BoundNetLog& source_net_log) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ DVLOG(1) << "ResolveFromCache " << info.host_port_pair().ToString(); |
+ // TODO(sammc): Support caching. |
+ 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.
|
+} |
+ |
+void HostResolverMojo::CancelRequest(RequestHandle req) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ 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
|
+} |
+ |
+HostResolverMojo::Job::Job( |
+ AddressList* addresses, |
+ const CompletionCallback& callback, |
+ mojo::InterfaceRequest<interfaces::HostResolverRequestClient> request) |
+ : addresses_(addresses), |
+ callback_(callback), |
+ binding_(this, request.Pass()) { |
+ binding_.set_error_handler(this); |
+} |
+ |
+void HostResolverMojo::Job::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.
|
+ interfaces::AddressListPtr address_list) { |
+ if (error == OK) { |
+ if (address_list) |
+ *addresses_ = address_list->To<AddressList>(); |
+ else |
+ 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
|
+ } |
+ callback_.Run(error); |
+ delete this; |
+} |
+ |
+void HostResolverMojo::Job::OnConnectionError() { |
+ ReportResult(ERR_FAILED, interfaces::AddressListPtr()); |
+} |
+ |
+} // namespace net |