• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/strings/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 
12 namespace net {
13 
MappedHostResolver(scoped_ptr<HostResolver> impl)14 MappedHostResolver::MappedHostResolver(scoped_ptr<HostResolver> impl)
15     : impl_(impl.Pass()) {
16 }
17 
~MappedHostResolver()18 MappedHostResolver::~MappedHostResolver() {
19 }
20 
Resolve(const RequestInfo & original_info,RequestPriority priority,AddressList * addresses,const CompletionCallback & callback,RequestHandle * out_req,const BoundNetLog & net_log)21 int MappedHostResolver::Resolve(const RequestInfo& original_info,
22                                 RequestPriority priority,
23                                 AddressList* addresses,
24                                 const CompletionCallback& callback,
25                                 RequestHandle* out_req,
26                                 const BoundNetLog& net_log) {
27   RequestInfo info = original_info;
28   int rv = ApplyRules(&info);
29   if (rv != OK)
30     return rv;
31 
32   return impl_->Resolve(info, priority, addresses, callback, out_req, net_log);
33 }
34 
ResolveFromCache(const RequestInfo & original_info,AddressList * addresses,const BoundNetLog & net_log)35 int MappedHostResolver::ResolveFromCache(const RequestInfo& original_info,
36                                          AddressList* addresses,
37                                          const BoundNetLog& net_log) {
38   RequestInfo info = original_info;
39   int rv = ApplyRules(&info);
40   if (rv != OK)
41     return rv;
42 
43   return impl_->ResolveFromCache(info, addresses, net_log);
44 }
45 
CancelRequest(RequestHandle req)46 void MappedHostResolver::CancelRequest(RequestHandle req) {
47   impl_->CancelRequest(req);
48 }
49 
SetDnsClientEnabled(bool enabled)50 void MappedHostResolver::SetDnsClientEnabled(bool enabled) {
51   impl_->SetDnsClientEnabled(enabled);
52 }
53 
GetHostCache()54 HostCache* MappedHostResolver::GetHostCache() {
55   return impl_->GetHostCache();
56 }
57 
GetDnsConfigAsValue() const58 base::Value* MappedHostResolver::GetDnsConfigAsValue() const {
59   return impl_->GetDnsConfigAsValue();
60 }
61 
ApplyRules(RequestInfo * info) const62 int MappedHostResolver::ApplyRules(RequestInfo* info) const {
63   HostPortPair host_port(info->host_port_pair());
64   if (rules_.RewriteHost(&host_port)) {
65     if (host_port.host() == "~NOTFOUND")
66       return ERR_NAME_NOT_RESOLVED;
67     info->set_host_port_pair(host_port);
68   }
69   return OK;
70 }
71 
72 }  // namespace net
73