| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 virtual void FinishedWaitingForThread() { | 240 virtual void FinishedWaitingForThread() { |
| 241 DCHECK(executor()); | 241 DCHECK(executor()); |
| 242 | 242 |
| 243 if (was_waiting_for_thread_) { | 243 if (was_waiting_for_thread_) { |
| 244 net_log_.EndEvent( | 244 net_log_.EndEvent( |
| 245 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD, NULL); | 245 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD, NULL); |
| 246 } | 246 } |
| 247 | 247 |
| 248 net_log_.AddEvent( | 248 net_log_.AddEvent( |
| 249 NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, | 249 NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, |
| 250 new NetLogIntegerParameter( | 250 make_scoped_refptr(new NetLogIntegerParameter( |
| 251 "thread_number", executor()->thread_number())); | 251 "thread_number", executor()->thread_number()))); |
| 252 } | 252 } |
| 253 | 253 |
| 254 // Runs on the worker thread. | 254 // Runs on the worker thread. |
| 255 virtual void Run(MessageLoop* origin_loop) { | 255 virtual void Run(MessageLoop* origin_loop) { |
| 256 const size_t kNetLogBound = 50u; | 256 const size_t kNetLogBound = 50u; |
| 257 worker_log_.reset(new CapturingNetLog(kNetLogBound)); | 257 worker_log_.reset(new CapturingNetLog(kNetLogBound)); |
| 258 BoundNetLog bound_worker_log(NetLog::Source(), worker_log_.get()); | 258 BoundNetLog bound_worker_log(NetLog::Source(), worker_log_.get()); |
| 259 | 259 |
| 260 ProxyResolver* resolver = executor()->resolver(); | 260 ProxyResolver* resolver = executor()->resolver(); |
| 261 int rv = resolver->GetProxyForURL( | 261 int rv = resolver->GetProxyForURL( |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 550 |
| 551 MultiThreadedProxyResolver::Executor* | 551 MultiThreadedProxyResolver::Executor* |
| 552 MultiThreadedProxyResolver::AddNewExecutor() { | 552 MultiThreadedProxyResolver::AddNewExecutor() { |
| 553 DCHECK(CalledOnValidThread()); | 553 DCHECK(CalledOnValidThread()); |
| 554 DCHECK_LT(executors_.size(), max_num_threads_); | 554 DCHECK_LT(executors_.size(), max_num_threads_); |
| 555 // The "thread number" is used to give the thread a unique name. | 555 // The "thread number" is used to give the thread a unique name. |
| 556 int thread_number = executors_.size(); | 556 int thread_number = executors_.size(); |
| 557 ProxyResolver* resolver = resolver_factory_->CreateProxyResolver(); | 557 ProxyResolver* resolver = resolver_factory_->CreateProxyResolver(); |
| 558 Executor* executor = new Executor( | 558 Executor* executor = new Executor( |
| 559 this, resolver, thread_number); | 559 this, resolver, thread_number); |
| 560 executors_.push_back(executor); | 560 executors_.push_back(make_scoped_refptr(executor)); |
| 561 return executor; | 561 return executor; |
| 562 } | 562 } |
| 563 | 563 |
| 564 void MultiThreadedProxyResolver::OnExecutorReady(Executor* executor) { | 564 void MultiThreadedProxyResolver::OnExecutorReady(Executor* executor) { |
| 565 DCHECK(CalledOnValidThread()); | 565 DCHECK(CalledOnValidThread()); |
| 566 if (pending_jobs_.empty()) | 566 if (pending_jobs_.empty()) |
| 567 return; | 567 return; |
| 568 | 568 |
| 569 // Get the next job to process (FIFO). Transfer it from the pending queue | 569 // Get the next job to process (FIFO). Transfer it from the pending queue |
| 570 // to the executor. | 570 // to the executor. |
| 571 scoped_refptr<Job> job = pending_jobs_.front(); | 571 scoped_refptr<Job> job = pending_jobs_.front(); |
| 572 pending_jobs_.pop_front(); | 572 pending_jobs_.pop_front(); |
| 573 executor->StartJob(job); | 573 executor->StartJob(job); |
| 574 } | 574 } |
| 575 | 575 |
| 576 } // namespace net | 576 } // namespace net |
| OLD | NEW |