| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/public/python/src/python_system_helper.h" | 5 #include "mojo/public/python/src/python_system_helper.h" |
| 6 | 6 |
| 7 #include "Python.h" | 7 #include "Python.h" |
| 8 | 8 |
| 9 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
| 10 #include "mojo/public/cpp/environment/logging.h" | 10 #include "mojo/public/cpp/environment/logging.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedPyRef); | 51 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedPyRef); |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 class PythonClosure : public mojo::Closure::Runnable { | 54 class PythonClosure : public mojo::Closure::Runnable { |
| 55 public: | 55 public: |
| 56 PythonClosure(PyObject* callable) : callable_(callable, kAcquire) { | 56 PythonClosure(PyObject* callable) : callable_(callable, kAcquire) { |
| 57 MOJO_DCHECK(callable); | 57 MOJO_DCHECK(callable); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual void Run() const override { | 60 void Run() const override { |
| 61 ScopedGIL acquire_gil; | 61 ScopedGIL acquire_gil; |
| 62 ScopedPyRef empty_tuple(PyTuple_New(0)); | 62 ScopedPyRef empty_tuple(PyTuple_New(0)); |
| 63 if (!empty_tuple) { | 63 if (!empty_tuple) { |
| 64 mojo::RunLoop::current()->Quit(); | 64 mojo::RunLoop::current()->Quit(); |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 | 67 |
| 68 ScopedPyRef result(PyObject_CallObject(callable_, empty_tuple)); | 68 ScopedPyRef result(PyObject_CallObject(callable_, empty_tuple)); |
| 69 if (!result) { | 69 if (!result) { |
| 70 mojo::RunLoop::current()->Quit(); | 70 mojo::RunLoop::current()->Quit(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 94 : public mojo::Callback<void(MojoResult)>::Runnable { | 94 : public mojo::Callback<void(MojoResult)>::Runnable { |
| 95 public: | 95 public: |
| 96 AsyncWaiterRunnable(PyObject* callable, CallbackMap* callbacks) | 96 AsyncWaiterRunnable(PyObject* callable, CallbackMap* callbacks) |
| 97 : wait_id_(0), callable_(callable, kAcquire), callbacks_(callbacks) { | 97 : wait_id_(0), callable_(callable, kAcquire), callbacks_(callbacks) { |
| 98 MOJO_DCHECK(callable); | 98 MOJO_DCHECK(callable); |
| 99 MOJO_DCHECK(callbacks_); | 99 MOJO_DCHECK(callbacks_); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void set_wait_id(int wait_id) { wait_id_ = wait_id; } | 102 void set_wait_id(int wait_id) { wait_id_ = wait_id; } |
| 103 | 103 |
| 104 virtual void Run(MojoResult mojo_result) const override { | 104 void Run(MojoResult mojo_result) const override { |
| 105 MOJO_DCHECK(wait_id_); | 105 MOJO_DCHECK(wait_id_); |
| 106 | 106 |
| 107 // Remove to reference to this object from PythonAsyncWaiter and ensure this | 107 // Remove to reference to this object from PythonAsyncWaiter and ensure this |
| 108 // object will be destroyed when this method exits. | 108 // object will be destroyed when this method exits. |
| 109 MOJO_DCHECK(callbacks_->find(wait_id_) != callbacks_->end()); | 109 MOJO_DCHECK(callbacks_->find(wait_id_) != callbacks_->end()); |
| 110 internal::SharedPtr<mojo::Callback<void(MojoResult)>> self = | 110 internal::SharedPtr<mojo::Callback<void(MojoResult)>> self = |
| 111 (*callbacks_)[wait_id_]; | 111 (*callbacks_)[wait_id_]; |
| 112 callbacks_->erase(wait_id_); | 112 callbacks_->erase(wait_id_); |
| 113 | 113 |
| 114 ScopedGIL acquire_gil; | 114 ScopedGIL acquire_gil; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 void PythonAsyncWaiter::CancelWait(MojoAsyncWaitID wait_id) { | 171 void PythonAsyncWaiter::CancelWait(MojoAsyncWaitID wait_id) { |
| 172 if (callbacks_.find(wait_id) != callbacks_.end()) { | 172 if (callbacks_.find(wait_id) != callbacks_.end()) { |
| 173 async_waiter_->CancelWait(wait_id); | 173 async_waiter_->CancelWait(wait_id); |
| 174 callbacks_.erase(wait_id); | 174 callbacks_.erase(wait_id); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace python | 178 } // namespace python |
| 179 } // namespace mojo | 179 } // namespace mojo |
| OLD | NEW |