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