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, |
131 AddressList* addrlist); | 132 AddressList* addrlist); |
132 | 133 |
133 private: | 134 private: |
134 ~RuleBasedHostResolverProc(); | 135 ~RuleBasedHostResolverProc(); |
135 | 136 |
136 struct Rule; | 137 struct Rule; |
137 typedef std::list<Rule> RuleList; | 138 typedef std::list<Rule> RuleList; |
138 | 139 |
139 RuleList rules_; | 140 RuleList rules_; |
140 }; | 141 }; |
141 | 142 |
142 // Using WaitingHostResolverProc you can simulate very long lookups. | 143 // Using WaitingHostResolverProc you can simulate very long lookups. |
143 class WaitingHostResolverProc : public HostResolverProc { | 144 class WaitingHostResolverProc : public HostResolverProc { |
144 public: | 145 public: |
145 explicit WaitingHostResolverProc(HostResolverProc* previous) | 146 explicit WaitingHostResolverProc(HostResolverProc* previous) |
146 : HostResolverProc(previous), event_(false, false) {} | 147 : HostResolverProc(previous), event_(false, false) {} |
147 | 148 |
148 void Signal() { | 149 void Signal() { |
149 event_.Signal(); | 150 event_.Signal(); |
150 } | 151 } |
151 | 152 |
152 // HostResolverProc methods: | 153 // HostResolverProc methods: |
153 virtual int Resolve(const std::string& host, | 154 virtual int Resolve(const std::string& host, |
154 AddressFamily address_family, | 155 AddressFamily address_family, |
| 156 HostResolverFlags host_resolver_flags, |
155 AddressList* addrlist) { | 157 AddressList* addrlist) { |
156 event_.Wait(); | 158 event_.Wait(); |
157 return ResolveUsingPrevious(host, address_family, addrlist); | 159 return ResolveUsingPrevious(host, address_family, host_resolver_flags, |
| 160 addrlist); |
158 } | 161 } |
159 | 162 |
160 private: | 163 private: |
161 ~WaitingHostResolverProc() {} | 164 ~WaitingHostResolverProc() {} |
162 | 165 |
163 base::WaitableEvent event_; | 166 base::WaitableEvent event_; |
164 }; | 167 }; |
165 | 168 |
166 // This class sets the default HostResolverProc for a particular scope. The | 169 // This class sets the default HostResolverProc for a particular scope. The |
167 // chain of resolver procs starting at |proc| is placed in front of any existing | 170 // chain of resolver procs starting at |proc| is placed in front of any existing |
(...skipping 14 matching lines...) Expand all Loading... |
182 void Init(HostResolverProc* proc); | 185 void Init(HostResolverProc* proc); |
183 | 186 |
184 private: | 187 private: |
185 scoped_refptr<HostResolverProc> current_proc_; | 188 scoped_refptr<HostResolverProc> current_proc_; |
186 scoped_refptr<HostResolverProc> previous_proc_; | 189 scoped_refptr<HostResolverProc> previous_proc_; |
187 }; | 190 }; |
188 | 191 |
189 } // namespace net | 192 } // namespace net |
190 | 193 |
191 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ | 194 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ |
OLD | NEW |