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

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: fix chromecast 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/library_loader/library_loader_hooks.h" 8 #include "base/android/library_loader/library_loader_hooks.h"
9 #include "base/bind.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 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); 17 return RegisterLibraryLoaderEntryHook(env);
25 } 18 }
26 19
27 bool BaseJNIOnLoadDelegate::Init() {
28 return true;
29 }
30
31 } // namespace 20 } // namespace
32 21
33 22
34 bool OnJNIOnLoad(JavaVM* vm, 23 bool OnJNIOnLoadRegisterJNI(JavaVM* vm,
35 std::vector<JNIOnLoadDelegate*>* delegates) { 24 std::vector<RegisterCallback> callbacks) {
36 base::android::InitVM(vm); 25 base::android::InitVM(vm);
37 JNIEnv* env = base::android::AttachCurrentThread(); 26 JNIEnv* env = base::android::AttachCurrentThread();
38 27
39 BaseJNIOnLoadDelegate delegate; 28 callbacks.push_back(base::Bind(&RegisterJNI));
40 delegates->push_back(&delegate); 29 for (std::vector<RegisterCallback>::reverse_iterator i =
41 bool ret = true; 30 callbacks.rbegin(); i != callbacks.rend(); ++i) {
42 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = 31 if (!i->Run(env))
nyquist 2015/02/20 19:45:16 Is there a reason why we don't pop_back() before r
michaelbai 2015/02/20 19:59:20 Thanks, fixed it
michaelbai 2015/02/20 20:11:13 Actually, callbacks has been copied, I don't think
43 delegates->rbegin(); i != delegates->rend(); ++i) { 32 return false;
44 if (!(*i)->RegisterJNI(env)) {
45 ret = false;
46 break;
47 }
48 } 33 }
34 callbacks.pop_back();
35 return true;
36 }
49 37
50 if (ret) { 38 bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks) {
51 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = 39 for (std::vector<InitCallback>::reverse_iterator i =
52 delegates->rbegin(); i != delegates->rend(); ++i) { 40 callbacks.rbegin(); i != callbacks.rend(); ++i) {
53 if (!(*i)->Init()) { 41 if (!i->Run())
54 ret = false; 42 return false;
55 break;
56 }
57 }
58 } 43 }
59 delegates->pop_back(); 44 return true;
60 return ret;
61 } 45 }
62 46
63 } // namespace android 47 } // namespace android
64 } // namespace base 48 } // 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