Add/resurrect support for bundles of WebStore items.
[chromium-blink-merge.git] / jingle / glue / task_pump.cc
blob3c0ddaafeda1037e7f46fee4eb43de75c00723cf
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 : posted_wake_(false),
13 stopped_(false),
14 weak_factory_(this) {
17 TaskPump::~TaskPump() {
18 DCHECK(CalledOnValidThread());
21 void TaskPump::WakeTasks() {
22 DCHECK(CalledOnValidThread());
23 if (!stopped_ && !posted_wake_) {
24 base::MessageLoop* current_message_loop = base::MessageLoop::current();
25 CHECK(current_message_loop);
26 // Do the requested wake up.
27 current_message_loop->PostTask(
28 FROM_HERE,
29 base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr()));
30 posted_wake_ = true;
34 int64 TaskPump::CurrentTime() {
35 DCHECK(CalledOnValidThread());
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.
38 return 0;
41 void TaskPump::Stop() {
42 stopped_ = true;
45 void TaskPump::CheckAndRunTasks() {
46 DCHECK(CalledOnValidThread());
47 if (stopped_) {
48 return;
50 posted_wake_ = false;
51 // We shouldn't be using libjingle for timeout tasks, so we should
52 // have no timeout tasks at all.
54 // TODO(akalin): Add HasTimeoutTask() back in TaskRunner class and
55 // uncomment this check.
56 // DCHECK(!HasTimeoutTask())
57 RunTasks();
60 } // namespace jingle_glue