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

Unified Diff: net/dns/host_resolver_mojo_host.cc

Issue 862813002: WIP: Prototype OOP V8 PAC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Slight cleanup and report JS memory usage. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/dns/host_resolver_mojo_host.h ('k') | net/net.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_mojo_host.cc
diff --git a/net/dns/host_resolver_mojo_host.cc b/net/dns/host_resolver_mojo_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ee8a4579c8d78168bdfff54434c902951307f30
--- /dev/null
+++ b/net/dns/host_resolver_mojo_host.cc
@@ -0,0 +1,107 @@
+// 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 "mojo/common/common_type_converters.h"
+#include "net/base/net_errors.h"
+#include "net/dns/host_resolver_mojo_host.h"
+#include "url/gurl.h"
+
+namespace net {
+
+class HostResolverMojoHost::Job : public mojo::ErrorHandler {
+ public:
+ Job(HostResolver* resolver,
+ const HostResolver::RequestInfo& request_info,
+ dns::ResolveRequestClientPtr client);
+
+ private:
+ void OnResolveDone(int32_t result);
+
+ // mojo::ErrorHandler override.
+ void OnConnectionError() override;
+
+ HostResolver* resolver_;
+ dns::ResolveRequestClientPtr client_;
+ HostResolver::RequestHandle handle_;
+ AddressList result_;
+ BoundNetLog net_log_;
+ std::string target_;
+};
+
+HostResolverMojoHost::HostResolverMojoHost(HostResolver* resolver)
+ : resolver_(resolver) {
+}
+
+void HostResolverMojoHost::Resolve(dns::RequestInfoPtr request_info,
+ dns::ResolveRequestClientPtr client) {
+ new Job(resolver_, request_info->To<HostResolver::RequestInfo>(),
+ client.Pass());
+}
+
+HostResolverMojoHost::Job::Job(HostResolver* resolver,
+ const HostResolver::RequestInfo& request_info,
+ dns::ResolveRequestClientPtr client)
+ : resolver_(resolver),
+ client_(client.Pass()),
+ handle_(nullptr),
+ target_(request_info.host_port_pair().ToString()) {
+ VLOG(1) << "Resolve " << request_info.host_port_pair().ToString();
+ int32_t result =
+ resolver_->Resolve(request_info, DEFAULT_PRIORITY, &result_,
+ base::Bind(&HostResolverMojoHost::Job::OnResolveDone,
+ base::Unretained(this)),
+ &handle_, net_log_);
+ if (result != ERR_IO_PENDING)
+ OnResolveDone(result);
+}
+
+void HostResolverMojoHost::Job::OnResolveDone(int32_t result) {
+ VLOG(1) << "Resolved " << target_ << " with error " << result << " and "
+ << result_.size() << " results!";
+ for (const auto& address : result_) {
+ VLOG(1) << address.ToString();
+ }
+ if (result)
+ client_->ReportError(result);
+ else
+ client_->ReportResult(dns::AddressList::From(result_));
+ delete this;
+}
+
+void HostResolverMojoHost::Job::OnConnectionError() {
+ resolver_->CancelRequest(handle_);
+ delete this;
+}
+
+} // namespace net
+
+namespace mojo {
+
+// static
+net::HostResolver::RequestInfo
+TypeConverter<net::HostResolver::RequestInfo, net::dns::RequestInfo>::Convert(
+ const net::dns::RequestInfo& obj) {
+ net::HostResolver::RequestInfo result(
+ net::HostPortPair::FromString(obj.host_port_pair));
+ result.set_address_family(
+ static_cast<net::AddressFamily>(obj.address_family));
+ return result;
+}
+
+// static
+net::dns::AddressListPtr
+TypeConverter<net::dns::AddressListPtr, net::AddressList>::Convert(
+ const net::AddressList& obj) {
+ net::dns::AddressListPtr result(net::dns::AddressList::New());
+ result->canonical_name = obj.canonical_name();
+ for (const auto& endpoint : obj) {
+ const auto& address = endpoint.address();
+ mojo::Array<uint8_t> serialized_address(address.size());
+ std::copy(address.begin(), address.end(), &serialized_address[0]);
+ result->addresses.push_back(serialized_address.Pass());
+ }
+ return result.Pass();
+}
+
+} // namespace mojo
« no previous file with comments | « net/dns/host_resolver_mojo_host.h ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698