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

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

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