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

Side by Side Diff: mojo/android/system/core_impl.cc

Issue 339403003: Mojo: Make GetDefault{AsyncWaiter,Logger} static methods of Environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/bindings/js/support.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/android/base_jni_registrar.h" 7 #include "base/android/base_jni_registrar.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_registrar.h" 9 #include "base/android/jni_registrar.h"
10 #include "base/android/library_loader/library_loader_hooks.h" 10 #include "base/android/library_loader/library_loader_hooks.h"
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "jni/CoreImpl_jni.h" 14 #include "jni/CoreImpl_jni.h"
15 #include "mojo/embedder/embedder.h" 15 #include "mojo/embedder/embedder.h"
16 #include "mojo/public/c/environment/async_waiter.h" 16 #include "mojo/public/c/environment/async_waiter.h"
17 #include "mojo/public/c/system/core.h" 17 #include "mojo/public/c/system/core.h"
18 #include "mojo/public/cpp/environment/default_async_waiter.h" 18 #include "mojo/public/cpp/environment/environment.h"
19 19
20 namespace { 20 namespace {
21 21
22 // |AsyncWait| is guaranteed never to return 0. 22 // |AsyncWait| is guaranteed never to return 0.
23 const MojoAsyncWaitID kInvalidHandleCancelID = 0; 23 const MojoAsyncWaitID kInvalidHandleCancelID = 0;
24 24
25 struct AsyncWaitCallbackData { 25 struct AsyncWaitCallbackData {
26 base::android::ScopedJavaGlobalRef<jobject> core_impl; 26 base::android::ScopedJavaGlobalRef<jobject> core_impl;
27 base::android::ScopedJavaGlobalRef<jobject> callback; 27 base::android::ScopedJavaGlobalRef<jobject> callback;
28 base::android::ScopedJavaGlobalRef<jobject> cancellable; 28 base::android::ScopedJavaGlobalRef<jobject> cancellable;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 static jobject AsyncWait(JNIEnv* env, 322 static jobject AsyncWait(JNIEnv* env,
323 jobject jcaller, 323 jobject jcaller,
324 jint mojo_handle, 324 jint mojo_handle,
325 jint signals, 325 jint signals,
326 jlong deadline, 326 jlong deadline,
327 jobject callback) { 327 jobject callback) {
328 AsyncWaitCallbackData* callback_data = 328 AsyncWaitCallbackData* callback_data =
329 new AsyncWaitCallbackData(env, jcaller, callback); 329 new AsyncWaitCallbackData(env, jcaller, callback);
330 MojoAsyncWaitID cancel_id; 330 MojoAsyncWaitID cancel_id;
331 if (static_cast<MojoHandle>(mojo_handle) != MOJO_HANDLE_INVALID) { 331 if (static_cast<MojoHandle>(mojo_handle) != MOJO_HANDLE_INVALID) {
332 cancel_id = mojo::GetDefaultAsyncWaiter()->AsyncWait(mojo_handle, 332 cancel_id = mojo::Environment::GetDefaultAsyncWaiter()->AsyncWait(
333 signals, 333 mojo_handle, signals, deadline, AsyncWaitCallback, callback_data);
334 deadline,
335 AsyncWaitCallback,
336 callback_data);
337 } else { 334 } else {
338 cancel_id = kInvalidHandleCancelID; 335 cancel_id = kInvalidHandleCancelID;
339 base::MessageLoop::current()->PostTask( 336 base::MessageLoop::current()->PostTask(
340 FROM_HERE, 337 FROM_HERE,
341 base::Bind( 338 base::Bind(
342 &AsyncWaitCallback, callback_data, MOJO_RESULT_INVALID_ARGUMENT)); 339 &AsyncWaitCallback, callback_data, MOJO_RESULT_INVALID_ARGUMENT));
343 } 340 }
344 base::android::ScopedJavaLocalRef<jobject> cancellable = 341 base::android::ScopedJavaLocalRef<jobject> cancellable =
345 Java_CoreImpl_newAsyncWaiterCancellableImpl( 342 Java_CoreImpl_newAsyncWaiterCancellableImpl(
346 env, jcaller, cancel_id, reinterpret_cast<intptr_t>(callback_data)); 343 env, jcaller, cancel_id, reinterpret_cast<intptr_t>(callback_data));
347 callback_data->cancellable.Reset(env, cancellable.obj()); 344 callback_data->cancellable.Reset(env, cancellable.obj());
348 return cancellable.Release(); 345 return cancellable.Release();
349 } 346 }
350 347
351 static void CancelAsyncWait(JNIEnv* env, 348 static void CancelAsyncWait(JNIEnv* env,
352 jobject jcaller, 349 jobject jcaller,
353 jlong id, 350 jlong id,
354 jlong data_ptr) { 351 jlong data_ptr) {
355 if (id == 0) { 352 if (id == 0) {
356 // If |id| is |kInvalidHandleCancelID|, the async wait was done on an 353 // If |id| is |kInvalidHandleCancelID|, the async wait was done on an
357 // invalid handle, so the AsyncWaitCallback will be called and will clear 354 // invalid handle, so the AsyncWaitCallback will be called and will clear
358 // the data_ptr. 355 // the data_ptr.
359 return; 356 return;
360 } 357 }
361 scoped_ptr<AsyncWaitCallbackData> deleter( 358 scoped_ptr<AsyncWaitCallbackData> deleter(
362 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); 359 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr));
363 mojo::GetDefaultAsyncWaiter()->CancelWait(id); 360 mojo::Environment::GetDefaultAsyncWaiter()->CancelWait(id);
364 } 361 }
365 362
366 bool RegisterCoreImpl(JNIEnv* env) { 363 bool RegisterCoreImpl(JNIEnv* env) {
367 return RegisterNativesImpl(env); 364 return RegisterNativesImpl(env);
368 } 365 }
369 366
370 } // namespace android 367 } // namespace android
371 } // namespace mojo 368 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/bindings/js/support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698