| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "jingle/glue/task_pump.h" | 9 #include "jingle/glue/task_pump.h" |
| 10 | 10 |
| 11 namespace jingle_glue { | 11 namespace jingle_glue { |
| 12 | 12 |
| 13 TaskPump::TaskPump() | 13 TaskPump::TaskPump() |
| 14 : posted_wake_(false), | 14 : posted_wake_(false), |
| 15 stopped_(false), | 15 stopped_(false), |
| 16 weak_factory_(this) { | 16 weak_factory_(this) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 TaskPump::~TaskPump() { | 19 TaskPump::~TaskPump() { |
| 20 DCHECK(CalledOnValidThread()); | 20 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void TaskPump::WakeTasks() { | 23 void TaskPump::WakeTasks() { |
| 24 DCHECK(CalledOnValidThread()); | 24 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 25 if (!stopped_ && !posted_wake_) { | 25 if (!stopped_ && !posted_wake_) { |
| 26 // Do the requested wake up. | 26 // Do the requested wake up. |
| 27 base::ThreadTaskRunnerHandle::Get()->PostTask( | 27 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 28 FROM_HERE, | 28 FROM_HERE, |
| 29 base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr())); | 29 base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr())); |
| 30 posted_wake_ = true; | 30 posted_wake_ = true; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 int64_t TaskPump::CurrentTime() { | 34 int64_t TaskPump::CurrentTime() { |
| 35 DCHECK(CalledOnValidThread()); | 35 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 36 // Only timeout tasks rely on this function. Since we're not using | 36 // Only timeout tasks rely on this function. Since we're not using |
| 37 // libjingle tasks for timeout, it's safe to return 0 here. | 37 // libjingle tasks for timeout, it's safe to return 0 here. |
| 38 return 0; | 38 return 0; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void TaskPump::Stop() { | 41 void TaskPump::Stop() { |
| 42 stopped_ = true; | 42 stopped_ = true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void TaskPump::CheckAndRunTasks() { | 45 void TaskPump::CheckAndRunTasks() { |
| 46 DCHECK(CalledOnValidThread()); | 46 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 47 if (stopped_) { | 47 if (stopped_) { |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 posted_wake_ = false; | 50 posted_wake_ = false; |
| 51 // We shouldn't be using libjingle for timeout tasks, so we should | 51 // We shouldn't be using libjingle for timeout tasks, so we should |
| 52 // have no timeout tasks at all. | 52 // have no timeout tasks at all. |
| 53 | 53 |
| 54 // TODO(akalin): Add HasTimeoutTask() back in TaskRunner class and | 54 // TODO(akalin): Add HasTimeoutTask() back in TaskRunner class and |
| 55 // uncomment this check. | 55 // uncomment this check. |
| 56 // DCHECK(!HasTimeoutTask()) | 56 // DCHECK(!HasTimeoutTask()) |
| 57 RunTasks(); | 57 RunTasks(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace jingle_glue | 60 } // namespace jingle_glue |
| OLD | NEW |