Built UserAgent according to OS And Product.
[platform/framework/web/crosswalk-tizen.git] / atom / browser / bridge_task_runner.cc
1 // Copyright (c) 2015 GitHub, Inc.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
4
5 #include "atom/browser/bridge_task_runner.h"
6
7 #include "base/message_loop/message_loop.h"
8
9 namespace atom {
10
11 void BridgeTaskRunner::MessageLoopIsReady() {
12   auto message_loop = base::MessageLoop::current();
13   CHECK(message_loop);
14   for (const TaskPair& task : tasks_) {
15     message_loop->task_runner()->PostDelayedTask(
16         base::get<0>(task), base::get<1>(task), base::get<2>(task));
17   }
18   for (const TaskPair& task : non_nestable_tasks_) {
19     message_loop->task_runner()->PostNonNestableDelayedTask(
20         base::get<0>(task), base::get<1>(task), base::get<2>(task));
21   }
22 }
23
24 bool BridgeTaskRunner::PostDelayedTask(
25     const tracked_objects::Location& from_here,
26     const base::Closure& task,
27     base::TimeDelta delay) {
28   auto message_loop = base::MessageLoop::current();
29   if (!message_loop) {
30     tasks_.push_back(std::make_tuple(from_here, task, delay));
31     return true;
32   }
33
34   return message_loop->task_runner()->PostDelayedTask(from_here, task, delay);
35 }
36
37 bool BridgeTaskRunner::RunsTasksOnCurrentThread() const {
38   auto message_loop = base::MessageLoop::current();
39   if (!message_loop)
40     return true;
41
42   return message_loop->task_runner()->RunsTasksOnCurrentThread();
43 }
44
45 bool BridgeTaskRunner::PostNonNestableDelayedTask(
46     const tracked_objects::Location& from_here,
47     const base::Closure& task,
48     base::TimeDelta delay) {
49   auto message_loop = base::MessageLoop::current();
50   if (!message_loop) {
51     non_nestable_tasks_.push_back(std::make_tuple(from_here, task, delay));
52     return true;
53   }
54
55   return message_loop->task_runner()->PostNonNestableDelayedTask(
56       from_here, task, delay);
57 }
58
59 }  // namespace atom