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

Side by Side Diff: net/dns/mapped_ip_resolver.h

Issue 156963003: Support replacement of IP address resolutions via command line flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: General cleanup Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_DNS_MAPPED_HOST_RESOLVER_H_ 5 #ifndef NET_DNS_MAPPED_IP_RESOLVER_H_
6 #define NET_DNS_MAPPED_HOST_RESOLVER_H_ 6 #define NET_DNS_MAPPED_IP_RESOLVER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/host_mapping_rules.h" 11 #include "base/memory/weak_ptr.h"
12 #include "net/base/ip_mapping_rules.h"
12 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
13 #include "net/dns/host_resolver.h" 14 #include "net/dns/host_resolver.h"
14 15
15 namespace net { 16 namespace net {
16 17
17 // This class wraps an existing HostResolver instance, but modifies the 18 // This class wraps an existing HostResolver instance, but modifies the
18 // request before passing it off to |impl|. This is different from 19 // resolution response by inserting or replacing IP addresses before returning
wtc 2014/02/11 23:52:30 You only implemented the "PREFACE" directive, righ
jar (doing other things) 2014/02/15 21:14:56 I added clarifying comments.
19 // MockHostResolver which does the remapping at the HostResolverProc 20 // it.
20 // layer, so it is able to preserve the effectiveness of the cache. 21 class NET_EXPORT MappedIPResolver : public HostResolver {
wtc 2014/02/11 23:52:30 Nit: "IPResolver" is a poor name because there is
jar (doing other things) 2014/02/15 21:14:56 As per offline discussion.... I parsed the names (
21 class NET_EXPORT MappedHostResolver : public HostResolver {
22 public: 22 public:
23 // Creates a MappedHostResolver that forwards all of its requests through 23 // Creates a MappedHostResolver that forwards all of its requests through
wtc 2014/02/11 23:52:30 MappedHostResolver => MappedIPResolver
jar (doing other things) 2014/02/15 21:14:56 Done.
24 // |impl|. 24 // |impl|.
25 explicit MappedHostResolver(scoped_ptr<HostResolver> impl); 25 explicit MappedIPResolver(scoped_ptr<HostResolver> impl);
26 virtual ~MappedHostResolver(); 26 virtual ~MappedIPResolver();
27 27
28 // Adds a rule to this mapper. The format of the rule can be one of: 28 // Adds a rule to our IP mapper rules_.
29 // 29 // See ip_mapping_rules.h for syntax and semantics.
30 // "MAP" <hostname_pattern> <replacement_host> [":" <replacement_port>]
31 // "EXCLUDE" <hostname_pattern>
32 //
33 // The <replacement_host> can be either a hostname, or an IP address literal,
34 // or "~NOTFOUND". If it is "~NOTFOUND" then all matched hostnames will fail
35 // to be resolved with ERR_NAME_NOT_RESOLVED.
36 //
37 // Returns true if the rule was successfully parsed and added. 30 // Returns true if the rule was successfully parsed and added.
38 bool AddRuleFromString(const std::string& rule_string) { 31 bool AddRuleFromString(const std::string& rule_string) {
39 return rules_.AddRuleFromString(rule_string); 32 return rules_.AddRuleFromString(rule_string);
40 } 33 }
41 34
42 // Takes a comma separated list of rules, and assigns them to this resolver. 35 // Takes a comma separated list of rules, and assigns them to this resolver.
wtc 2014/02/11 23:52:30 Typo: comma => semicolon
jar (doing other things) 2014/02/15 21:14:56 Done.
43 void SetRulesFromString(const std::string& rules_string) { 36 void SetRulesFromString(const std::string& rules_string) {
44 rules_.SetRulesFromString(rules_string); 37 rules_.SetRulesFromString(rules_string);
45 } 38 }
46 39
47 // HostResolver methods: 40 // HostResolver methods:
48 virtual int Resolve(const RequestInfo& info, 41 virtual int Resolve(const RequestInfo& info,
49 RequestPriority priority, 42 RequestPriority priority,
50 AddressList* addresses, 43 AddressList* addresses,
51 const CompletionCallback& callback, 44 const CompletionCallback& callback,
52 RequestHandle* out_req, 45 RequestHandle* out_req,
53 const BoundNetLog& net_log) OVERRIDE; 46 const BoundNetLog& net_log) OVERRIDE;
54 virtual int ResolveFromCache(const RequestInfo& info, 47 virtual int ResolveFromCache(const RequestInfo& info,
55 AddressList* addresses, 48 AddressList* addresses,
56 const BoundNetLog& net_log) OVERRIDE; 49 const BoundNetLog& net_log) OVERRIDE;
57 virtual void CancelRequest(RequestHandle req) OVERRIDE; 50 virtual void CancelRequest(RequestHandle req) OVERRIDE;
58 virtual void SetDnsClientEnabled(bool enabled) OVERRIDE; 51 virtual void SetDnsClientEnabled(bool enabled) OVERRIDE;
59 virtual HostCache* GetHostCache() OVERRIDE; 52 virtual HostCache* GetHostCache() OVERRIDE;
60 virtual base::Value* GetDnsConfigAsValue() const OVERRIDE; 53 virtual base::Value* GetDnsConfigAsValue() const OVERRIDE;
61 54
62 private: 55 private:
63 // Modify the request |info| according to |rules_|. Returns either OK or 56 // Modify the list of resolution |addresses| according to |rules_|, and then
64 // the network error code that the hostname's resolution mapped to. 57 // calls the |original_cb| with network error code |rv|.
65 int ApplyRules(RequestInfo* info) const; 58 void ApplyRules(const CompletionCallback& original_cb,
wtc 2014/02/11 23:52:30 Nit: it may be nice to be verbose and name this pa
jar (doing other things) 2014/02/15 21:14:56 Done.
59 AddressList* addresses,
60 int rv) const;
66 61
67 scoped_ptr<HostResolver> impl_; 62 scoped_ptr<HostResolver> impl_;
63 IPMappingRules rules_;
68 64
69 HostMappingRules rules_; 65 base::WeakPtrFactory<MappedIPResolver> weak_factory_;
66 DISALLOW_COPY_AND_ASSIGN(MappedIPResolver);
70 }; 67 };
71 68
72 } // namespace net 69 } // namespace net
73 70
74 #endif // NET_DNS_MAPPED_HOST_RESOLVER_H_ 71 #endif // NET_DNS_MAPPED_IP_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698