| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" |
| 5 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 6 #include "jingle/notifier/base/task_pump.h" | 7 #include "jingle/notifier/base/task_pump.h" |
| 7 | 8 |
| 8 namespace notifier { | 9 namespace notifier { |
| 9 | 10 |
| 10 TaskPump::TaskPump() | 11 TaskPump::TaskPump() |
| 11 : scoped_runnable_method_factory_( | 12 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 12 ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
| 13 posted_wake_(false), | 13 posted_wake_(false), |
| 14 stopped_(false) {} | 14 stopped_(false) {} |
| 15 | 15 |
| 16 TaskPump::~TaskPump() { | 16 TaskPump::~TaskPump() { |
| 17 DCHECK(non_thread_safe_.CalledOnValidThread()); | 17 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void TaskPump::WakeTasks() { | 20 void TaskPump::WakeTasks() { |
| 21 DCHECK(non_thread_safe_.CalledOnValidThread()); | 21 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 22 if (!stopped_ && !posted_wake_) { | 22 if (!stopped_ && !posted_wake_) { |
| 23 MessageLoop* current_message_loop = MessageLoop::current(); | 23 MessageLoop* current_message_loop = MessageLoop::current(); |
| 24 CHECK(current_message_loop); | 24 CHECK(current_message_loop); |
| 25 // Do the requested wake up. | 25 // Do the requested wake up. |
| 26 current_message_loop->PostTask( | 26 current_message_loop->PostTask( |
| 27 FROM_HERE, | 27 FROM_HERE, |
| 28 scoped_runnable_method_factory_.NewRunnableMethod( | 28 base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr())); |
| 29 &TaskPump::CheckAndRunTasks)); | |
| 30 posted_wake_ = true; | 29 posted_wake_ = true; |
| 31 } | 30 } |
| 32 } | 31 } |
| 33 | 32 |
| 34 int64 TaskPump::CurrentTime() { | 33 int64 TaskPump::CurrentTime() { |
| 35 DCHECK(non_thread_safe_.CalledOnValidThread()); | 34 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 36 // Only timeout tasks rely on this function. Since we're not using | 35 // Only timeout tasks rely on this function. Since we're not using |
| 37 // libjingle tasks for timeout, it's safe to return 0 here. | 36 // libjingle tasks for timeout, it's safe to return 0 here. |
| 38 return 0; | 37 return 0; |
| 39 } | 38 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 // We shouldn't be using libjingle for timeout tasks, so we should | 50 // We shouldn't be using libjingle for timeout tasks, so we should |
| 52 // have no timeout tasks at all. | 51 // have no timeout tasks at all. |
| 53 | 52 |
| 54 // TODO(akalin): Add HasTimeoutTask() back in TaskRunner class and | 53 // TODO(akalin): Add HasTimeoutTask() back in TaskRunner class and |
| 55 // uncomment this check. | 54 // uncomment this check. |
| 56 // DCHECK(!HasTimeoutTask()) | 55 // DCHECK(!HasTimeoutTask()) |
| 57 RunTasks(); | 56 RunTasks(); |
| 58 } | 57 } |
| 59 | 58 |
| 60 } // namespace notifier | 59 } // namespace notifier |
| OLD | NEW |