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

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

Issue 302010: Add a mechanism to disable IPv6.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address darin's comments Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 int latency_ms); 114 int latency_ms);
115 115
116 // Make sure that |host| will not be re-mapped or even processed by underlying 116 // Make sure that |host| will not be re-mapped or even processed by underlying
117 // host resolver procedures. It can also be a pattern. 117 // host resolver procedures. It can also be a pattern.
118 void AllowDirectLookup(const std::string& host); 118 void AllowDirectLookup(const std::string& host);
119 119
120 // Simulate a lookup failure for |host| (it also can be a pattern). 120 // Simulate a lookup failure for |host| (it also can be a pattern).
121 void AddSimulatedFailure(const std::string& host); 121 void AddSimulatedFailure(const std::string& host);
122 122
123 // HostResolverProc methods: 123 // HostResolverProc methods:
124 virtual int Resolve(const std::string& host, AddressList* addrlist); 124 virtual int Resolve(const std::string& host,
125 AddressFamily address_family,
126 AddressList* addrlist);
125 127
126 private: 128 private:
127 struct Rule; 129 struct Rule;
128 typedef std::list<Rule> RuleList; 130 typedef std::list<Rule> RuleList;
129 131
130 RuleList rules_; 132 RuleList rules_;
131 }; 133 };
132 134
133 // Using WaitingHostResolverProc you can simulate very long lookups. 135 // Using WaitingHostResolverProc you can simulate very long lookups.
134 class WaitingHostResolverProc : public HostResolverProc { 136 class WaitingHostResolverProc : public HostResolverProc {
135 public: 137 public:
136 explicit WaitingHostResolverProc(HostResolverProc* previous) 138 explicit WaitingHostResolverProc(HostResolverProc* previous)
137 : HostResolverProc(previous), event_(false, false) {} 139 : HostResolverProc(previous), event_(false, false) {}
138 140
139 void Signal() { 141 void Signal() {
140 event_.Signal(); 142 event_.Signal();
141 } 143 }
142 144
143 // HostResolverProc methods: 145 // HostResolverProc methods:
144 virtual int Resolve(const std::string& host, AddressList* addrlist) { 146 virtual int Resolve(const std::string& host,
147 AddressFamily address_family,
148 AddressList* addrlist) {
145 event_.Wait(); 149 event_.Wait();
146 return ResolveUsingPrevious(host, addrlist); 150 return ResolveUsingPrevious(host, address_family, addrlist);
147 } 151 }
148 152
149 base::WaitableEvent event_; 153 base::WaitableEvent event_;
150 }; 154 };
151 155
152 // This class sets the HostResolverProc for a particular scope. If there are 156 // This class sets the HostResolverProc for a particular scope. If there are
153 // multiple ScopedDefaultHostResolverProc in existence, then the last one 157 // multiple ScopedDefaultHostResolverProc in existence, then the last one
154 // allocated will be used. However, if it does not provide a matching rule, 158 // allocated will be used. However, if it does not provide a matching rule,
155 // then it should delegate to the previously set HostResolverProc. 159 // then it should delegate to the previously set HostResolverProc.
156 // 160 //
157 // NOTE: Only use this as a catch-all safety net. Individual tests should use 161 // NOTE: Only use this as a catch-all safety net. Individual tests should use
158 // MockHostResolver. 162 // MockHostResolver.
159 class ScopedDefaultHostResolverProc { 163 class ScopedDefaultHostResolverProc {
160 public: 164 public:
161 ScopedDefaultHostResolverProc() {} 165 ScopedDefaultHostResolverProc() {}
162 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc); 166 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc);
163 167
164 ~ScopedDefaultHostResolverProc(); 168 ~ScopedDefaultHostResolverProc();
165 169
166 void Init(HostResolverProc* proc); 170 void Init(HostResolverProc* proc);
167 171
168 private: 172 private:
169 scoped_refptr<HostResolverProc> current_proc_; 173 scoped_refptr<HostResolverProc> current_proc_;
170 scoped_refptr<HostResolverProc> previous_proc_; 174 scoped_refptr<HostResolverProc> previous_proc_;
171 }; 175 };
172 176
173 } // namespace net 177 } // namespace net
174 178
175 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ 179 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698