Adding error message to error string.
[chromium-blink-merge.git] / jingle / glue / task_pump.cc
blobbe5f25b4b6721e61f6d98a762b8daf1aba72dbe8
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
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "jingle/glue/task_pump.h"
9 namespace jingle_glue {
11 TaskPump::TaskPump()
12 : weak_factory_(this),
13 posted_wake_(false),
14 stopped_(false) {}
16 TaskPump::~TaskPump() {
17 DCHECK(CalledOnValidThread());
20 void TaskPump::WakeTasks() {
21 DCHECK(CalledOnValidThread());
22 if (!stopped_ && !posted_wake_) {
23 base::MessageLoop* current_message_loop = base::MessageLoop::current();
24 CHECK(current_message_loop);
25 // Do the requested wake up.
26 current_message_loop->PostTask(
27 FROM_HERE,
28 base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr()));
29 posted_wake_ = true;
33 int64 TaskPump::CurrentTime() {
34 DCHECK(CalledOnValidThread());
35 // Only timeout tasks rely on this function. Since we're not using
36 // libjingle tasks for timeout, it's safe to return 0 here.
37 return 0;
40 void TaskPump::Stop() {
41 stopped_ = true;
44 void TaskPump::CheckAndRunTasks() {
45 DCHECK(CalledOnValidThread());
46 if (stopped_) {
47 return;
49 posted_wake_ = false;
50 // We shouldn't be using libjingle for timeout tasks, so we should
51 // have no timeout tasks at all.
53 // TODO(akalin): Add HasTimeoutTask() back in TaskRunner class and
54 // uncomment this check.
55 // DCHECK(!HasTimeoutTask())
56 RunTasks();
59 } // namespace jingle_glue