mapped_host_resolver.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 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/mapped_host_resolver.h"
6
7#include "base/string_util.h"
8#include "net/base/host_port_pair.h"
9#include "net/base/net_errors.h"
10#include "net/base/net_util.h"
11
12namespace net {
13
14MappedHostResolver::MappedHostResolver(scoped_ptr<HostResolver> impl)
15    : impl_(impl.Pass()) {
16}
17
18MappedHostResolver::~MappedHostResolver() {
19}
20
21int MappedHostResolver::Resolve(const RequestInfo& original_info,
22                                AddressList* addresses,
23                                const CompletionCallback& callback,
24                                RequestHandle* out_req,
25                                const BoundNetLog& net_log) {
26  RequestInfo info = original_info;
27  int rv = ApplyRules(&info);
28  if (rv != OK)
29    return rv;
30
31  return impl_->Resolve(info, addresses, callback, out_req, net_log);
32}
33
34int MappedHostResolver::ResolveFromCache(const RequestInfo& original_info,
35                                         AddressList* addresses,
36                                         const BoundNetLog& net_log) {
37  RequestInfo info = original_info;
38  int rv = ApplyRules(&info);
39  if (rv != OK)
40    return rv;
41
42  return impl_->ResolveFromCache(info, addresses, net_log);
43}
44
45void MappedHostResolver::CancelRequest(RequestHandle req) {
46  impl_->CancelRequest(req);
47}
48
49void MappedHostResolver::ProbeIPv6Support() {
50  impl_->ProbeIPv6Support();
51}
52
53HostCache* MappedHostResolver::GetHostCache() {
54  return impl_->GetHostCache();
55}
56
57int MappedHostResolver::ApplyRules(RequestInfo* info) const {
58  HostPortPair host_port(info->host_port_pair());
59  if (rules_.RewriteHost(&host_port)) {
60    if (host_port.host() == "~NOTFOUND")
61      return ERR_NAME_NOT_RESOLVED;
62    info->set_host_port_pair(host_port);
63  }
64  return OK;
65}
66
67}  // namespace net
68