OLD | NEW |
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 #include "net/proxy/multi_threaded_proxy_resolver.h" | 5 #include "net/proxy/multi_threaded_proxy_resolver.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 const scoped_refptr<ProxyResolverScriptData>& script_data, | 112 const scoped_refptr<ProxyResolverScriptData>& script_data, |
113 scoped_refptr<Executor> executor); | 113 scoped_refptr<Executor> executor); |
114 | 114 |
115 ~MultiThreadedProxyResolver() override; | 115 ~MultiThreadedProxyResolver() override; |
116 | 116 |
117 // ProxyResolver implementation: | 117 // ProxyResolver implementation: |
118 int GetProxyForURL(const GURL& url, | 118 int GetProxyForURL(const GURL& url, |
119 ProxyInfo* results, | 119 ProxyInfo* results, |
120 const CompletionCallback& callback, | 120 const CompletionCallback& callback, |
121 RequestHandle* request, | 121 RequestHandle* request, |
122 const BoundNetLog& net_log) override; | 122 const NetLogWithSource& net_log) override; |
123 void CancelRequest(RequestHandle request) override; | 123 void CancelRequest(RequestHandle request) override; |
124 LoadState GetLoadState(RequestHandle request) const override; | 124 LoadState GetLoadState(RequestHandle request) const override; |
125 | 125 |
126 private: | 126 private: |
127 class GetProxyForURLJob; | 127 class GetProxyForURLJob; |
128 // FIFO queue of pending jobs waiting to be started. | 128 // FIFO queue of pending jobs waiting to be started. |
129 // TODO(eroman): Make this priority queue. | 129 // TODO(eroman): Make this priority queue. |
130 typedef std::deque<scoped_refptr<Job>> PendingJobsQueue; | 130 typedef std::deque<scoped_refptr<Job>> PendingJobsQueue; |
131 typedef std::vector<scoped_refptr<Executor>> ExecutorList; | 131 typedef std::vector<scoped_refptr<Executor>> ExecutorList; |
132 | 132 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 275 |
276 // MultiThreadedProxyResolver::GetProxyForURLJob ------------------------------ | 276 // MultiThreadedProxyResolver::GetProxyForURLJob ------------------------------ |
277 | 277 |
278 class MultiThreadedProxyResolver::GetProxyForURLJob : public Job { | 278 class MultiThreadedProxyResolver::GetProxyForURLJob : public Job { |
279 public: | 279 public: |
280 // |url| -- the URL of the query. | 280 // |url| -- the URL of the query. |
281 // |results| -- the structure to fill with proxy resolve results. | 281 // |results| -- the structure to fill with proxy resolve results. |
282 GetProxyForURLJob(const GURL& url, | 282 GetProxyForURLJob(const GURL& url, |
283 ProxyInfo* results, | 283 ProxyInfo* results, |
284 const CompletionCallback& callback, | 284 const CompletionCallback& callback, |
285 const BoundNetLog& net_log) | 285 const NetLogWithSource& net_log) |
286 : Job(TYPE_GET_PROXY_FOR_URL, callback), | 286 : Job(TYPE_GET_PROXY_FOR_URL, callback), |
287 results_(results), | 287 results_(results), |
288 net_log_(net_log), | 288 net_log_(net_log), |
289 url_(url), | 289 url_(url), |
290 was_waiting_for_thread_(false) { | 290 was_waiting_for_thread_(false) { |
291 DCHECK(!callback.is_null()); | 291 DCHECK(!callback.is_null()); |
292 } | 292 } |
293 | 293 |
294 BoundNetLog* net_log() { return &net_log_; } | 294 NetLogWithSource* net_log() { return &net_log_; } |
295 | 295 |
296 void WaitingForThread() override { | 296 void WaitingForThread() override { |
297 was_waiting_for_thread_ = true; | 297 was_waiting_for_thread_ = true; |
298 net_log_.BeginEvent(NetLogEventType::WAITING_FOR_PROXY_RESOLVER_THREAD); | 298 net_log_.BeginEvent(NetLogEventType::WAITING_FOR_PROXY_RESOLVER_THREAD); |
299 } | 299 } |
300 | 300 |
301 void FinishedWaitingForThread() override { | 301 void FinishedWaitingForThread() override { |
302 DCHECK(executor()); | 302 DCHECK(executor()); |
303 | 303 |
304 if (was_waiting_for_thread_) { | 304 if (was_waiting_for_thread_) { |
(...skipping 30 matching lines...) Expand all Loading... |
335 } | 335 } |
336 RunUserCallback(result_code); | 336 RunUserCallback(result_code); |
337 } | 337 } |
338 OnJobCompleted(); | 338 OnJobCompleted(); |
339 } | 339 } |
340 | 340 |
341 // Must only be used on the "origin" thread. | 341 // Must only be used on the "origin" thread. |
342 ProxyInfo* results_; | 342 ProxyInfo* results_; |
343 | 343 |
344 // Can be used on either "origin" or worker thread. | 344 // Can be used on either "origin" or worker thread. |
345 BoundNetLog net_log_; | 345 NetLogWithSource net_log_; |
346 const GURL url_; | 346 const GURL url_; |
347 | 347 |
348 // Usable from within DoQuery on the worker thread. | 348 // Usable from within DoQuery on the worker thread. |
349 ProxyInfo results_buf_; | 349 ProxyInfo results_buf_; |
350 | 350 |
351 bool was_waiting_for_thread_; | 351 bool was_waiting_for_thread_; |
352 }; | 352 }; |
353 | 353 |
354 // Executor ---------------------------------------- | 354 // Executor ---------------------------------------- |
355 | 355 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 DCHECK(CalledOnValidThread()); | 436 DCHECK(CalledOnValidThread()); |
437 // We will cancel all outstanding requests. | 437 // We will cancel all outstanding requests. |
438 pending_jobs_.clear(); | 438 pending_jobs_.clear(); |
439 | 439 |
440 for (auto& executor : executors_) { | 440 for (auto& executor : executors_) { |
441 executor->Destroy(); | 441 executor->Destroy(); |
442 } | 442 } |
443 } | 443 } |
444 | 444 |
445 int MultiThreadedProxyResolver::GetProxyForURL( | 445 int MultiThreadedProxyResolver::GetProxyForURL( |
446 const GURL& url, ProxyInfo* results, const CompletionCallback& callback, | 446 const GURL& url, |
447 RequestHandle* request, const BoundNetLog& net_log) { | 447 ProxyInfo* results, |
| 448 const CompletionCallback& callback, |
| 449 RequestHandle* request, |
| 450 const NetLogWithSource& net_log) { |
448 DCHECK(CalledOnValidThread()); | 451 DCHECK(CalledOnValidThread()); |
449 DCHECK(!callback.is_null()); | 452 DCHECK(!callback.is_null()); |
450 | 453 |
451 scoped_refptr<GetProxyForURLJob> job( | 454 scoped_refptr<GetProxyForURLJob> job( |
452 new GetProxyForURLJob(url, results, callback, net_log)); | 455 new GetProxyForURLJob(url, results, callback, net_log)); |
453 | 456 |
454 // Completion will be notified through |callback|, unless the caller cancels | 457 // Completion will be notified through |callback|, unless the caller cancels |
455 // the request using |request|. | 458 // the request using |request|. |
456 if (request) | 459 if (request) |
457 *request = reinterpret_cast<RequestHandle>(job.get()); | 460 *request = reinterpret_cast<RequestHandle>(job.get()); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 return ERR_IO_PENDING; | 628 return ERR_IO_PENDING; |
626 } | 629 } |
627 | 630 |
628 void MultiThreadedProxyResolverFactory::RemoveJob( | 631 void MultiThreadedProxyResolverFactory::RemoveJob( |
629 MultiThreadedProxyResolverFactory::Job* job) { | 632 MultiThreadedProxyResolverFactory::Job* job) { |
630 size_t erased = jobs_.erase(job); | 633 size_t erased = jobs_.erase(job); |
631 DCHECK_EQ(1u, erased); | 634 DCHECK_EQ(1u, erased); |
632 } | 635 } |
633 | 636 |
634 } // namespace net | 637 } // namespace net |
OLD | NEW |