Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 105 |
| 106 void MockAsyncProxyResolverBase::RemovePendingSetPacScriptRequest( | 106 void MockAsyncProxyResolverBase::RemovePendingSetPacScriptRequest( |
| 107 SetPacScriptRequest* request) { | 107 SetPacScriptRequest* request) { |
| 108 DCHECK_EQ(request, pending_set_pac_script_request()); | 108 DCHECK_EQ(request, pending_set_pac_script_request()); |
| 109 pending_set_pac_script_request_.reset(); | 109 pending_set_pac_script_request_.reset(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 MockAsyncProxyResolverBase::MockAsyncProxyResolverBase(bool expects_pac_bytes) | 112 MockAsyncProxyResolverBase::MockAsyncProxyResolverBase(bool expects_pac_bytes) |
| 113 : ProxyResolver(expects_pac_bytes) {} | 113 : ProxyResolver(expects_pac_bytes) {} |
| 114 | 114 |
| 115 MockAsyncProxyResolverFactory::Request::Request( | |
| 116 MockAsyncProxyResolverFactory* factory, | |
| 117 const scoped_refptr<ProxyResolverScriptData>& script_data, | |
| 118 scoped_ptr<ProxyResolver>* resolver, | |
| 119 const CompletionCallback& callback) | |
| 120 : factory_(factory), | |
| 121 script_data_(script_data), | |
| 122 resolver_(resolver), | |
| 123 callback_(callback) { | |
| 124 } | |
| 125 | |
| 126 MockAsyncProxyResolverFactory::Request::~Request() { | |
| 127 } | |
| 128 | |
| 129 void MockAsyncProxyResolverFactory::Request::CompleteNow( | |
| 130 int rv, | |
| 131 scoped_ptr<ProxyResolver> resolver) { | |
| 132 CompletionCallback callback = callback_; | |
|
eroman
2015/04/22 16:30:38
How about instead:
scoped_refptr<Request> keep_al
Sam McNally
2015/04/23 03:04:43
Done.
| |
| 133 *resolver_ = resolver.Pass(); | |
| 134 | |
| 135 // Will delete |this|. | |
| 136 factory_->RemovePendingRequest(this); | |
| 137 | |
| 138 callback.Run(rv); | |
| 139 } | |
| 140 | |
| 141 void MockAsyncProxyResolverFactory::Request::CompleteNowWithForwarder( | |
| 142 int rv, | |
| 143 ProxyResolver* resolver) { | |
| 144 DCHECK(resolver); | |
| 145 CompleteNow(rv, make_scoped_ptr(new ForwardingProxyResolver(resolver))); | |
| 146 } | |
| 147 | |
| 148 class MockAsyncProxyResolverFactory::Job | |
| 149 : public ProxyResolverFactory::Request { | |
| 150 public: | |
| 151 Job(MockAsyncProxyResolverFactory* factory, | |
| 152 const scoped_refptr<MockAsyncProxyResolverFactory::Request>& request) | |
| 153 : factory_(factory), request_(request) {} | |
| 154 ~Job() override { | |
| 155 if (std::find(factory_->pending_requests_.begin(), | |
|
eroman
2015/04/22 16:30:38
The assumption here is that the ProxyResolverFacto
Sam McNally
2015/04/23 03:04:43
Done.
| |
| 156 factory_->pending_requests_.end(), | |
| 157 request_.get()) == factory_->pending_requests_.end()) { | |
| 158 return; | |
| 159 } | |
| 160 factory_->cancelled_requests_.push_back(request_); | |
| 161 factory_->RemovePendingRequest(request_.get()); | |
| 162 } | |
| 163 | |
| 164 private: | |
| 165 MockAsyncProxyResolverFactory* factory_; | |
| 166 scoped_refptr<MockAsyncProxyResolverFactory::Request> request_; | |
| 167 }; | |
| 168 | |
| 169 MockAsyncProxyResolverFactory::MockAsyncProxyResolverFactory( | |
| 170 bool resolvers_expect_pac_bytes) | |
| 171 : ProxyResolverFactory(resolvers_expect_pac_bytes) { | |
| 172 } | |
| 173 | |
| 174 int MockAsyncProxyResolverFactory::CreateProxyResolver( | |
| 175 const scoped_refptr<ProxyResolverScriptData>& pac_script, | |
| 176 scoped_ptr<ProxyResolver>* resolver, | |
| 177 const net::CompletionCallback& callback, | |
| 178 scoped_ptr<ProxyResolverFactory::Request>* request_handle) { | |
| 179 scoped_refptr<Request> request = | |
| 180 new Request(this, pac_script, resolver, callback); | |
| 181 pending_requests_.push_back(request); | |
| 182 | |
| 183 request_handle->reset(new Job(this, request)); | |
|
eroman
2015/04/22 16:30:38
see comment above. |this| is redundant with |reque
Sam McNally
2015/04/23 03:04:43
Done.
| |
| 184 | |
| 185 // Test code completes the request by calling request->CompleteNow(). | |
| 186 return ERR_IO_PENDING; | |
| 187 } | |
| 188 | |
| 189 void MockAsyncProxyResolverFactory::RemovePendingRequest(Request* request) { | |
| 190 RequestsList::iterator it = | |
| 191 std::find(pending_requests_.begin(), pending_requests_.end(), request); | |
| 192 DCHECK(it != pending_requests_.end()); | |
| 193 pending_requests_.erase(it); | |
| 194 } | |
| 195 | |
| 196 MockAsyncProxyResolverFactory::~MockAsyncProxyResolverFactory() { | |
|
eroman
2015/04/22 16:30:38
See earlier comment about cancelling outstanding r
Sam McNally
2015/04/23 03:04:43
Done.
| |
| 197 } | |
| 198 | |
| 115 ForwardingProxyResolver::ForwardingProxyResolver(ProxyResolver* impl) | 199 ForwardingProxyResolver::ForwardingProxyResolver(ProxyResolver* impl) |
| 116 : ProxyResolver(impl->expects_pac_bytes()), impl_(impl) { | 200 : ProxyResolver(impl->expects_pac_bytes()), impl_(impl) { |
| 117 } | 201 } |
| 118 | 202 |
| 119 int ForwardingProxyResolver::GetProxyForURL(const GURL& query_url, | 203 int ForwardingProxyResolver::GetProxyForURL(const GURL& query_url, |
| 120 ProxyInfo* results, | 204 ProxyInfo* results, |
| 121 const CompletionCallback& callback, | 205 const CompletionCallback& callback, |
| 122 RequestHandle* request, | 206 RequestHandle* request, |
| 123 const BoundNetLog& net_log) { | 207 const BoundNetLog& net_log) { |
| 124 return impl_->GetProxyForURL(query_url, results, callback, request, net_log); | 208 return impl_->GetProxyForURL(query_url, results, callback, request, net_log); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 136 impl_->CancelSetPacScript(); | 220 impl_->CancelSetPacScript(); |
| 137 } | 221 } |
| 138 | 222 |
| 139 int ForwardingProxyResolver::SetPacScript( | 223 int ForwardingProxyResolver::SetPacScript( |
| 140 const scoped_refptr<ProxyResolverScriptData>& script_data, | 224 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 141 const CompletionCallback& callback) { | 225 const CompletionCallback& callback) { |
| 142 return impl_->SetPacScript(script_data, callback); | 226 return impl_->SetPacScript(script_data, callback); |
| 143 } | 227 } |
| 144 | 228 |
| 145 ForwardingProxyResolverFactory::ForwardingProxyResolverFactory( | 229 ForwardingProxyResolverFactory::ForwardingProxyResolverFactory( |
| 146 ProxyResolver* resolver) | 230 ProxyResolverFactory* impl) |
| 147 : LegacyProxyResolverFactory(resolver->expects_pac_bytes()), | 231 : ProxyResolverFactory(impl->expects_pac_bytes()), impl_(impl) { |
| 148 resolver_(resolver) { | |
| 149 } | 232 } |
| 150 | 233 |
| 151 scoped_ptr<ProxyResolver> | 234 int ForwardingProxyResolverFactory::CreateProxyResolver( |
| 152 ForwardingProxyResolverFactory::CreateProxyResolver() { | 235 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 153 return make_scoped_ptr(new ForwardingProxyResolver(resolver_)); | 236 scoped_ptr<ProxyResolver>* resolver, |
| 237 const net::CompletionCallback& callback, | |
| 238 scoped_ptr<Request>* request) { | |
| 239 return impl_->CreateProxyResolver(pac_script, resolver, callback, request); | |
| 154 } | 240 } |
| 155 | 241 |
| 156 } // namespace net | 242 } // namespace net |
| OLD | NEW |