| 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/android/system/core_impl.h" | 5 #include "mojo/android/system/core_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/android/base_jni_registrar.h" | 12 #include "base/android/base_jni_registrar.h" |
| 13 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
| 14 #include "base/android/jni_registrar.h" | 14 #include "base/android/jni_registrar.h" |
| 15 #include "base/android/library_loader/library_loader_hooks.h" | 15 #include "base/android/library_loader/library_loader_hooks.h" |
| 16 #include "base/android/scoped_java_ref.h" | 16 #include "base/android/scoped_java_ref.h" |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/message_loop/message_loop.h" | 18 #include "base/location.h" |
| 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "jni/CoreImpl_jni.h" | 21 #include "jni/CoreImpl_jni.h" |
| 20 #include "mojo/message_pump/handle_watcher.h" | 22 #include "mojo/message_pump/handle_watcher.h" |
| 21 #include "mojo/public/c/system/core.h" | 23 #include "mojo/public/c/system/core.h" |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 using MojoAsyncWaitID = uintptr_t; | 27 using MojoAsyncWaitID = uintptr_t; |
| 26 const MojoAsyncWaitID kInvalidHandleCancelID = 0; | 28 const MojoAsyncWaitID kInvalidHandleCancelID = 0; |
| 27 | 29 |
| 28 struct AsyncWaitCallbackData { | 30 struct AsyncWaitCallbackData { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 new AsyncWaitCallbackData(env, jcaller, callback); | 376 new AsyncWaitCallbackData(env, jcaller, callback); |
| 375 MojoAsyncWaitID cancel_id; | 377 MojoAsyncWaitID cancel_id; |
| 376 if (static_cast<MojoHandle>(mojo_handle) != MOJO_HANDLE_INVALID) { | 378 if (static_cast<MojoHandle>(mojo_handle) != MOJO_HANDLE_INVALID) { |
| 377 common::HandleWatcher* watcher = new common::HandleWatcher(); | 379 common::HandleWatcher* watcher = new common::HandleWatcher(); |
| 378 cancel_id = reinterpret_cast<MojoAsyncWaitID>(watcher); | 380 cancel_id = reinterpret_cast<MojoAsyncWaitID>(watcher); |
| 379 watcher->Start(Handle(static_cast<MojoHandle>(mojo_handle)), signals, | 381 watcher->Start(Handle(static_cast<MojoHandle>(mojo_handle)), signals, |
| 380 deadline, | 382 deadline, |
| 381 base::Bind(&AsyncWaitCallback, watcher, callback_data)); | 383 base::Bind(&AsyncWaitCallback, watcher, callback_data)); |
| 382 } else { | 384 } else { |
| 383 cancel_id = kInvalidHandleCancelID; | 385 cancel_id = kInvalidHandleCancelID; |
| 384 base::MessageLoop::current()->PostTask( | 386 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 385 FROM_HERE, base::Bind(&AsyncWaitCallback, nullptr, callback_data, | 387 FROM_HERE, base::Bind(&AsyncWaitCallback, nullptr, callback_data, |
| 386 MOJO_RESULT_INVALID_ARGUMENT)); | 388 MOJO_RESULT_INVALID_ARGUMENT)); |
| 387 } | 389 } |
| 388 base::android::ScopedJavaLocalRef<jobject> cancellable = | 390 base::android::ScopedJavaLocalRef<jobject> cancellable = |
| 389 Java_CoreImpl_newAsyncWaiterCancellableImpl( | 391 Java_CoreImpl_newAsyncWaiterCancellableImpl( |
| 390 env, jcaller, cancel_id, reinterpret_cast<intptr_t>(callback_data)); | 392 env, jcaller, cancel_id, reinterpret_cast<intptr_t>(callback_data)); |
| 391 callback_data->cancellable.Reset(env, cancellable.obj()); | 393 callback_data->cancellable.Reset(env, cancellable.obj()); |
| 392 return cancellable; | 394 return cancellable; |
| 393 } | 395 } |
| 394 | 396 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 419 return 0; | 421 return 0; |
| 420 return alignment - offset; | 422 return alignment - offset; |
| 421 } | 423 } |
| 422 | 424 |
| 423 bool RegisterCoreImpl(JNIEnv* env) { | 425 bool RegisterCoreImpl(JNIEnv* env) { |
| 424 return RegisterNativesImpl(env); | 426 return RegisterNativesImpl(env); |
| 425 } | 427 } |
| 426 | 428 |
| 427 } // namespace android | 429 } // namespace android |
| 428 } // namespace mojo | 430 } // namespace mojo |
| OLD | NEW |