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

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

Issue 2837813004: Sync the browser test host resolver with the network process before a test runs. (Closed)
Patch Set: fix release builds Created 3 years, 8 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
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_DNS_MOCK_HOST_RESOLVER_H_ 5 #ifndef NET_DNS_MOCK_HOST_RESOLVER_H_
6 #define NET_DNS_MOCK_HOST_RESOLVER_H_ 6 #define NET_DNS_MOCK_HOST_RESOLVER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Make sure that |host| will not be re-mapped or even processed by underlying 205 // Make sure that |host| will not be re-mapped or even processed by underlying
206 // host resolver procedures. It can also be a pattern. 206 // host resolver procedures. It can also be a pattern.
207 void AllowDirectLookup(const std::string& host); 207 void AllowDirectLookup(const std::string& host);
208 208
209 // Simulate a lookup failure for |host| (it also can be a pattern). 209 // Simulate a lookup failure for |host| (it also can be a pattern).
210 void AddSimulatedFailure(const std::string& host); 210 void AddSimulatedFailure(const std::string& host);
211 211
212 // Deletes all the rules that have been added. 212 // Deletes all the rules that have been added.
213 void ClearRules(); 213 void ClearRules();
214 214
215 // Asserts if any changes are made to the rules after this call.
mmenke 2017/04/25 16:37:53 Could you clarify that this makes calls that add/r
jam 2017/04/25 17:04:40 "after this call" isn't clear enough?
mmenke 2017/04/25 17:44:44 Oops, forgot to respond to this. My feeling is th
mmenke 2017/04/25 18:10:08 A better explanation: This method does not "Asser
jam 2017/04/25 18:19:37 Done.
216 void Lock();
mmenke 2017/04/25 16:37:55 Add a TODO to remove this, once it's no longer use
mmenke 2017/04/25 16:37:55 Can we not call this lock? Commit() or Initialize
jam 2017/04/25 17:04:40 Done.
jam 2017/04/25 17:04:40 Done.
217
215 // HostResolverProc methods: 218 // HostResolverProc methods:
216 int Resolve(const std::string& host, 219 int Resolve(const std::string& host,
217 AddressFamily address_family, 220 AddressFamily address_family,
218 HostResolverFlags host_resolver_flags, 221 HostResolverFlags host_resolver_flags,
219 AddressList* addrlist, 222 AddressList* addrlist,
220 int* os_error) override; 223 int* os_error) override;
221 224
222 private: 225 struct Rule {
223 struct Rule; 226 enum ResolverType {
227 kResolverTypeFail,
228 kResolverTypeSystem,
229 kResolverTypeIPLiteral,
230 };
231
232 ResolverType resolver_type;
233 std::string host_pattern;
234 AddressFamily address_family;
235 HostResolverFlags host_resolver_flags;
236 std::string replacement;
237 std::string canonical_name;
mmenke 2017/04/25 16:37:54 include <string> (Should have been included alread
jam 2017/04/25 17:04:41 Done.
238 int latency_ms; // In milliseconds.
239
240 Rule(ResolverType resolver_type,
241 const std::string& host_pattern,
242 AddressFamily address_family,
243 HostResolverFlags host_resolver_flags,
244 const std::string& replacement,
245 const std::string& canonical_name,
246 int latency_ms);
247 Rule(const Rule& other);
mmenke 2017/04/25 16:37:56 Per style guide, constructor/destructor should go
jam 2017/04/25 17:04:40 Done.
248 };
249
224 typedef std::list<Rule> RuleList; 250 typedef std::list<Rule> RuleList;
225 251
252 RuleList GetRules();
253
254 private:
226 ~RuleBasedHostResolverProc() override; 255 ~RuleBasedHostResolverProc() override;
227 256
228 void AddRuleInternal(const Rule& rule); 257 void AddRuleInternal(const Rule& rule);
229 258
230 RuleList rules_; 259 RuleList rules_;
231 260
232 // Must be obtained before writing to or reading from |rules_|. 261 // Must be obtained before writing to or reading from |rules_|.
233 base::Lock rule_lock_; 262 base::Lock rule_lock_;
263
264 // Whether changes are allowed.
265 bool locked_;
mmenke 2017/04/25 16:37:55 Hrm...Should this be protected by the lock as well
jam 2017/04/25 17:04:40 this will be modified before any threading happens
mmenke 2017/04/25 17:29:46 SGTM (Particularly with the above TODO)
234 }; 266 };
235 267
236 // Create rules that map all requests to localhost. 268 // Create rules that map all requests to localhost.
237 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc(); 269 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc();
238 270
239 // HangingHostResolver never completes its |Resolve| request. 271 // HangingHostResolver never completes its |Resolve| request.
240 class HangingHostResolver : public HostResolver { 272 class HangingHostResolver : public HostResolver {
241 public: 273 public:
242 int Resolve(const RequestInfo& info, 274 int Resolve(const RequestInfo& info,
243 RequestPriority priority, 275 RequestPriority priority,
(...skipping 25 matching lines...) Expand all
269 void Init(HostResolverProc* proc); 301 void Init(HostResolverProc* proc);
270 302
271 private: 303 private:
272 scoped_refptr<HostResolverProc> current_proc_; 304 scoped_refptr<HostResolverProc> current_proc_;
273 scoped_refptr<HostResolverProc> previous_proc_; 305 scoped_refptr<HostResolverProc> previous_proc_;
274 }; 306 };
275 307
276 } // namespace net 308 } // namespace net
277 309
278 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_ 310 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698