Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / base / android / base_jni_onload.cc
blob7ab4982c427276ac438ff0b2adabe46ca4cfc1da
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 "base/android/base_jni_onload.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_utils.h"
9 #include "base/android/library_loader/library_loader_hooks.h"
10 #include "base/bind.h"
12 namespace base {
13 namespace android {
15 namespace {
17 bool RegisterJNI(JNIEnv* env) {
18 return RegisterLibraryLoaderEntryHook(env);
21 bool Init() {
22 InitAtExitManager();
23 JNIEnv* env = base::android::AttachCurrentThread();
24 base::android::InitReplacementClassLoader(env,
25 base::android::GetClassLoader(env));
26 return true;
29 } // namespace
32 bool OnJNIOnLoadRegisterJNI(JavaVM* vm,
33 std::vector<RegisterCallback> callbacks) {
34 base::android::InitVM(vm);
35 JNIEnv* env = base::android::AttachCurrentThread();
37 callbacks.push_back(base::Bind(&RegisterJNI));
38 for (std::vector<RegisterCallback>::reverse_iterator i =
39 callbacks.rbegin(); i != callbacks.rend(); ++i) {
40 if (!i->Run(env))
41 return false;
43 return true;
46 bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks) {
47 callbacks.push_back(base::Bind(&Init));
48 for (std::vector<InitCallback>::reverse_iterator i =
49 callbacks.rbegin(); i != callbacks.rend(); ++i) {
50 if (!i->Run())
51 return false;
53 return true;
56 } // namespace android
57 } // namespace base