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 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Make sure that |host| will not be re-mapped or even processed by underlying | 121 // Make sure that |host| will not be re-mapped or even processed by underlying |
122 // host resolver procedures. It can also be a pattern. | 122 // host resolver procedures. It can also be a pattern. |
123 void AllowDirectLookup(const std::string& host); | 123 void AllowDirectLookup(const std::string& host); |
124 | 124 |
125 // Simulate a lookup failure for |host| (it also can be a pattern). | 125 // Simulate a lookup failure for |host| (it also can be a pattern). |
126 void AddSimulatedFailure(const std::string& host); | 126 void AddSimulatedFailure(const std::string& host); |
127 | 127 |
128 // HostResolverProc methods: | 128 // HostResolverProc methods: |
129 virtual int Resolve(const std::string& host, | 129 virtual int Resolve(const std::string& host, |
130 AddressFamily address_family, | 130 AddressFamily address_family, |
131 HostResolverFlags host_resolver_flags, | |
132 AddressList* addrlist); | 131 AddressList* addrlist); |
133 | 132 |
134 private: | 133 private: |
135 ~RuleBasedHostResolverProc(); | 134 ~RuleBasedHostResolverProc(); |
136 | 135 |
137 struct Rule; | 136 struct Rule; |
138 typedef std::list<Rule> RuleList; | 137 typedef std::list<Rule> RuleList; |
139 | 138 |
140 RuleList rules_; | 139 RuleList rules_; |
141 }; | 140 }; |
142 | 141 |
143 // Using WaitingHostResolverProc you can simulate very long lookups. | 142 // Using WaitingHostResolverProc you can simulate very long lookups. |
144 class WaitingHostResolverProc : public HostResolverProc { | 143 class WaitingHostResolverProc : public HostResolverProc { |
145 public: | 144 public: |
146 explicit WaitingHostResolverProc(HostResolverProc* previous) | 145 explicit WaitingHostResolverProc(HostResolverProc* previous) |
147 : HostResolverProc(previous), event_(false, false) {} | 146 : HostResolverProc(previous), event_(false, false) {} |
148 | 147 |
149 void Signal() { | 148 void Signal() { |
150 event_.Signal(); | 149 event_.Signal(); |
151 } | 150 } |
152 | 151 |
153 // HostResolverProc methods: | 152 // HostResolverProc methods: |
154 virtual int Resolve(const std::string& host, | 153 virtual int Resolve(const std::string& host, |
155 AddressFamily address_family, | 154 AddressFamily address_family, |
156 HostResolverFlags host_resolver_flags, | |
157 AddressList* addrlist) { | 155 AddressList* addrlist) { |
158 event_.Wait(); | 156 event_.Wait(); |
159 return ResolveUsingPrevious(host, address_family, host_resolver_flags, | 157 return ResolveUsingPrevious(host, address_family, addrlist); |
160 addrlist); | |
161 } | 158 } |
162 | 159 |
163 private: | 160 private: |
164 ~WaitingHostResolverProc() {} | 161 ~WaitingHostResolverProc() {} |
165 | 162 |
166 base::WaitableEvent event_; | 163 base::WaitableEvent event_; |
167 }; | 164 }; |
168 | 165 |
169 // This class sets the default HostResolverProc for a particular scope. The | 166 // This class sets the default HostResolverProc for a particular scope. The |
170 // chain of resolver procs starting at |proc| is placed in front of any existing | 167 // chain of resolver procs starting at |proc| is placed in front of any existing |
(...skipping 14 matching lines...) Expand all Loading... |
185 void Init(HostResolverProc* proc); | 182 void Init(HostResolverProc* proc); |
186 | 183 |
187 private: | 184 private: |
188 scoped_refptr<HostResolverProc> current_proc_; | 185 scoped_refptr<HostResolverProc> current_proc_; |
189 scoped_refptr<HostResolverProc> previous_proc_; | 186 scoped_refptr<HostResolverProc> previous_proc_; |
190 }; | 187 }; |
191 | 188 |
192 } // namespace net | 189 } // namespace net |
193 | 190 |
194 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ | 191 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ |
OLD | NEW |