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

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 refptr due windows error Created 4 years, 10 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> {
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_; };
eroman 2016/02/24 03:08:06 can call this 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 virtual ~Job();
42 43 friend class base::RefCounted<Job>;
43 virtual ~Request();
44 44
45 MockAsyncProxyResolver* resolver_; 45 MockAsyncProxyResolver* resolver_;
46 const GURL url_; 46 const GURL url_;
47 ProxyInfo* results_; 47 ProxyInfo* results_;
48 CompletionCallback callback_; 48 CompletionCallback callback_;
49 base::MessageLoop* origin_loop_; 49 base::MessageLoop* origin_loop_;
50 }; 50 };
51 51
52 typedef std::vector<scoped_refptr<Request> > RequestsList; 52 class RequestImpl : public ProxyResolver::Request {
53 public:
54 RequestImpl(scoped_refptr<Job> job);
eroman 2016/02/24 03:08:06 mark as "explicit"
eroman 2016/02/24 19:20:29 This comment was not addressed.
55
56 ~RequestImpl() override;
57
58 LoadState GetLoadState() override;
59
60 private:
61 // TODO This should be scoped_ptr but windows compiler have some bug.
eroman 2016/02/24 03:08:06 What is the bug that happens?
eroman 2016/02/24 19:20:29 What is the response to this comment?
62 // probably this: https://support.microsoft.com/en-us/kb/121216
63 scoped_refptr<Job> job_;
64 };
53 65
54 MockAsyncProxyResolver(); 66 MockAsyncProxyResolver();
55 ~MockAsyncProxyResolver() override; 67 ~MockAsyncProxyResolver() override;
56 68
57 // ProxyResolver implementation. 69 // ProxyResolver implementation.
58 int GetProxyForURL(const GURL& url, 70 int GetProxyForURL(const GURL& url,
59 ProxyInfo* results, 71 ProxyInfo* results,
60 const CompletionCallback& callback, 72 const CompletionCallback& callback,
61 RequestHandle* request_handle, 73 scoped_ptr<Request>* request,
62 const BoundNetLog& /*net_log*/) override; 74 const BoundNetLog& /*net_log*/) override;
63 void CancelRequest(RequestHandle request_handle) override; 75 const std::vector<Job*>& pending_jobs() const { return pending_jobs_; }
64 LoadState GetLoadState(RequestHandle request_handle) const override; 76
65 const RequestsList& pending_requests() const { 77 const std::vector<scoped_refptr<Job>>& cancelled_jobs() const {
66 return pending_requests_; 78 return cancelled_jobs_;
67 } 79 }
68 80
69 const RequestsList& cancelled_requests() const { 81 void AddCancelledJob(scoped_refptr<Job> job);
70 return cancelled_requests_; 82 void RemovePendingJob(Job* job);
71 }
72
73 void RemovePendingRequest(Request* request);
74 83
75 private: 84 private:
76 RequestsList pending_requests_; 85 std::vector<Job*> pending_jobs_;
77 RequestsList cancelled_requests_; 86 std::vector<scoped_refptr<Job>> cancelled_jobs_;
78 }; 87 };
79 88
80 // Asynchronous mock proxy resolver factory . All requests complete 89 // Asynchronous mock proxy resolver factory . All requests complete
81 // asynchronously; the user must call Request::CompleteNow() on a pending 90 // asynchronously; the user must call Request::CompleteNow() on a pending
82 // request to signal it. 91 // request to signal it.
83 class MockAsyncProxyResolverFactory : public ProxyResolverFactory { 92 class MockAsyncProxyResolverFactory : public ProxyResolverFactory {
84 public: 93 public:
85 class Request; 94 class Request;
86 using RequestsList = std::vector<scoped_refptr<Request>>; 95 using RequestsList = std::vector<scoped_refptr<Request>>;
87 96
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain 153 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain
145 // so long as this remains in use. 154 // so long as this remains in use.
146 class ForwardingProxyResolver : public ProxyResolver { 155 class ForwardingProxyResolver : public ProxyResolver {
147 public: 156 public:
148 explicit ForwardingProxyResolver(ProxyResolver* impl); 157 explicit ForwardingProxyResolver(ProxyResolver* impl);
149 158
150 // ProxyResolver overrides. 159 // ProxyResolver overrides.
151 int GetProxyForURL(const GURL& query_url, 160 int GetProxyForURL(const GURL& query_url,
152 ProxyInfo* results, 161 ProxyInfo* results,
153 const CompletionCallback& callback, 162 const CompletionCallback& callback,
154 RequestHandle* request, 163 scoped_ptr<Request>* request,
155 const BoundNetLog& net_log) override; 164 const BoundNetLog& net_log) override;
156 void CancelRequest(RequestHandle request) override;
157 LoadState GetLoadState(RequestHandle request) const override;
158 165
159 private: 166 private:
160 ProxyResolver* impl_; 167 ProxyResolver* impl_;
161 168
162 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); 169 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver);
163 }; 170 };
164 171
165 } // namespace net 172 } // namespace net
166 173
167 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ 174 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698