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

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

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: Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/proxy_resolver_factory_mojo.h" 5 #include "net/proxy/proxy_resolver_factory_mojo.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 HostResolver* host_resolver, 109 HostResolver* host_resolver,
110 scoped_ptr<base::ScopedClosureRunner> on_delete_callback_runner, 110 scoped_ptr<base::ScopedClosureRunner> on_delete_callback_runner,
111 scoped_ptr<ProxyResolverErrorObserver> error_observer, 111 scoped_ptr<ProxyResolverErrorObserver> error_observer,
112 NetLog* net_log); 112 NetLog* net_log);
113 ~ProxyResolverMojo() override; 113 ~ProxyResolverMojo() override;
114 114
115 // ProxyResolver implementation: 115 // ProxyResolver implementation:
116 int GetProxyForURL(const GURL& url, 116 int GetProxyForURL(const GURL& url,
117 ProxyInfo* results, 117 ProxyInfo* results,
118 const net::CompletionCallback& callback, 118 const net::CompletionCallback& callback,
119 RequestHandle* request, 119 scoped_ptr<Request>* request,
120 const BoundNetLog& net_log) override; 120 const BoundNetLog& net_log) override;
121 void CancelRequest(RequestHandle request) override; 121 base::ThreadChecker thread_checker_; // TODO this should be private
eroman 2015/11/24 01:20:59 why not make it private here?
122 LoadState GetLoadState(RequestHandle request) const override;
123 122
124 private: 123 private:
125 class Job; 124 class Job;
125 class RequestImpl;
126 126
127 // Mojo error handler. 127 // Mojo error handler.
128 void OnConnectionError(); 128 void OnConnectionError();
129 129
130 void RemoveJob(Job* job); 130 void RemoveJob(Job* job);
131 131
132 // Connection to the Mojo proxy resolver. 132 // Connection to the Mojo proxy resolver.
133 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_; 133 interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_;
134 134
135 HostResolver* host_resolver_; 135 HostResolver* host_resolver_;
136 136
137 scoped_ptr<ProxyResolverErrorObserver> error_observer_; 137 scoped_ptr<ProxyResolverErrorObserver> error_observer_;
138 138
139 NetLog* net_log_; 139 NetLog* net_log_;
140 140
141 std::set<Job*> pending_jobs_; 141 std::set<Job*> pending_jobs_;
142 142
143 base::ThreadChecker thread_checker_;
144 143
145 scoped_ptr<base::ScopedClosureRunner> on_delete_callback_runner_; 144 scoped_ptr<base::ScopedClosureRunner> on_delete_callback_runner_;
146 145
147 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo); 146 DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo);
148 }; 147 };
149 148
149 class ProxyResolverMojo::RequestImpl : public ProxyResolver::Request {
150 public:
151 RequestImpl(Job* job, ProxyResolverMojo* resolver);
152
153 ~RequestImpl() override;
154
155 LoadState GetLoadState() override;
156
157 private:
158 Job* job_;
159 ProxyResolverMojo* resolver_;
160 };
161
150 class ProxyResolverMojo::Job 162 class ProxyResolverMojo::Job
151 : public ClientMixin<interfaces::ProxyResolverRequestClient> { 163 : public ClientMixin<interfaces::ProxyResolverRequestClient> {
152 public: 164 public:
153 Job(ProxyResolverMojo* resolver, 165 Job(ProxyResolverMojo* resolver,
154 const GURL& url, 166 const GURL& url,
155 ProxyInfo* results, 167 ProxyInfo* results,
156 const CompletionCallback& callback, 168 const CompletionCallback& callback,
157 const BoundNetLog& net_log); 169 const BoundNetLog& net_log);
158 ~Job() override; 170 ~Job() override;
159 171
(...skipping 14 matching lines...) Expand all
174 186
175 ProxyResolverMojo* resolver_; 187 ProxyResolverMojo* resolver_;
176 const GURL url_; 188 const GURL url_;
177 ProxyInfo* results_; 189 ProxyInfo* results_;
178 CompletionCallback callback_; 190 CompletionCallback callback_;
179 191
180 base::ThreadChecker thread_checker_; 192 base::ThreadChecker thread_checker_;
181 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; 193 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_;
182 }; 194 };
183 195
196 ProxyResolverMojo::RequestImpl::RequestImpl(Job* job,
197 ProxyResolverMojo* resolver)
198 : job_(job), resolver_(resolver) {}
199
200 ProxyResolverMojo::RequestImpl::~RequestImpl() {
201 DCHECK(resolver_->thread_checker_.CalledOnValidThread());
202 DCHECK(job_);
203 job_->Cancel();
eroman 2015/11/24 01:20:59 Same issue on ownership -- Can't job_ already be d
204 resolver_->RemoveJob(job_);
205 }
206
207 LoadState ProxyResolverMojo::RequestImpl::GetLoadState() {
208 CHECK_EQ(1u, resolver_->pending_jobs_.count(job_));
209 return job_->GetLoadState();
210 }
211
184 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver, 212 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
185 const GURL& url, 213 const GURL& url,
186 ProxyInfo* results, 214 ProxyInfo* results,
187 const CompletionCallback& callback, 215 const CompletionCallback& callback,
188 const BoundNetLog& net_log) 216 const BoundNetLog& net_log)
189 : ClientMixin<interfaces::ProxyResolverRequestClient>( 217 : ClientMixin<interfaces::ProxyResolverRequestClient>(
190 resolver->host_resolver_, 218 resolver->host_resolver_,
191 resolver->error_observer_.get(), 219 resolver->error_observer_.get(),
192 resolver->net_log_, 220 resolver->net_log_,
193 net_log), 221 net_log),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 void ProxyResolverMojo::RemoveJob(Job* job) { 305 void ProxyResolverMojo::RemoveJob(Job* job) {
278 DCHECK(thread_checker_.CalledOnValidThread()); 306 DCHECK(thread_checker_.CalledOnValidThread());
279 size_t num_erased = pending_jobs_.erase(job); 307 size_t num_erased = pending_jobs_.erase(job);
280 DCHECK(num_erased); 308 DCHECK(num_erased);
281 delete job; 309 delete job;
282 } 310 }
283 311
284 int ProxyResolverMojo::GetProxyForURL(const GURL& url, 312 int ProxyResolverMojo::GetProxyForURL(const GURL& url,
285 ProxyInfo* results, 313 ProxyInfo* results,
286 const CompletionCallback& callback, 314 const CompletionCallback& callback,
287 RequestHandle* request, 315 scoped_ptr<Request>* request,
288 const BoundNetLog& net_log) { 316 const BoundNetLog& net_log) {
289 DCHECK(thread_checker_.CalledOnValidThread()); 317 DCHECK(thread_checker_.CalledOnValidThread());
290 318
291 if (!mojo_proxy_resolver_ptr_) 319 if (!mojo_proxy_resolver_ptr_)
292 return ERR_PAC_SCRIPT_TERMINATED; 320 return ERR_PAC_SCRIPT_TERMINATED;
293 321
294 Job* job = new Job(this, url, results, callback, net_log); 322 Job* job = new Job(this, url, results, callback, net_log);
295 bool inserted = pending_jobs_.insert(job).second; 323 bool inserted = pending_jobs_.insert(job).second;
296 DCHECK(inserted); 324 DCHECK(inserted);
297 *request = job; 325 request->reset(new RequestImpl(job, this));
298 326
299 return ERR_IO_PENDING; 327 return ERR_IO_PENDING;
300 } 328 }
301 329
302 void ProxyResolverMojo::CancelRequest(RequestHandle request) {
303 DCHECK(thread_checker_.CalledOnValidThread());
304 Job* job = static_cast<Job*>(request);
305 DCHECK(job);
306 job->Cancel();
307 RemoveJob(job);
308 }
309 330
310 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const {
311 Job* job = static_cast<Job*>(request);
312 CHECK_EQ(1u, pending_jobs_.count(job));
313 return job->GetLoadState();
314 }
315 331
316 } // namespace 332 } // namespace
317 333
318 // A Job to create a ProxyResolver instance. 334 // A Job to create a ProxyResolver instance.
319 // 335 //
320 // Note: a Job instance is not tied to a particular resolve request, and hence 336 // Note: a Job instance is not tied to a particular resolve request, and hence
321 // there is no per-request logging to be done (any netlog events are only sent 337 // there is no per-request logging to be done (any netlog events are only sent
322 // globally) so this always uses an empty BoundNetLog. 338 // globally) so this always uses an empty BoundNetLog.
323 class ProxyResolverFactoryMojo::Job 339 class ProxyResolverFactoryMojo::Job
324 : public ClientMixin<interfaces::ProxyResolverFactoryRequestClient>, 340 : public ClientMixin<interfaces::ProxyResolverFactoryRequestClient>,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 return ERR_PAC_SCRIPT_FAILED; 420 return ERR_PAC_SCRIPT_FAILED;
405 } 421 }
406 request->reset(new Job(this, pac_script, resolver, callback, 422 request->reset(new Job(this, pac_script, resolver, callback,
407 error_observer_factory_.is_null() 423 error_observer_factory_.is_null()
408 ? nullptr 424 ? nullptr
409 : error_observer_factory_.Run())); 425 : error_observer_factory_.Run()));
410 return ERR_IO_PENDING; 426 return ERR_IO_PENDING;
411 } 427 }
412 428
413 } // namespace net 429 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698