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

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: Restore scoped_ptr to mock and nits Created 4 years, 9 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
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/proxy/mock_proxy_resolver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
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
41 ~Job();
42
40 private: 43 private:
41 friend class base::RefCounted<Request>;
42
43 virtual ~Request();
44
45 MockAsyncProxyResolver* resolver_; 44 MockAsyncProxyResolver* resolver_;
46 const GURL url_; 45 const GURL url_;
47 ProxyInfo* results_; 46 ProxyInfo* results_;
48 CompletionCallback callback_; 47 CompletionCallback callback_;
49 base::MessageLoop* origin_loop_; 48 base::MessageLoop* origin_loop_;
50 }; 49 };
51 50
52 typedef std::vector<scoped_refptr<Request> > RequestsList; 51 class RequestImpl : public ProxyResolver::Request {
52 public:
53 explicit RequestImpl(scoped_ptr<Job> job);
54
55 ~RequestImpl() override;
56
57 LoadState GetLoadState() override;
58
59 private:
60 scoped_ptr<Job> job_;
61 };
53 62
54 MockAsyncProxyResolver(); 63 MockAsyncProxyResolver();
55 ~MockAsyncProxyResolver() override; 64 ~MockAsyncProxyResolver() override;
56 65
57 // ProxyResolver implementation. 66 // ProxyResolver implementation.
58 int GetProxyForURL(const GURL& url, 67 int GetProxyForURL(const GURL& url,
59 ProxyInfo* results, 68 ProxyInfo* results,
60 const CompletionCallback& callback, 69 const CompletionCallback& callback,
61 RequestHandle* request_handle, 70 scoped_ptr<Request>* request,
62 const BoundNetLog& /*net_log*/) override; 71 const BoundNetLog& /*net_log*/) override;
63 void CancelRequest(RequestHandle request_handle) override; 72 const std::vector<Job*>& pending_jobs() const { return pending_jobs_; }
64 LoadState GetLoadState(RequestHandle request_handle) const override; 73
65 const RequestsList& pending_requests() const { 74 const std::vector<scoped_ptr<Job>>& cancelled_jobs() const {
66 return pending_requests_; 75 return cancelled_jobs_;
67 } 76 }
68 77
69 const RequestsList& cancelled_requests() const { 78 void AddCancelledJob(scoped_ptr<Job> job);
70 return cancelled_requests_; 79 void RemovePendingJob(Job* job);
71 }
72
73 void RemovePendingRequest(Request* request);
74 80
75 private: 81 private:
76 RequestsList pending_requests_; 82 std::vector<Job*> pending_jobs_;
77 RequestsList cancelled_requests_; 83 std::vector<scoped_ptr<Job>> cancelled_jobs_;
78 }; 84 };
79 85
80 // Asynchronous mock proxy resolver factory . All requests complete 86 // Asynchronous mock proxy resolver factory . All requests complete
81 // asynchronously; the user must call Request::CompleteNow() on a pending 87 // asynchronously; the user must call Request::CompleteNow() on a pending
82 // request to signal it. 88 // request to signal it.
83 class MockAsyncProxyResolverFactory : public ProxyResolverFactory { 89 class MockAsyncProxyResolverFactory : public ProxyResolverFactory {
84 public: 90 public:
85 class Request; 91 class Request;
86 using RequestsList = std::vector<scoped_refptr<Request>>; 92 using RequestsList = std::vector<scoped_refptr<Request>>;
87 93
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain 150 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain
145 // so long as this remains in use. 151 // so long as this remains in use.
146 class ForwardingProxyResolver : public ProxyResolver { 152 class ForwardingProxyResolver : public ProxyResolver {
147 public: 153 public:
148 explicit ForwardingProxyResolver(ProxyResolver* impl); 154 explicit ForwardingProxyResolver(ProxyResolver* impl);
149 155
150 // ProxyResolver overrides. 156 // ProxyResolver overrides.
151 int GetProxyForURL(const GURL& query_url, 157 int GetProxyForURL(const GURL& query_url,
152 ProxyInfo* results, 158 ProxyInfo* results,
153 const CompletionCallback& callback, 159 const CompletionCallback& callback,
154 RequestHandle* request, 160 scoped_ptr<Request>* request,
155 const BoundNetLog& net_log) override; 161 const BoundNetLog& net_log) override;
156 void CancelRequest(RequestHandle request) override;
157 LoadState GetLoadState(RequestHandle request) const override;
158 162
159 private: 163 private:
160 ProxyResolver* impl_; 164 ProxyResolver* impl_;
161 165
162 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); 166 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver);
163 }; 167 };
164 168
165 } // namespace net 169 } // namespace net
166 170
167 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ 171 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/proxy/mock_proxy_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698