summaryrefslogtreecommitdiffstats
path: root/jingle/notifier/base/task_pump.cc
blob: 52ffd26bbdad6c20e1b8c7dccc6ee0d1678f85b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/message_loop.h"
#include "jingle/notifier/base/task_pump.h"

namespace notifier {

TaskPump::TaskPump()
    : scoped_runnable_method_factory_(
        ALLOW_THIS_IN_INITIALIZER_LIST(this)),
      posted_wake_(false) {}

TaskPump::~TaskPump() {}

void TaskPump::WakeTasks() {
  if (!posted_wake_) {
    // Do the requested wake up.
    MessageLoop::current()->PostTask(
        FROM_HERE,
        scoped_runnable_method_factory_.NewRunnableMethod(
            &TaskPump::CheckAndRunTasks));
    posted_wake_ = true;
  }
}

int64 TaskPump::CurrentTime() {
  // Only timeout tasks rely on this function.  Since we're not using
  // libjingle tasks for timeout, it's safe to return 0 here.
  return 0;
}

void TaskPump::CheckAndRunTasks() {
  posted_wake_ = false;
  // We shouldn't be using libjingle for timeout tasks, so we should
  // have no timeout tasks at all.

  // TODO(akalin): Add HasTimeoutTask() back in TaskRunner class and
  // uncomment this check.
  // DCHECK(!HasTimeoutTask())
  RunTasks();
}

}  // namespace notifier