| OLD | NEW |
| 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 <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 void set_ondemand_mode(bool is_ondemand) { | 72 void set_ondemand_mode(bool is_ondemand) { |
| 73 ondemand_mode_ = is_ondemand; | 73 ondemand_mode_ = is_ondemand; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // HostResolver methods: | 76 // HostResolver methods: |
| 77 virtual int Resolve(const RequestInfo& info, | 77 virtual int Resolve(const RequestInfo& info, |
| 78 RequestPriority priority, | 78 RequestPriority priority, |
| 79 AddressList* addresses, | 79 AddressList* addresses, |
| 80 const CompletionCallback& callback, | 80 const CompletionCallback& callback, |
| 81 RequestHandle* out_req, | 81 RequestHandle* out_req, |
| 82 const BoundNetLog& net_log) OVERRIDE; | 82 const BoundNetLog& net_log) override; |
| 83 virtual int ResolveFromCache(const RequestInfo& info, | 83 virtual int ResolveFromCache(const RequestInfo& info, |
| 84 AddressList* addresses, | 84 AddressList* addresses, |
| 85 const BoundNetLog& net_log) OVERRIDE; | 85 const BoundNetLog& net_log) override; |
| 86 virtual void CancelRequest(RequestHandle req) OVERRIDE; | 86 virtual void CancelRequest(RequestHandle req) override; |
| 87 virtual HostCache* GetHostCache() OVERRIDE; | 87 virtual HostCache* GetHostCache() override; |
| 88 | 88 |
| 89 // Resolves all pending requests. It is only valid to invoke this if | 89 // Resolves all pending requests. It is only valid to invoke this if |
| 90 // set_ondemand_mode was set before. The requests are resolved asynchronously, | 90 // set_ondemand_mode was set before. The requests are resolved asynchronously, |
| 91 // after this call returns. | 91 // after this call returns. |
| 92 void ResolveAllPending(); | 92 void ResolveAllPending(); |
| 93 | 93 |
| 94 // Returns true if there are pending requests that can be resolved by invoking | 94 // Returns true if there are pending requests that can be resolved by invoking |
| 95 // ResolveAllPending(). | 95 // ResolveAllPending(). |
| 96 bool has_pending_requests() const { return !requests_.empty(); } | 96 bool has_pending_requests() const { return !requests_.empty(); } |
| 97 | 97 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void AddSimulatedFailure(const std::string& host); | 199 void AddSimulatedFailure(const std::string& host); |
| 200 | 200 |
| 201 // Deletes all the rules that have been added. | 201 // Deletes all the rules that have been added. |
| 202 void ClearRules(); | 202 void ClearRules(); |
| 203 | 203 |
| 204 // HostResolverProc methods: | 204 // HostResolverProc methods: |
| 205 virtual int Resolve(const std::string& host, | 205 virtual int Resolve(const std::string& host, |
| 206 AddressFamily address_family, | 206 AddressFamily address_family, |
| 207 HostResolverFlags host_resolver_flags, | 207 HostResolverFlags host_resolver_flags, |
| 208 AddressList* addrlist, | 208 AddressList* addrlist, |
| 209 int* os_error) OVERRIDE; | 209 int* os_error) override; |
| 210 | 210 |
| 211 private: | 211 private: |
| 212 struct Rule; | 212 struct Rule; |
| 213 typedef std::list<Rule> RuleList; | 213 typedef std::list<Rule> RuleList; |
| 214 | 214 |
| 215 virtual ~RuleBasedHostResolverProc(); | 215 virtual ~RuleBasedHostResolverProc(); |
| 216 | 216 |
| 217 RuleList rules_; | 217 RuleList rules_; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 // Create rules that map all requests to localhost. | 220 // Create rules that map all requests to localhost. |
| 221 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc(); | 221 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc(); |
| 222 | 222 |
| 223 // HangingHostResolver never completes its |Resolve| request. | 223 // HangingHostResolver never completes its |Resolve| request. |
| 224 class HangingHostResolver : public HostResolver { | 224 class HangingHostResolver : public HostResolver { |
| 225 public: | 225 public: |
| 226 virtual int Resolve(const RequestInfo& info, | 226 virtual int Resolve(const RequestInfo& info, |
| 227 RequestPriority priority, | 227 RequestPriority priority, |
| 228 AddressList* addresses, | 228 AddressList* addresses, |
| 229 const CompletionCallback& callback, | 229 const CompletionCallback& callback, |
| 230 RequestHandle* out_req, | 230 RequestHandle* out_req, |
| 231 const BoundNetLog& net_log) OVERRIDE; | 231 const BoundNetLog& net_log) override; |
| 232 virtual int ResolveFromCache(const RequestInfo& info, | 232 virtual int ResolveFromCache(const RequestInfo& info, |
| 233 AddressList* addresses, | 233 AddressList* addresses, |
| 234 const BoundNetLog& net_log) OVERRIDE; | 234 const BoundNetLog& net_log) override; |
| 235 virtual void CancelRequest(RequestHandle req) OVERRIDE {} | 235 virtual void CancelRequest(RequestHandle req) override {} |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 // This class sets the default HostResolverProc for a particular scope. The | 238 // This class sets the default HostResolverProc for a particular scope. The |
| 239 // chain of resolver procs starting at |proc| is placed in front of any existing | 239 // chain of resolver procs starting at |proc| is placed in front of any existing |
| 240 // default resolver proc(s). This means that if multiple | 240 // default resolver proc(s). This means that if multiple |
| 241 // ScopedDefaultHostResolverProcs are declared, then resolving will start with | 241 // ScopedDefaultHostResolverProcs are declared, then resolving will start with |
| 242 // the procs given to the last-allocated one, then fall back to the procs given | 242 // the procs given to the last-allocated one, then fall back to the procs given |
| 243 // to the previously-allocated one, and so forth. | 243 // to the previously-allocated one, and so forth. |
| 244 // | 244 // |
| 245 // NOTE: Only use this as a catch-all safety net. Individual tests should use | 245 // NOTE: Only use this as a catch-all safety net. Individual tests should use |
| 246 // MockHostResolver. | 246 // MockHostResolver. |
| 247 class ScopedDefaultHostResolverProc { | 247 class ScopedDefaultHostResolverProc { |
| 248 public: | 248 public: |
| 249 ScopedDefaultHostResolverProc(); | 249 ScopedDefaultHostResolverProc(); |
| 250 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc); | 250 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc); |
| 251 | 251 |
| 252 ~ScopedDefaultHostResolverProc(); | 252 ~ScopedDefaultHostResolverProc(); |
| 253 | 253 |
| 254 void Init(HostResolverProc* proc); | 254 void Init(HostResolverProc* proc); |
| 255 | 255 |
| 256 private: | 256 private: |
| 257 scoped_refptr<HostResolverProc> current_proc_; | 257 scoped_refptr<HostResolverProc> current_proc_; |
| 258 scoped_refptr<HostResolverProc> previous_proc_; | 258 scoped_refptr<HostResolverProc> previous_proc_; |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 } // namespace net | 261 } // namespace net |
| 262 | 262 |
| 263 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_ | 263 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_ |
| OLD | NEW |