 Chromium Code Reviews
 Chromium Code Reviews Issue 864563002:
  Separate JNI registration with initialization  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 864563002:
  Separate JNI registration with initialization  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "base/android/base_jni_onload.h" | |
| 6 | |
| 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" | |
| 10 | |
| 11 namespace base { | |
| 12 namespace android { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // The JNIOnLoadDelegate implementation in base. | |
| 17 class BaseJNIOnLoadDelegate : public JNIOnLoadDelegate { | |
| 18 public: | |
| 19 virtual bool RegisterJNI(JNIEnv* env) override; | |
| 20 virtual bool Init() override; | |
| 21 }; | |
| 22 | |
| 23 bool BaseJNIOnLoadDelegate::RegisterJNI(JNIEnv* env) { | |
| 
jam
2015/01/27 16:10:33
nit: it'd be easier to read if these two short met
 
michaelbai
2015/01/27 20:13:50
I were told this style is only acceptable in unit
 
jam
2015/01/28 21:48:49
I just noticed the wiki. this is the first time I
 | |
| 24 return RegisterLibraryLoaderEntryHook(env); | |
| 25 } | |
| 26 | |
| 27 bool BaseJNIOnLoadDelegate::Init() { | |
| 28 return true; | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 | |
| 34 bool OnJNIOnLoad(JavaVM* vm, | |
| 35 std::vector<JNIOnLoadDelegate*>* delegates) { | |
| 36 base::android::InitVM(vm); | |
| 37 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 38 | |
| 39 BaseJNIOnLoadDelegate delegate; | |
| 40 delegates->push_back(&delegate); | |
| 41 bool ret = true; | |
| 42 for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i = | |
| 43 delegates->rbegin(); i != delegates->rend(); ++i) { | |
| 44 if (!(*i)->RegisterJNI(env)) { | |
| 45 ret = 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 } | |
| 59 delegates->pop_back(); | |
| 60 return ret; | |
| 61 } | |
| 62 | |
| 63 } // namespace android | |
| 64 } // namespace base | |
| OLD | NEW |