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

Side by Side Diff: net/base/mock_host_resolver.h

Issue 11885009: Improve performance of proxy resolver by tracing DNS dependencies. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: re-upload due to failure last time Created 7 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
« no previous file with comments | « net/base/capturing_net_log.cc ('k') | net/base/mock_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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_BASE_MOCK_HOST_RESOLVER_H_ 5 #ifndef NET_BASE_MOCK_HOST_RESOLVER_H_
6 #define NET_BASE_MOCK_HOST_RESOLVER_H_ 6 #define NET_BASE_MOCK_HOST_RESOLVER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 // Resolves all pending requests. It is only valid to invoke this if 88 // Resolves all pending requests. It is only valid to invoke this if
89 // set_ondemand_mode was set before. The requests are resolved asynchronously, 89 // set_ondemand_mode was set before. The requests are resolved asynchronously,
90 // after this call returns. 90 // after this call returns.
91 void ResolveAllPending(); 91 void ResolveAllPending();
92 92
93 // Returns true if there are pending requests that can be resolved by invoking 93 // Returns true if there are pending requests that can be resolved by invoking
94 // ResolveAllPending(). 94 // ResolveAllPending().
95 bool has_pending_requests() const { return !requests_.empty(); } 95 bool has_pending_requests() const { return !requests_.empty(); }
96 96
97 // The number of times that Resolve() has been called.
98 size_t num_resolve() const {
99 return num_resolve_;
100 }
101
102 // The number of times that ResolveFromCache() has been called.
103 size_t num_resolve_from_cache() const {
104 return num_resolve_from_cache_;
105 }
106
97 protected: 107 protected:
98 explicit MockHostResolverBase(bool use_caching); 108 explicit MockHostResolverBase(bool use_caching);
99 109
100 private: 110 private:
101 struct Request; 111 struct Request;
102 typedef std::map<size_t, Request*> RequestMap; 112 typedef std::map<size_t, Request*> RequestMap;
103 113
104 // Resolve as IP or from |cache_| return cached error or 114 // Resolve as IP or from |cache_| return cached error or
105 // DNS_CACHE_MISS if failed. 115 // DNS_CACHE_MISS if failed.
106 int ResolveFromIPLiteralOrCache(const RequestInfo& info, 116 int ResolveFromIPLiteralOrCache(const RequestInfo& info,
107 AddressList* addresses); 117 AddressList* addresses);
108 // Resolve via |proc_|. 118 // Resolve via |proc_|.
109 int ResolveProc(size_t id, const RequestInfo& info, AddressList* addresses); 119 int ResolveProc(size_t id, const RequestInfo& info, AddressList* addresses);
110 // Resolve request stored in |requests_|. Pass rv to callback. 120 // Resolve request stored in |requests_|. Pass rv to callback.
111 void ResolveNow(size_t id); 121 void ResolveNow(size_t id);
112 122
113 bool synchronous_mode_; 123 bool synchronous_mode_;
114 bool ondemand_mode_; 124 bool ondemand_mode_;
115 scoped_refptr<RuleBasedHostResolverProc> rules_; 125 scoped_refptr<RuleBasedHostResolverProc> rules_;
116 scoped_ptr<HostCache> cache_; 126 scoped_ptr<HostCache> cache_;
117 RequestMap requests_; 127 RequestMap requests_;
118 size_t next_request_id_; 128 size_t next_request_id_;
119 129
130 size_t num_resolve_;
131 size_t num_resolve_from_cache_;
132
120 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); 133 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase);
121 }; 134 };
122 135
123 class MockHostResolver : public MockHostResolverBase { 136 class MockHostResolver : public MockHostResolverBase {
124 public: 137 public:
125 MockHostResolver() : MockHostResolverBase(false /*use_caching*/) {} 138 MockHostResolver() : MockHostResolverBase(false /*use_caching*/) {}
126 virtual ~MockHostResolver() {} 139 virtual ~MockHostResolver() {}
127 }; 140 };
128 141
129 // Same as MockHostResolver, except internally it uses a host-cache. 142 // Same as MockHostResolver, except internally it uses a host-cache.
(...skipping 21 matching lines...) Expand all
151 const std::string& replacement); 164 const std::string& replacement);
152 165
153 // Same as AddRule(), but further restricts to |address_family|. 166 // Same as AddRule(), but further restricts to |address_family|.
154 void AddRuleForAddressFamily(const std::string& host_pattern, 167 void AddRuleForAddressFamily(const std::string& host_pattern,
155 AddressFamily address_family, 168 AddressFamily address_family,
156 const std::string& replacement); 169 const std::string& replacement);
157 170
158 // Same as AddRule(), but the replacement is expected to be an IPv4 or IPv6 171 // Same as AddRule(), but the replacement is expected to be an IPv4 or IPv6
159 // literal. This can be used in place of AddRule() to bypass the system's 172 // literal. This can be used in place of AddRule() to bypass the system's
160 // host resolver (the address list will be constructed manually). 173 // host resolver (the address list will be constructed manually).
161 // If |canonical-name| is non-empty, it is copied to the resulting AddressList 174 // If |canonical_name| is non-empty, it is copied to the resulting AddressList
162 // but does not impact DNS resolution. 175 // but does not impact DNS resolution.
176 // |ip_literal| can be a single IP address like "192.168.1.1" or a comma
177 // separated list of IP addresses, like "::1,192:168.1.2".
163 void AddIPLiteralRule(const std::string& host_pattern, 178 void AddIPLiteralRule(const std::string& host_pattern,
164 const std::string& ip_literal, 179 const std::string& ip_literal,
165 const std::string& canonical_name); 180 const std::string& canonical_name);
166 181
167 void AddRuleWithLatency(const std::string& host_pattern, 182 void AddRuleWithLatency(const std::string& host_pattern,
168 const std::string& replacement, 183 const std::string& replacement,
169 int latency_ms); 184 int latency_ms);
170 185
171 // Make sure that |host| will not be re-mapped or even processed by underlying 186 // Make sure that |host| will not be re-mapped or even processed by underlying
172 // host resolver procedures. It can also be a pattern. 187 // host resolver procedures. It can also be a pattern.
173 void AllowDirectLookup(const std::string& host); 188 void AllowDirectLookup(const std::string& host);
174 189
175 // Simulate a lookup failure for |host| (it also can be a pattern). 190 // Simulate a lookup failure for |host| (it also can be a pattern).
176 void AddSimulatedFailure(const std::string& host); 191 void AddSimulatedFailure(const std::string& host);
177 192
193 // Deletes all the rules that have been added.
194 void ClearRules();
195
178 // HostResolverProc methods: 196 // HostResolverProc methods:
179 virtual int Resolve(const std::string& host, 197 virtual int Resolve(const std::string& host,
180 AddressFamily address_family, 198 AddressFamily address_family,
181 HostResolverFlags host_resolver_flags, 199 HostResolverFlags host_resolver_flags,
182 AddressList* addrlist, 200 AddressList* addrlist,
183 int* os_error) OVERRIDE; 201 int* os_error) OVERRIDE;
184 202
185 private: 203 private:
186 struct Rule; 204 struct Rule;
187 typedef std::list<Rule> RuleList; 205 typedef std::list<Rule> RuleList;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void Init(HostResolverProc* proc); 245 void Init(HostResolverProc* proc);
228 246
229 private: 247 private:
230 scoped_refptr<HostResolverProc> current_proc_; 248 scoped_refptr<HostResolverProc> current_proc_;
231 scoped_refptr<HostResolverProc> previous_proc_; 249 scoped_refptr<HostResolverProc> previous_proc_;
232 }; 250 };
233 251
234 } // namespace net 252 } // namespace net
235 253
236 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ 254 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_
OLDNEW
« no previous file with comments | « net/base/capturing_net_log.cc ('k') | net/base/mock_host_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698