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

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: 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
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" 8 #include "base/android/jni_onload_delegate.h"
9 #include "base/android/library_loader/library_loader_hooks.h" 9 #include "base/android/library_loader/library_loader_hooks.h"
10 10
11 namespace base { 11 namespace base {
12 namespace android { 12 namespace android {
13 13
14 namespace { 14 namespace {
15 15
16 // The JNIOnLoadDelegate implementation in base. 16 // The JNIOnLoadDelegate implementation in base.
17 class BaseJNIOnLoadDelegate : public JNIOnLoadDelegate { 17 class BaseJNIOnLoadDelegate : public JNIOnLoadDelegate {
18 public: 18 public:
19 bool RegisterJNI(JNIEnv* env) override; 19 bool RegisterJNI(JNIEnv* env) override {
20 bool Init() override; 20 return RegisterLibraryLoaderEntryHook(env);
21 }
22 bool Init() override {
23 return true;
24 }
21 }; 25 };
22 26
23 bool BaseJNIOnLoadDelegate::RegisterJNI(JNIEnv* env) {
24 return RegisterLibraryLoaderEntryHook(env);
25 }
26
27 bool BaseJNIOnLoadDelegate::Init() {
28 return true;
29 }
30
31 } // namespace 27 } // namespace
32 28
33 29
34 bool OnJNIOnLoad(JavaVM* vm, 30 bool OnJNIOnLoadRegisterJNI(
35 std::vector<JNIOnLoadDelegate*>* delegates) { 31 JavaVM* vm,
32 std::vector<JNIOnLoadDelegate*>* delegates) {
36 base::android::InitVM(vm); 33 base::android::InitVM(vm);
37 JNIEnv* env = base::android::AttachCurrentThread(); 34 JNIEnv* env = base::android::AttachCurrentThread();
38 35
39 BaseJNIOnLoadDelegate delegate; 36 BaseJNIOnLoadDelegate delegate;
40 delegates->push_back(&delegate); 37 delegates->push_back(&delegate);
41 bool ret = true;
42 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = 38 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i =
43 delegates->rbegin(); i != delegates->rend(); ++i) { 39 delegates->rbegin(); i != delegates->rend(); ++i) {
44 if (!(*i)->RegisterJNI(env)) { 40 if (!(*i)->RegisterJNI(env))
45 ret = false; 41 return false;
46 break;
47 }
48 }
49
50 if (ret) {
51 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i =
52 delegates->rbegin(); i != delegates->rend(); ++i) {
53 if (!(*i)->Init()) {
54 ret = false;
55 break;
56 }
57 }
58 } 42 }
59 delegates->pop_back(); 43 delegates->pop_back();
60 return ret; 44 return true;
45 }
46
47 bool OnJNIOnLoadInit(std::vector<JNIOnLoadDelegate*>* delegates) {
48 BaseJNIOnLoadDelegate delegate;
49 delegates->push_back(&delegate);
50
51 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i =
52 delegates->rbegin(); i != delegates->rend(); ++i) {
53 if (!(*i)->Init())
54 return false;
55 }
56 delegates->pop_back();
57 return true;
61 } 58 }
62 59
63 } // namespace android 60 } // namespace android
64 } // namespace base 61 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698