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

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

Issue 1157163003: Remove ProxyResolver::(Cancel)SetPacScript and LegacyProxyResolverFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8-proxy-resolver-refactor
Patch Set: Created 5 years, 7 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/proxy/mock_proxy_resolver.h ('k') | net/proxy/mojo_proxy_resolver_factory_impl_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "net/proxy/mock_proxy_resolver.h" 5 #include "net/proxy/mock_proxy_resolver.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 MockAsyncProxyResolverBase::Request::Request( 12 MockAsyncProxyResolver::Request::Request(MockAsyncProxyResolver* resolver,
13 MockAsyncProxyResolverBase* resolver, 13 const GURL& url,
14 const GURL& url, 14 ProxyInfo* results,
15 ProxyInfo* results, 15 const CompletionCallback& callback)
16 const CompletionCallback& callback)
17 : resolver_(resolver), 16 : resolver_(resolver),
18 url_(url), 17 url_(url),
19 results_(results), 18 results_(results),
20 callback_(callback), 19 callback_(callback),
21 origin_loop_(base::MessageLoop::current()) {} 20 origin_loop_(base::MessageLoop::current()) {
21 }
22 22
23 void MockAsyncProxyResolverBase::Request::CompleteNow(int rv) { 23 void MockAsyncProxyResolver::Request::CompleteNow(int rv) {
24 CompletionCallback callback = callback_; 24 CompletionCallback callback = callback_;
25 25
26 // May delete |this|. 26 // May delete |this|.
27 resolver_->RemovePendingRequest(this); 27 resolver_->RemovePendingRequest(this);
28 28
29 callback.Run(rv); 29 callback.Run(rv);
30 } 30 }
31 31
32 MockAsyncProxyResolverBase::Request::~Request() {} 32 MockAsyncProxyResolver::Request::~Request() {
33
34 MockAsyncProxyResolverBase::SetPacScriptRequest::SetPacScriptRequest(
35 MockAsyncProxyResolverBase* resolver,
36 const scoped_refptr<ProxyResolverScriptData>& script_data,
37 const CompletionCallback& callback)
38 : resolver_(resolver),
39 script_data_(script_data),
40 callback_(callback),
41 origin_loop_(base::MessageLoop::current()) {}
42
43 MockAsyncProxyResolverBase::SetPacScriptRequest::~SetPacScriptRequest() {}
44
45 void MockAsyncProxyResolverBase::SetPacScriptRequest::CompleteNow(int rv) {
46 CompletionCallback callback = callback_;
47
48 // Will delete |this|.
49 resolver_->RemovePendingSetPacScriptRequest(this);
50
51 callback.Run(rv);
52 } 33 }
53 34
54 MockAsyncProxyResolverBase::~MockAsyncProxyResolverBase() {} 35 MockAsyncProxyResolver::~MockAsyncProxyResolver() {
36 }
55 37
56 int MockAsyncProxyResolverBase::GetProxyForURL( 38 int MockAsyncProxyResolver::GetProxyForURL(
57 const GURL& url, ProxyInfo* results, const CompletionCallback& callback, 39 const GURL& url,
58 RequestHandle* request_handle, const BoundNetLog& /*net_log*/) { 40 ProxyInfo* results,
41 const CompletionCallback& callback,
42 RequestHandle* request_handle,
43 const BoundNetLog& /*net_log*/) {
59 scoped_refptr<Request> request = new Request(this, url, results, callback); 44 scoped_refptr<Request> request = new Request(this, url, results, callback);
60 pending_requests_.push_back(request); 45 pending_requests_.push_back(request);
61 46
62 if (request_handle) 47 if (request_handle)
63 *request_handle = reinterpret_cast<RequestHandle>(request.get()); 48 *request_handle = reinterpret_cast<RequestHandle>(request.get());
64 49
65 // Test code completes the request by calling request->CompleteNow(). 50 // Test code completes the request by calling request->CompleteNow().
66 return ERR_IO_PENDING; 51 return ERR_IO_PENDING;
67 } 52 }
68 53
69 void MockAsyncProxyResolverBase::CancelRequest(RequestHandle request_handle) { 54 void MockAsyncProxyResolver::CancelRequest(RequestHandle request_handle) {
70 scoped_refptr<Request> request = reinterpret_cast<Request*>(request_handle); 55 scoped_refptr<Request> request = reinterpret_cast<Request*>(request_handle);
71 cancelled_requests_.push_back(request); 56 cancelled_requests_.push_back(request);
72 RemovePendingRequest(request.get()); 57 RemovePendingRequest(request.get());
73 } 58 }
74 59
75 LoadState MockAsyncProxyResolverBase::GetLoadState( 60 LoadState MockAsyncProxyResolver::GetLoadState(
76 RequestHandle request_handle) const { 61 RequestHandle request_handle) const {
77 return LOAD_STATE_RESOLVING_PROXY_FOR_URL; 62 return LOAD_STATE_RESOLVING_PROXY_FOR_URL;
78 } 63 }
79 64
80 int MockAsyncProxyResolverBase::SetPacScript( 65 void MockAsyncProxyResolver::RemovePendingRequest(Request* request) {
81 const scoped_refptr<ProxyResolverScriptData>& script_data,
82 const CompletionCallback& callback) {
83 DCHECK(!pending_set_pac_script_request_.get());
84 pending_set_pac_script_request_.reset(
85 new SetPacScriptRequest(this, script_data, callback));
86 // Finished when user calls SetPacScriptRequest::CompleteNow().
87 return ERR_IO_PENDING;
88 }
89
90 void MockAsyncProxyResolverBase::CancelSetPacScript() {
91 // Do nothing (caller was responsible for completing the request).
92 }
93
94 MockAsyncProxyResolverBase::SetPacScriptRequest*
95 MockAsyncProxyResolverBase::pending_set_pac_script_request() const {
96 return pending_set_pac_script_request_.get();
97 }
98
99 void MockAsyncProxyResolverBase::RemovePendingRequest(Request* request) {
100 RequestsList::iterator it = std::find( 66 RequestsList::iterator it = std::find(
101 pending_requests_.begin(), pending_requests_.end(), request); 67 pending_requests_.begin(), pending_requests_.end(), request);
102 DCHECK(it != pending_requests_.end()); 68 DCHECK(it != pending_requests_.end());
103 pending_requests_.erase(it); 69 pending_requests_.erase(it);
104 } 70 }
105 71
106 void MockAsyncProxyResolverBase::RemovePendingSetPacScriptRequest( 72 MockAsyncProxyResolver::MockAsyncProxyResolver() {
107 SetPacScriptRequest* request) {
108 DCHECK_EQ(request, pending_set_pac_script_request());
109 pending_set_pac_script_request_.reset();
110 } 73 }
111 74
112 MockAsyncProxyResolverBase::MockAsyncProxyResolverBase(bool expects_pac_bytes)
113 : ProxyResolver(expects_pac_bytes) {}
114
115 MockAsyncProxyResolverFactory::Request::Request( 75 MockAsyncProxyResolverFactory::Request::Request(
116 MockAsyncProxyResolverFactory* factory, 76 MockAsyncProxyResolverFactory* factory,
117 const scoped_refptr<ProxyResolverScriptData>& script_data, 77 const scoped_refptr<ProxyResolverScriptData>& script_data,
118 scoped_ptr<ProxyResolver>* resolver, 78 scoped_ptr<ProxyResolver>* resolver,
119 const CompletionCallback& callback) 79 const CompletionCallback& callback)
120 : factory_(factory), 80 : factory_(factory),
121 script_data_(script_data), 81 script_data_(script_data),
122 resolver_(resolver), 82 resolver_(resolver),
123 callback_(callback) { 83 callback_(callback) {
124 } 84 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 pending_requests_.erase(it); 153 pending_requests_.erase(it);
194 } 154 }
195 155
196 MockAsyncProxyResolverFactory::~MockAsyncProxyResolverFactory() { 156 MockAsyncProxyResolverFactory::~MockAsyncProxyResolverFactory() {
197 for (auto& request : pending_requests_) { 157 for (auto& request : pending_requests_) {
198 request->FactoryDestroyed(); 158 request->FactoryDestroyed();
199 } 159 }
200 } 160 }
201 161
202 ForwardingProxyResolver::ForwardingProxyResolver(ProxyResolver* impl) 162 ForwardingProxyResolver::ForwardingProxyResolver(ProxyResolver* impl)
203 : ProxyResolver(impl->expects_pac_bytes()), impl_(impl) { 163 : impl_(impl) {
204 } 164 }
205 165
206 int ForwardingProxyResolver::GetProxyForURL(const GURL& query_url, 166 int ForwardingProxyResolver::GetProxyForURL(const GURL& query_url,
207 ProxyInfo* results, 167 ProxyInfo* results,
208 const CompletionCallback& callback, 168 const CompletionCallback& callback,
209 RequestHandle* request, 169 RequestHandle* request,
210 const BoundNetLog& net_log) { 170 const BoundNetLog& net_log) {
211 return impl_->GetProxyForURL(query_url, results, callback, request, net_log); 171 return impl_->GetProxyForURL(query_url, results, callback, request, net_log);
212 } 172 }
213 173
214 void ForwardingProxyResolver::CancelRequest(RequestHandle request) { 174 void ForwardingProxyResolver::CancelRequest(RequestHandle request) {
215 impl_->CancelRequest(request); 175 impl_->CancelRequest(request);
216 } 176 }
217 177
218 LoadState ForwardingProxyResolver::GetLoadState(RequestHandle request) const { 178 LoadState ForwardingProxyResolver::GetLoadState(RequestHandle request) const {
219 return impl_->GetLoadState(request); 179 return impl_->GetLoadState(request);
220 } 180 }
221 181
222 void ForwardingProxyResolver::CancelSetPacScript() {
223 impl_->CancelSetPacScript();
224 }
225
226 int ForwardingProxyResolver::SetPacScript(
227 const scoped_refptr<ProxyResolverScriptData>& script_data,
228 const CompletionCallback& callback) {
229 return impl_->SetPacScript(script_data, callback);
230 }
231
232 } // namespace net 182 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/mock_proxy_resolver.h ('k') | net/proxy/mojo_proxy_resolver_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698