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

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

Powered by Google App Engine
This is Rietveld 408576698