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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « net/dns/host_resolver_proc.cc ('k') | net/dns/mapped_host_resolver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #ifndef NET_DNS_MAPPED_HOST_RESOLVER_H_
6 #define NET_DNS_MAPPED_HOST_RESOLVER_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/host_mapping_rules.h"
12 #include "net/base/net_export.h"
13 #include "net/dns/host_resolver.h"
14
15 namespace net {
16
17 // This class wraps an existing HostResolver instance, but modifies the
18 // request before passing it off to |impl|. This is different from
19 // MockHostResolver which does the remapping at the HostResolverProc
20 // layer, so it is able to preserve the effectiveness of the cache.
21 class NET_EXPORT MappedHostResolver : public HostResolver {
22 public:
23 // Creates a MappedHostResolver that forwards all of its requests through
24 // |impl|.
25 explicit MappedHostResolver(scoped_ptr<HostResolver> impl);
26 ~MappedHostResolver() override;
27
28 // Adds a rule to this mapper. The format of the rule can be one of:
29 //
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.
38 bool AddRuleFromString(const std::string& rule_string) {
39 return rules_.AddRuleFromString(rule_string);
40 }
41
42 // Takes a comma separated list of rules, and assigns them to this resolver.
43 void SetRulesFromString(const std::string& rules_string) {
44 rules_.SetRulesFromString(rules_string);
45 }
46
47 // HostResolver methods:
48 int Resolve(const RequestInfo& info,
49 RequestPriority priority,
50 AddressList* addresses,
51 const CompletionCallback& callback,
52 RequestHandle* out_req,
53 const BoundNetLog& net_log) override;
54 int ResolveFromCache(const RequestInfo& info,
55 AddressList* addresses,
56 const BoundNetLog& net_log) override;
57 void CancelRequest(RequestHandle req) override;
58 void SetDnsClientEnabled(bool enabled) override;
59 HostCache* GetHostCache() override;
60 base::Value* GetDnsConfigAsValue() const override;
61
62 private:
63 // Modify the request |info| according to |rules_|. Returns either OK or
64 // the network error code that the hostname's resolution mapped to.
65 int ApplyRules(RequestInfo* info) const;
66
67 scoped_ptr<HostResolver> impl_;
68
69 HostMappingRules rules_;
70 };
71
72 } // namespace net
73
74 #endif // NET_DNS_MAPPED_HOST_RESOLVER_H_
OLDNEW
« no previous file with comments | « net/dns/host_resolver_proc.cc ('k') | net/dns/mapped_host_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698