| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // host_mapper->AddRule("*.com", "127.0.0.1"); | 34 // host_mapper->AddRule("*.com", "127.0.0.1"); |
| 35 // | 35 // |
| 36 // Replacement doesn't have to be string representing an IP address. It can | 36 // Replacement doesn't have to be string representing an IP address. It can |
| 37 // re-map one hostname to another as well. | 37 // re-map one hostname to another as well. |
| 38 | 38 |
| 39 // Base class shared by MockHostResolver and MockCachingHostResolver. | 39 // Base class shared by MockHostResolver and MockCachingHostResolver. |
| 40 class MockHostResolverBase : public HostResolver { | 40 class MockHostResolverBase : public HostResolver { |
| 41 public: | 41 public: |
| 42 virtual ~MockHostResolverBase(); | 42 virtual ~MockHostResolverBase(); |
| 43 | 43 |
| 44 // HostResolver methods: | |
| 45 virtual int Resolve(const RequestInfo& info, | |
| 46 AddressList* addresses, | |
| 47 CompletionCallback* callback, | |
| 48 RequestHandle* out_req, | |
| 49 const BoundNetLog& net_log); | |
| 50 virtual void CancelRequest(RequestHandle req); | |
| 51 virtual void AddObserver(Observer* observer); | |
| 52 virtual void RemoveObserver(Observer* observer); | |
| 53 | |
| 54 RuleBasedHostResolverProc* rules() { return rules_; } | 44 RuleBasedHostResolverProc* rules() { return rules_; } |
| 55 | 45 |
| 56 // Controls whether resolutions complete synchronously or asynchronously. | 46 // Controls whether resolutions complete synchronously or asynchronously. |
| 57 void set_synchronous_mode(bool is_synchronous) { | 47 void set_synchronous_mode(bool is_synchronous) { |
| 58 synchronous_mode_ = is_synchronous; | 48 synchronous_mode_ = is_synchronous; |
| 59 } | 49 } |
| 60 | 50 |
| 61 // Resets the mock. | 51 // Resets the mock. |
| 62 void Reset(HostResolverProc* interceptor); | 52 void Reset(HostResolverProc* interceptor); |
| 63 | 53 |
| 64 void SetPoolConstraints(HostResolverImpl::JobPoolIndex pool_index, | 54 void SetPoolConstraints(HostResolverImpl::JobPoolIndex pool_index, |
| 65 size_t max_outstanding_jobs, | 55 size_t max_outstanding_jobs, |
| 66 size_t max_pending_requests) { | 56 size_t max_pending_requests) { |
| 67 impl_->SetPoolConstraints( | 57 impl_->SetPoolConstraints( |
| 68 pool_index, max_outstanding_jobs, max_pending_requests); | 58 pool_index, max_outstanding_jobs, max_pending_requests); |
| 69 } | 59 } |
| 70 | 60 |
| 61 // HostResolver methods: |
| 62 virtual int Resolve(const RequestInfo& info, |
| 63 AddressList* addresses, |
| 64 CompletionCallback* callback, |
| 65 RequestHandle* out_req, |
| 66 const BoundNetLog& net_log); |
| 67 virtual void CancelRequest(RequestHandle req); |
| 68 virtual void AddObserver(Observer* observer); |
| 69 virtual void RemoveObserver(Observer* observer); |
| 70 |
| 71 protected: | 71 protected: |
| 72 MockHostResolverBase(bool use_caching); | 72 MockHostResolverBase(bool use_caching); |
| 73 | 73 |
| 74 scoped_ptr<HostResolverImpl> impl_; | 74 scoped_ptr<HostResolverImpl> impl_; |
| 75 scoped_refptr<RuleBasedHostResolverProc> rules_; | 75 scoped_refptr<RuleBasedHostResolverProc> rules_; |
| 76 bool synchronous_mode_; | 76 bool synchronous_mode_; |
| 77 bool use_caching_; | 77 bool use_caching_; |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); | 80 DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 void AddSimulatedFailure(const std::string& host); | 136 void AddSimulatedFailure(const std::string& host); |
| 137 | 137 |
| 138 // HostResolverProc methods: | 138 // HostResolverProc methods: |
| 139 virtual int Resolve(const std::string& host, | 139 virtual int Resolve(const std::string& host, |
| 140 AddressFamily address_family, | 140 AddressFamily address_family, |
| 141 HostResolverFlags host_resolver_flags, | 141 HostResolverFlags host_resolver_flags, |
| 142 AddressList* addrlist, | 142 AddressList* addrlist, |
| 143 int* os_error); | 143 int* os_error); |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 ~RuleBasedHostResolverProc(); | |
| 147 | |
| 148 struct Rule; | 146 struct Rule; |
| 149 typedef std::list<Rule> RuleList; | 147 typedef std::list<Rule> RuleList; |
| 150 | 148 |
| 149 ~RuleBasedHostResolverProc(); |
| 150 |
| 151 RuleList rules_; | 151 RuleList rules_; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 // Using WaitingHostResolverProc you can simulate very long lookups. | 154 // Using WaitingHostResolverProc you can simulate very long lookups. |
| 155 class WaitingHostResolverProc : public HostResolverProc { | 155 class WaitingHostResolverProc : public HostResolverProc { |
| 156 public: | 156 public: |
| 157 explicit WaitingHostResolverProc(HostResolverProc* previous); | 157 explicit WaitingHostResolverProc(HostResolverProc* previous); |
| 158 | 158 |
| 159 void Signal(); | 159 void Signal(); |
| 160 | 160 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 190 void Init(HostResolverProc* proc); | 190 void Init(HostResolverProc* proc); |
| 191 | 191 |
| 192 private: | 192 private: |
| 193 scoped_refptr<HostResolverProc> current_proc_; | 193 scoped_refptr<HostResolverProc> current_proc_; |
| 194 scoped_refptr<HostResolverProc> previous_proc_; | 194 scoped_refptr<HostResolverProc> previous_proc_; |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 } // namespace net | 197 } // namespace net |
| 198 | 198 |
| 199 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ | 199 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ |
| OLD | NEW |