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

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

Issue 952893003: Update from https://crrev.com/317530 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix gn for nacl 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_utils.h"
9 #include "base/android/library_loader/library_loader_hooks.h" 9 #include "base/android/library_loader/library_loader_hooks.h"
10 #include "base/bind.h"
10 11
11 namespace base { 12 namespace base {
12 namespace android { 13 namespace android {
13 14
14 namespace { 15 namespace {
15 16
16 // The JNIOnLoadDelegate implementation in base. 17 bool RegisterJNI(JNIEnv* env) {
17 class BaseJNIOnLoadDelegate : public JNIOnLoadDelegate {
18 public:
19 bool RegisterJNI(JNIEnv* env) override;
20 bool Init() override;
21 };
22
23 bool BaseJNIOnLoadDelegate::RegisterJNI(JNIEnv* env) {
24 return RegisterLibraryLoaderEntryHook(env); 18 return RegisterLibraryLoaderEntryHook(env);
25 } 19 }
26 20
27 bool BaseJNIOnLoadDelegate::Init() { 21 bool Init() {
22 JNIEnv* env = base::android::AttachCurrentThread();
23 base::android::InitReplacementClassLoader(env,
24 base::android::GetClassLoader(env));
28 return true; 25 return true;
29 } 26 }
30 27
31 } // namespace 28 } // namespace
32 29
33 30
34 bool OnJNIOnLoad(JavaVM* vm, 31 bool OnJNIOnLoadRegisterJNI(JavaVM* vm,
35 std::vector<JNIOnLoadDelegate*>* delegates) { 32 std::vector<RegisterCallback> callbacks) {
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 callbacks.push_back(base::Bind(&RegisterJNI));
40 delegates->push_back(&delegate); 37 for (std::vector<RegisterCallback>::reverse_iterator i =
41 bool ret = true; 38 callbacks.rbegin(); i != callbacks.rend(); ++i) {
42 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = 39 if (!i->Run(env))
43 delegates->rbegin(); i != delegates->rend(); ++i) { 40 return false;
44 if (!(*i)->RegisterJNI(env)) {
45 ret = false;
46 break;
47 }
48 } 41 }
42 return true;
43 }
49 44
50 if (ret) { 45 bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks) {
51 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = 46 callbacks.push_back(base::Bind(&Init));
52 delegates->rbegin(); i != delegates->rend(); ++i) { 47 for (std::vector<InitCallback>::reverse_iterator i =
53 if (!(*i)->Init()) { 48 callbacks.rbegin(); i != callbacks.rend(); ++i) {
54 ret = false; 49 if (!i->Run())
55 break; 50 return false;
56 }
57 }
58 } 51 }
59 delegates->pop_back(); 52 return true;
60 return ret;
61 } 53 }
62 54
63 } // namespace android 55 } // namespace android
64 } // namespace base 56 } // namespace base
OLDNEW
« no previous file with comments | « base/android/base_jni_onload.h ('k') | base/android/java/src/org/chromium/base/ResourceExtractor.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698