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

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

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // that are pending. 75 // that are pending.
76 void set_ondemand_mode(bool is_ondemand) { 76 void set_ondemand_mode(bool is_ondemand) {
77 ondemand_mode_ = is_ondemand; 77 ondemand_mode_ = is_ondemand;
78 } 78 }
79 79
80 // HostResolver methods: 80 // HostResolver methods:
81 int Resolve(const RequestInfo& info, 81 int Resolve(const RequestInfo& info,
82 RequestPriority priority, 82 RequestPriority priority,
83 AddressList* addresses, 83 AddressList* addresses,
84 const CompletionCallback& callback, 84 const CompletionCallback& callback,
85 RequestHandle* out_req, 85 std::unique_ptr<Request>* out_req,
86 const BoundNetLog& net_log) override; 86 const BoundNetLog& net_log) override;
87 int ResolveFromCache(const RequestInfo& info, 87 int ResolveFromCache(const RequestInfo& info,
88 AddressList* addresses, 88 AddressList* addresses,
89 const BoundNetLog& net_log) override; 89 const BoundNetLog& net_log) override;
90 void CancelRequest(RequestHandle req) override;
91 HostCache* GetHostCache() override; 90 HostCache* GetHostCache() override;
92 91
93 // Resolves all pending requests. It is only valid to invoke this if 92 // Resolves all pending requests. It is only valid to invoke this if
94 // set_ondemand_mode was set before. The requests are resolved asynchronously, 93 // set_ondemand_mode was set before. The requests are resolved asynchronously,
95 // after this call returns. 94 // after this call returns.
96 void ResolveAllPending(); 95 void ResolveAllPending();
97 96
98 // Returns true if there are pending requests that can be resolved by invoking 97 // Returns true if there are pending requests that can be resolved by invoking
99 // ResolveAllPending(). 98 // ResolveAllPending().
100 bool has_pending_requests() const { return !requests_.empty(); } 99 bool has_pending_requests() const { return !requests_.empty(); }
101 100
102 // The number of times that Resolve() has been called. 101 // The number of times that Resolve() has been called.
103 size_t num_resolve() const { 102 size_t num_resolve() const {
104 return num_resolve_; 103 return num_resolve_;
105 } 104 }
106 105
107 // The number of times that ResolveFromCache() has been called. 106 // The number of times that ResolveFromCache() has been called.
108 size_t num_resolve_from_cache() const { 107 size_t num_resolve_from_cache() const {
109 return num_resolve_from_cache_; 108 return num_resolve_from_cache_;
110 } 109 }
111 110
112 // Returns the RequestPriority of the last call to Resolve() (or 111 // Returns the RequestPriority of the last call to Resolve() (or
113 // DEFAULT_PRIORITY if Resolve() hasn't been called yet). 112 // DEFAULT_PRIORITY if Resolve() hasn't been called yet).
114 RequestPriority last_request_priority() const { 113 RequestPriority last_request_priority() const {
115 return last_request_priority_; 114 return last_request_priority_;
116 } 115 }
117 116
117 // Removes a request from |RequestMap|
118 void RemoveRequest(size_t id);
119
118 protected: 120 protected:
119 explicit MockHostResolverBase(bool use_caching); 121 explicit MockHostResolverBase(bool use_caching);
120 122
121 private: 123 private:
122 struct Request; 124 class RequestImpl;
123 typedef std::map<size_t, Request*> RequestMap; 125 typedef std::map<size_t, RequestImpl*> RequestMap;
124 126
125 // Resolve as IP or from |cache_| return cached error or 127 // Resolve as IP or from |cache_| return cached error or
126 // DNS_CACHE_MISS if failed. 128 // DNS_CACHE_MISS if failed.
127 int ResolveFromIPLiteralOrCache(const RequestInfo& info, 129 int ResolveFromIPLiteralOrCache(const RequestInfo& info,
128 AddressList* addresses); 130 AddressList* addresses);
129 // Resolve via |proc_|. 131 // Resolve via |proc_|.
130 int ResolveProc(size_t id, const RequestInfo& info, AddressList* addresses); 132 int ResolveProc(size_t id, const RequestInfo& info, AddressList* addresses);
131 // Resolve request stored in |requests_|. Pass rv to callback. 133 // Resolve request stored in |requests_|. Pass rv to callback.
132 void ResolveNow(size_t id); 134 void ResolveNow(size_t id);
133 135
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // Create rules that map all requests to localhost. 234 // Create rules that map all requests to localhost.
233 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc(); 235 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc();
234 236
235 // HangingHostResolver never completes its |Resolve| request. 237 // HangingHostResolver never completes its |Resolve| request.
236 class HangingHostResolver : public HostResolver { 238 class HangingHostResolver : public HostResolver {
237 public: 239 public:
238 int Resolve(const RequestInfo& info, 240 int Resolve(const RequestInfo& info,
239 RequestPriority priority, 241 RequestPriority priority,
240 AddressList* addresses, 242 AddressList* addresses,
241 const CompletionCallback& callback, 243 const CompletionCallback& callback,
242 RequestHandle* out_req, 244 std::unique_ptr<Request>* out_req,
243 const BoundNetLog& net_log) override; 245 const BoundNetLog& net_log) override;
244 int ResolveFromCache(const RequestInfo& info, 246 int ResolveFromCache(const RequestInfo& info,
245 AddressList* addresses, 247 AddressList* addresses,
246 const BoundNetLog& net_log) override; 248 const BoundNetLog& net_log) override;
247 void CancelRequest(RequestHandle req) override {}
248 }; 249 };
249 250
250 // This class sets the default HostResolverProc for a particular scope. The 251 // This class sets the default HostResolverProc for a particular scope. The
251 // chain of resolver procs starting at |proc| is placed in front of any existing 252 // chain of resolver procs starting at |proc| is placed in front of any existing
252 // default resolver proc(s). This means that if multiple 253 // default resolver proc(s). This means that if multiple
253 // ScopedDefaultHostResolverProcs are declared, then resolving will start with 254 // ScopedDefaultHostResolverProcs are declared, then resolving will start with
254 // the procs given to the last-allocated one, then fall back to the procs given 255 // the procs given to the last-allocated one, then fall back to the procs given
255 // to the previously-allocated one, and so forth. 256 // to the previously-allocated one, and so forth.
256 // 257 //
257 // NOTE: Only use this as a catch-all safety net. Individual tests should use 258 // NOTE: Only use this as a catch-all safety net. Individual tests should use
258 // MockHostResolver. 259 // MockHostResolver.
259 class ScopedDefaultHostResolverProc { 260 class ScopedDefaultHostResolverProc {
260 public: 261 public:
261 ScopedDefaultHostResolverProc(); 262 ScopedDefaultHostResolverProc();
262 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc); 263 explicit ScopedDefaultHostResolverProc(HostResolverProc* proc);
263 264
264 ~ScopedDefaultHostResolverProc(); 265 ~ScopedDefaultHostResolverProc();
265 266
266 void Init(HostResolverProc* proc); 267 void Init(HostResolverProc* proc);
267 268
268 private: 269 private:
269 scoped_refptr<HostResolverProc> current_proc_; 270 scoped_refptr<HostResolverProc> current_proc_;
270 scoped_refptr<HostResolverProc> previous_proc_; 271 scoped_refptr<HostResolverProc> previous_proc_;
271 }; 272 };
272 273
273 } // namespace net 274 } // namespace net
274 275
275 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_ 276 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698