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

Side by Side Diff: net/proxy/mock_proxy_resolver.h

Issue 1439053002: Change ProxyResolver::GetProxyForURL() to take a scoped_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_PROXY_MOCK_PROXY_RESOLVER_H_ 5 #ifndef NET_PROXY_MOCK_PROXY_RESOLVER_H_
6 #define NET_PROXY_MOCK_PROXY_RESOLVER_H_ 6 #define NET_PROXY_MOCK_PROXY_RESOLVER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/proxy/proxy_resolver.h" 12 #include "net/proxy/proxy_resolver.h"
13 #include "net/proxy/proxy_resolver_factory.h" 13 #include "net/proxy/proxy_resolver_factory.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 namespace base { 16 namespace base {
17 class MessageLoop; 17 class MessageLoop;
18 } 18 }
19 19
20 namespace net { 20 namespace net {
21 21
22 // Asynchronous mock proxy resolver. All requests complete asynchronously, 22 // Asynchronous mock proxy resolver. All requests complete asynchronously,
23 // user must call Request::CompleteNow() on a pending request to signal it. 23 // user must call Job::CompleteNow() on a pending request to signal it.
24 class MockAsyncProxyResolver : public ProxyResolver { 24 class MockAsyncProxyResolver : public ProxyResolver {
25 public: 25 public:
26 class Request : public base::RefCounted<Request> { 26 class Job : public base::RefCounted<Job> {
27 public: 27 public:
28 Request(MockAsyncProxyResolver* resolver, 28 Job(MockAsyncProxyResolver* resolver,
29 const GURL& url, 29 const GURL& url,
30 ProxyInfo* results, 30 ProxyInfo* results,
31 const CompletionCallback& callback); 31 const CompletionCallback& callback);
32 32
33 const GURL& url() const { return url_; } 33 const GURL& url() const { return url_; }
34 ProxyInfo* results() const { return results_; } 34 ProxyInfo* results() const { return results_; }
35 const CompletionCallback& callback() const { return callback_; } 35 const CompletionCallback& callback() const { return callback_; }
36 36
37 void CompleteNow(int rv); 37 void CompleteNow(int rv);
38 38
39 private: 39 private:
40 friend class base::RefCounted<Request>; 40 friend class base::RefCounted<Job>;
41 41
42 virtual ~Request(); 42 virtual ~Job();
43 43
44 MockAsyncProxyResolver* resolver_; 44 MockAsyncProxyResolver* resolver_;
45 const GURL url_; 45 const GURL url_;
46 ProxyInfo* results_; 46 ProxyInfo* results_;
47 CompletionCallback callback_; 47 CompletionCallback callback_;
48 base::MessageLoop* origin_loop_; 48 base::MessageLoop* origin_loop_;
49 }; 49 };
50 50
51 typedef std::vector<scoped_refptr<Request> > RequestsList; 51 class RequestImpl : public ProxyResolver::Request {
52 public:
53 RequestImpl(Job* job, MockAsyncProxyResolver* resolver);
54
55 ~RequestImpl() override;
56
57 LoadState GetLoadState() override;
58
59 private:
60 scoped_refptr<Job> job_;
61 MockAsyncProxyResolver* resolver_;
62 };
63
64 typedef std::vector<scoped_refptr<Job>> JobsList;
52 65
53 MockAsyncProxyResolver(); 66 MockAsyncProxyResolver();
54 ~MockAsyncProxyResolver() override; 67 ~MockAsyncProxyResolver() override;
55 68
56 // ProxyResolver implementation. 69 // ProxyResolver implementation.
57 int GetProxyForURL(const GURL& url, 70 int GetProxyForURL(const GURL& url,
58 ProxyInfo* results, 71 ProxyInfo* results,
59 const CompletionCallback& callback, 72 const CompletionCallback& callback,
60 RequestHandle* request_handle, 73 scoped_ptr<Request>* request,
61 const BoundNetLog& /*net_log*/) override; 74 const BoundNetLog& /*net_log*/) override;
62 void CancelRequest(RequestHandle request_handle) override; 75 const JobsList& pending_jobs() const { return pending_jobs_; }
63 LoadState GetLoadState(RequestHandle request_handle) const override;
64 const RequestsList& pending_requests() const {
65 return pending_requests_;
66 }
67 76
68 const RequestsList& cancelled_requests() const { 77 const JobsList& cancelled_jobs() const { return cancelled_jobs_; }
69 return cancelled_requests_;
70 }
71 78
72 void RemovePendingRequest(Request* request); 79 void AddCancelledJob(scoped_refptr<Job> job);
80 void RemovePendingJob(Job* job);
73 81
74 private: 82 private:
75 RequestsList pending_requests_; 83 JobsList pending_jobs_;
76 RequestsList cancelled_requests_; 84 JobsList cancelled_jobs_;
77 }; 85 };
78 86
79 // Asynchronous mock proxy resolver factory . All requests complete 87 // Asynchronous mock proxy resolver factory . All requests complete
80 // asynchronously; the user must call Request::CompleteNow() on a pending 88 // asynchronously; the user must call Request::CompleteNow() on a pending
81 // request to signal it. 89 // request to signal it.
82 class MockAsyncProxyResolverFactory : public ProxyResolverFactory { 90 class MockAsyncProxyResolverFactory : public ProxyResolverFactory {
83 public: 91 public:
84 class Request; 92 class Request;
85 using RequestsList = std::vector<scoped_refptr<Request>>; 93 using RequestsList = std::vector<scoped_refptr<Request>>;
86 94
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain 151 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain
144 // so long as this remains in use. 152 // so long as this remains in use.
145 class ForwardingProxyResolver : public ProxyResolver { 153 class ForwardingProxyResolver : public ProxyResolver {
146 public: 154 public:
147 explicit ForwardingProxyResolver(ProxyResolver* impl); 155 explicit ForwardingProxyResolver(ProxyResolver* impl);
148 156
149 // ProxyResolver overrides. 157 // ProxyResolver overrides.
150 int GetProxyForURL(const GURL& query_url, 158 int GetProxyForURL(const GURL& query_url,
151 ProxyInfo* results, 159 ProxyInfo* results,
152 const CompletionCallback& callback, 160 const CompletionCallback& callback,
153 RequestHandle* request, 161 scoped_ptr<Request>* request,
154 const BoundNetLog& net_log) override; 162 const BoundNetLog& net_log) override;
155 void CancelRequest(RequestHandle request) override;
156 LoadState GetLoadState(RequestHandle request) const override;
157 163
158 private: 164 private:
159 ProxyResolver* impl_; 165 ProxyResolver* impl_;
160 166
161 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); 167 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver);
162 }; 168 };
163 169
164 } // namespace net 170 } // namespace net
165 171
166 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ 172 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698