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

Side by Side Diff: base/android/base_jni_onload.cc

Issue 935413004: Separate OnJNIOnLoad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 5 years, 10 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
« no previous file with comments | « base/android/base_jni_onload.h ('k') | base/android/jni_onload_delegate.h » ('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 2015 The Chromium Authors. All rights reserved. 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 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 "base/android/base_jni_onload.h" 5 #include "base/android/base_jni_onload.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_onload_delegate.h"
9 #include "base/android/jni_utils.h" 8 #include "base/android/jni_utils.h"
10 #include "base/android/library_loader/library_loader_hooks.h" 9 #include "base/android/library_loader/library_loader_hooks.h"
10 #include "base/bind.h"
11 11
12 namespace base { 12 namespace base {
13 namespace android { 13 namespace android {
14 14
15 namespace { 15 namespace {
16 16
17 // The JNIOnLoadDelegate implementation in base. 17 bool RegisterJNI(JNIEnv* env) {
18 class BaseJNIOnLoadDelegate : public JNIOnLoadDelegate {
19 public:
20 bool RegisterJNI(JNIEnv* env) override;
21 bool Init() override;
22 };
23
24 bool BaseJNIOnLoadDelegate::RegisterJNI(JNIEnv* env) {
25 return RegisterLibraryLoaderEntryHook(env); 18 return RegisterLibraryLoaderEntryHook(env);
26 } 19 }
27 20
28 bool BaseJNIOnLoadDelegate::Init() { 21 bool Init() {
29 JNIEnv* env = base::android::AttachCurrentThread(); 22 JNIEnv* env = base::android::AttachCurrentThread();
30
31 base::android::InitReplacementClassLoader(env, 23 base::android::InitReplacementClassLoader(env,
32 base::android::GetClassLoader(env)); 24 base::android::GetClassLoader(env));
33
34 return true; 25 return true;
35 } 26 }
36 27
37 } // namespace 28 } // namespace
38 29
39 30
40 bool OnJNIOnLoad(JavaVM* vm, 31 bool OnJNIOnLoadRegisterJNI(JavaVM* vm,
41 std::vector<JNIOnLoadDelegate*>* delegates) { 32 std::vector<RegisterCallback> callbacks) {
42 base::android::InitVM(vm); 33 base::android::InitVM(vm);
43 JNIEnv* env = base::android::AttachCurrentThread(); 34 JNIEnv* env = base::android::AttachCurrentThread();
44 35
45 BaseJNIOnLoadDelegate delegate; 36 callbacks.push_back(base::Bind(&RegisterJNI));
46 delegates->push_back(&delegate); 37 for (std::vector<RegisterCallback>::reverse_iterator i =
47 bool ret = true; 38 callbacks.rbegin(); i != callbacks.rend(); ++i) {
48 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = 39 if (!i->Run(env))
49 delegates->rbegin(); i != delegates->rend(); ++i) { 40 return false;
50 if (!(*i)->RegisterJNI(env)) {
51 ret = false;
52 break;
53 }
54 } 41 }
42 return true;
43 }
55 44
56 if (ret) { 45 bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks) {
57 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = 46 callbacks.push_back(base::Bind(&Init));
58 delegates->rbegin(); i != delegates->rend(); ++i) { 47 for (std::vector<InitCallback>::reverse_iterator i =
59 if (!(*i)->Init()) { 48 callbacks.rbegin(); i != callbacks.rend(); ++i) {
60 ret = false; 49 if (!i->Run())
61 break; 50 return false;
62 }
63 }
64 } 51 }
65 delegates->pop_back(); 52 return true;
66 return ret;
67 } 53 }
68 54
69 } // namespace android 55 } // namespace android
70 } // namespace base 56 } // namespace base
OLDNEW
« no previous file with comments | « base/android/base_jni_onload.h ('k') | base/android/jni_onload_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698