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/single_threaded_proxy_resolver.h" | 5 #include "net/proxy/single_threaded_proxy_resolver.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/thread.h" | 8 #include "base/thread.h" |
9 #include "net/base/net_log.h" | 9 #include "net/base/capturing_net_log.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/proxy/proxy_info.h" | 11 #include "net/proxy/proxy_info.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class PurgeMemoryTask : public base::RefCountedThreadSafe<PurgeMemoryTask> { | 17 class PurgeMemoryTask : public base::RefCountedThreadSafe<PurgeMemoryTask> { |
18 public: | 18 public: |
19 explicit PurgeMemoryTask(ProxyResolver* resolver) : resolver_(resolver) {} | 19 explicit PurgeMemoryTask(ProxyResolver* resolver) : resolver_(resolver) {} |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 bool is_first_job = pending_jobs_.empty(); | 240 bool is_first_job = pending_jobs_.empty(); |
241 pending_jobs_.push_back(job); // Jobs can never finish synchronously. | 241 pending_jobs_.push_back(job); // Jobs can never finish synchronously. |
242 | 242 |
243 if (is_first_job) { | 243 if (is_first_job) { |
244 // If there is nothing already running, start the job now. | 244 // If there is nothing already running, start the job now. |
245 EnsureThreadStarted(); | 245 EnsureThreadStarted(); |
246 job->Start(); | 246 job->Start(); |
247 } else { | 247 } else { |
248 // Otherwise the job will get started eventually by ProcessPendingJobs(). | 248 // Otherwise the job will get started eventually by ProcessPendingJobs(). |
249 job->net_log()->BeginEvent( | 249 job->net_log()->BeginEvent( |
250 NetLog::TYPE_WAITING_FOR_SINGLE_PROXY_RESOLVER_THREAD); | 250 NetLog::TYPE_WAITING_FOR_SINGLE_PROXY_RESOLVER_THREAD, NULL); |
251 } | 251 } |
252 | 252 |
253 // Completion will be notified through |callback|, unless the caller cancels | 253 // Completion will be notified through |callback|, unless the caller cancels |
254 // the request using |request|. | 254 // the request using |request|. |
255 if (request) | 255 if (request) |
256 *request = reinterpret_cast<RequestHandle>(job.get()); | 256 *request = reinterpret_cast<RequestHandle>(job.get()); |
257 | 257 |
258 return ERR_IO_PENDING; | 258 return ERR_IO_PENDING; |
259 } | 259 } |
260 | 260 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 void SingleThreadedProxyResolver::ProcessPendingJobs() { | 322 void SingleThreadedProxyResolver::ProcessPendingJobs() { |
323 if (pending_jobs_.empty()) | 323 if (pending_jobs_.empty()) |
324 return; | 324 return; |
325 | 325 |
326 // Get the next job to process (FIFO). | 326 // Get the next job to process (FIFO). |
327 Job* job = pending_jobs_.front().get(); | 327 Job* job = pending_jobs_.front().get(); |
328 if (job->is_started()) | 328 if (job->is_started()) |
329 return; | 329 return; |
330 | 330 |
331 job->net_log()->EndEvent( | 331 job->net_log()->EndEvent( |
332 NetLog::TYPE_WAITING_FOR_SINGLE_PROXY_RESOLVER_THREAD); | 332 NetLog::TYPE_WAITING_FOR_SINGLE_PROXY_RESOLVER_THREAD, NULL); |
333 | 333 |
334 EnsureThreadStarted(); | 334 EnsureThreadStarted(); |
335 job->Start(); | 335 job->Start(); |
336 } | 336 } |
337 | 337 |
338 void SingleThreadedProxyResolver::RemoveFrontOfJobsQueueAndStartNext( | 338 void SingleThreadedProxyResolver::RemoveFrontOfJobsQueueAndStartNext( |
339 Job* expected_job) { | 339 Job* expected_job) { |
340 DCHECK_EQ(expected_job, pending_jobs_.front().get()); | 340 DCHECK_EQ(expected_job, pending_jobs_.front().get()); |
341 pending_jobs_.pop_front(); | 341 pending_jobs_.pop_front(); |
342 | 342 |
343 // Start next work item. | 343 // Start next work item. |
344 ProcessPendingJobs(); | 344 ProcessPendingJobs(); |
345 } | 345 } |
346 | 346 |
347 void SingleThreadedProxyResolver::RemoveOutstandingSetPacScriptTask( | 347 void SingleThreadedProxyResolver::RemoveOutstandingSetPacScriptTask( |
348 SetPacScriptTask* task) { | 348 SetPacScriptTask* task) { |
349 DCHECK_EQ(outstanding_set_pac_script_task_.get(), task); | 349 DCHECK_EQ(outstanding_set_pac_script_task_.get(), task); |
350 outstanding_set_pac_script_task_ = NULL; | 350 outstanding_set_pac_script_task_ = NULL; |
351 } | 351 } |
352 | 352 |
353 } // namespace net | 353 } // namespace net |
OLD | NEW |