| 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/dns/serial_worker.h" | 5 #include "net/dns/serial_worker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 namespace { | |
| 15 // Delay between calls to WorkerPool::PostTask | |
| 16 const int kWorkerPoolRetryDelayMs = 100; | |
| 17 } | |
| 18 | |
| 19 SerialWorker::SerialWorker() | 14 SerialWorker::SerialWorker() |
| 20 : message_loop_(base::MessageLoopProxy::current()), | 15 : message_loop_(base::MessageLoopProxy::current()), |
| 21 state_(IDLE) {} | 16 state_(IDLE) {} |
| 22 | 17 |
| 23 SerialWorker::~SerialWorker() {} | 18 SerialWorker::~SerialWorker() {} |
| 24 | 19 |
| 25 void SerialWorker::WorkNow() { | 20 void SerialWorker::WorkNow() { |
| 26 DCHECK(message_loop_->BelongsToCurrentThread()); | 21 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 27 switch (state_) { | 22 switch (state_) { |
| 28 case IDLE: | 23 case IDLE: |
| 29 if (!base::WorkerPool::PostTask(FROM_HERE, base::Bind( | 24 if (!base::WorkerPool::PostTask(FROM_HERE, base::Bind( |
| 30 &SerialWorker::DoWorkJob, this), false)) { | 25 &SerialWorker::DoWorkJob, this), false)) { |
| 31 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
| 32 // See worker_pool_posix.cc. | 27 // See worker_pool_posix.cc. |
| 33 NOTREACHED() << "WorkerPool::PostTask is not expected to fail on posix"; | 28 NOTREACHED() << "WorkerPool::PostTask is not expected to fail on posix"; |
| 34 #else | 29 #else |
| 35 LOG(WARNING) << "Failed to WorkerPool::PostTask, will retry later"; | 30 LOG(WARNING) << "Failed to WorkerPool::PostTask, will retry later"; |
| 31 const int kWorkerPoolRetryDelayMs = 100; |
| 36 message_loop_->PostDelayedTask( | 32 message_loop_->PostDelayedTask( |
| 37 FROM_HERE, | 33 FROM_HERE, |
| 38 base::Bind(&SerialWorker::RetryWork, this), | 34 base::Bind(&SerialWorker::RetryWork, this), |
| 39 base::TimeDelta::FromMilliseconds(kWorkerPoolRetryDelayMs)); | 35 base::TimeDelta::FromMilliseconds(kWorkerPoolRetryDelayMs)); |
| 40 state_ = WAITING; | 36 state_ = WAITING; |
| 41 return; | 37 return; |
| 42 #endif | 38 #endif |
| 43 } | 39 } |
| 44 state_ = WORKING; | 40 state_ = WORKING; |
| 45 return; | 41 return; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 state_ = IDLE; | 91 state_ = IDLE; |
| 96 WorkNow(); | 92 WorkNow(); |
| 97 return; | 93 return; |
| 98 default: | 94 default: |
| 99 NOTREACHED() << "Unexpected state " << state_; | 95 NOTREACHED() << "Unexpected state " << state_; |
| 100 } | 96 } |
| 101 } | 97 } |
| 102 | 98 |
| 103 } // namespace net | 99 } // namespace net |
| 104 | 100 |
| OLD | NEW |