Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: mojo/python/content_handler/python_system_impl_helper.cc

Issue 796373006: Content handler for python. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/python/content_handler/python_system_impl_helper.cc
diff --git a/mojo/python/content_handler/python_system_impl_helper.cc b/mojo/python/content_handler/python_system_impl_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..68887e3ad761c6e1ded7469b731c1648284e3864
--- /dev/null
+++ b/mojo/python/content_handler/python_system_impl_helper.cc
@@ -0,0 +1,64 @@
+// Copyright 2013 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 "python_system_impl_helper.h"
+
+#include <Python.h>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "mojo/common/message_pump_mojo.h"
+#include "mojo/public/python/src/common.h"
+
+namespace {
+class QuitCurrentRunLoop : public mojo::Closure::Runnable {
+ public:
+ void Run() const override {
+ base::MessageLoop::current()->Quit();
+ }
+
+ static mojo::Closure::Runnable* NewInstance() {
+ return new QuitCurrentRunLoop();
+ }
+};
+
+} // namespace
+namespace mojo {
+namespace python {
+
+PythonRunLoop::PythonRunLoop() : loop_(common::MessagePumpMojo::Create()) {
+}
+
+PythonRunLoop::~PythonRunLoop() {
+}
+
+void PythonRunLoop::Run() {
+ loop_.Run();
+}
+
+void PythonRunLoop::RunUntilIdle() {
+ loop_.RunUntilIdle();
+}
+
+void PythonRunLoop::Quit() {
+ loop_.Quit();
+}
+
+void PythonRunLoop::PostDelayedTask(PyObject* callable, MojoTimeTicks delay) {
+ Closure::Runnable* quit_runnable =
+ NewRunnableFromCallable(callable, loop_.QuitClosure());
+
+ loop_.PostDelayedTask(
+ FROM_HERE, base::Bind(&mojo::Closure::Run,
+ base::Owned(new mojo::Closure(quit_runnable))),
+ base::TimeDelta::FromMicroseconds(delay));
+}
+
+PythonAsyncWaiter* NewAsyncWaiter() {
+ return new PythonAsyncWaiter(
+ mojo::Closure(QuitCurrentRunLoop::NewInstance()));
+}
+
+} // namespace python
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698