OLD | NEW |
| (Empty) |
1 // Copyright 2013 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. | |
4 | |
5 #include "python_system_impl_helper.h" | |
6 | |
7 #include <Python.h> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/location.h" | |
11 #include "mojo/common/message_pump_mojo.h" | |
12 #include "mojo/public/python/src/common.h" | |
13 | |
14 namespace { | |
15 class QuitCurrentRunLoop : public mojo::Closure::Runnable { | |
16 public: | |
17 void Run() const override { | |
18 base::MessageLoop::current()->Quit(); | |
19 } | |
20 | |
21 static mojo::Closure::Runnable* NewInstance() { | |
22 return new QuitCurrentRunLoop(); | |
23 } | |
24 }; | |
25 | |
26 } // namespace | |
27 namespace mojo { | |
28 namespace python { | |
29 | |
30 PythonRunLoop::PythonRunLoop() : loop_(common::MessagePumpMojo::Create()) { | |
31 } | |
32 | |
33 PythonRunLoop::~PythonRunLoop() { | |
34 } | |
35 | |
36 void PythonRunLoop::Run() { | |
37 loop_.Run(); | |
38 } | |
39 | |
40 void PythonRunLoop::RunUntilIdle() { | |
41 loop_.RunUntilIdle(); | |
42 } | |
43 | |
44 void PythonRunLoop::Quit() { | |
45 loop_.Quit(); | |
46 } | |
47 | |
48 void PythonRunLoop::PostDelayedTask(PyObject* callable, MojoTimeTicks delay) { | |
49 Closure::Runnable* quit_runnable = | |
50 NewRunnableFromCallable(callable, loop_.QuitClosure()); | |
51 | |
52 loop_.PostDelayedTask( | |
53 FROM_HERE, base::Bind(&mojo::Closure::Run, | |
54 base::Owned(new mojo::Closure(quit_runnable))), | |
55 base::TimeDelta::FromMicroseconds(delay)); | |
56 } | |
57 | |
58 PythonAsyncWaiter* NewAsyncWaiter() { | |
59 return new PythonAsyncWaiter( | |
60 mojo::Closure(QuitCurrentRunLoop::NewInstance())); | |
61 } | |
62 | |
63 } // namespace python | |
64 } // namespace mojo | |
OLD | NEW |