Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / mojo / android / system / base_run_loop.cc
blobdf78561b27de3d8cb57de74d3b9a4278334976d8
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/android/system/base_run_loop.h"
7 #include <jni.h>
9 #include "base/android/base_jni_registrar.h"
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_registrar.h"
12 #include "base/bind.h"
13 #include "base/message_loop/message_loop.h"
14 #include "jni/BaseRunLoop_jni.h"
15 #include "mojo/message_pump/message_pump_mojo.h"
17 namespace mojo {
18 namespace android {
20 static jlong CreateBaseRunLoop(JNIEnv* env,
21 const JavaParamRef<jobject>& jcaller) {
22 base::MessageLoop* message_loop =
23 new base::MessageLoop(common::MessagePumpMojo::Create());
24 return reinterpret_cast<uintptr_t>(message_loop);
27 static void Run(JNIEnv* env,
28 const JavaParamRef<jobject>& jcaller,
29 jlong runLoopID) {
30 reinterpret_cast<base::MessageLoop*>(runLoopID)->Run();
33 static void RunUntilIdle(JNIEnv* env,
34 const JavaParamRef<jobject>& jcaller,
35 jlong runLoopID) {
36 reinterpret_cast<base::MessageLoop*>(runLoopID)->RunUntilIdle();
39 static void Quit(JNIEnv* env,
40 const JavaParamRef<jobject>& jcaller,
41 jlong runLoopID) {
42 reinterpret_cast<base::MessageLoop*>(runLoopID)->Quit();
45 static void RunJavaRunnable(
46 const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) {
47 Java_BaseRunLoop_runRunnable(base::android::AttachCurrentThread(),
48 runnable_ref.obj());
51 static void PostDelayedTask(JNIEnv* env,
52 const JavaParamRef<jobject>& jcaller,
53 jlong runLoopID,
54 const JavaParamRef<jobject>& runnable,
55 jlong delay) {
56 base::android::ScopedJavaGlobalRef<jobject> runnable_ref;
57 // ScopedJavaGlobalRef do not hold onto the env reference, so it is safe to
58 // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before
59 // running the Runnable.
60 runnable_ref.Reset(env, runnable);
61 reinterpret_cast<base::MessageLoop*>(runLoopID)->PostDelayedTask(
62 FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref),
63 base::TimeDelta::FromMicroseconds(delay));
66 static void DeleteMessageLoop(JNIEnv* env,
67 const JavaParamRef<jobject>& jcaller,
68 jlong runLoopID) {
69 base::MessageLoop* message_loop =
70 reinterpret_cast<base::MessageLoop*>(runLoopID);
71 delete message_loop;
74 bool RegisterBaseRunLoop(JNIEnv* env) {
75 return RegisterNativesImpl(env);
78 } // namespace android
79 } // namespace mojo