Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android/jni/JniNotification.cpp

Issue 29354787: Issue 4442 - Cache class and ctors references in JNI_Load/UnLoad (Closed)
Patch Set: reverted to NewTuple Created Nov. 21, 2016, 8:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus.h>
19 #include "Utils.h" 18 #include "Utils.h"
20 #include "JniJsValue.h" 19 #include "JniNotification.h"
20
21 // precached in JNI_OnLoad and released in JNI_OnUnload
22 JniGlobalReference<jclass>* notificationEnumClass;
23
24 void JniNotification_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved)
25 {
26 notificationEnumClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG ("Notification$Type")));
27 }
28
29 void JniNotification_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved)
30 {
31 if (notificationEnumClass)
32 {
33 delete notificationEnumClass;
34 notificationEnumClass = NULL;
35 }
36 }
21 37
22 static AdblockPlus::Notification* GetNotificationPtr(jlong ptr) 38 static AdblockPlus::Notification* GetNotificationPtr(jlong ptr)
23 { 39 {
24 return JniLongToTypePtr<AdblockPlus::NotificationPtr>(ptr)->get(); 40 return JniLongToTypePtr<AdblockPlus::NotificationPtr>(ptr)->get();
25 } 41 }
26 42
27 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) 43 static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
28 { 44 {
29 AdblockPlus::NotificationType type; 45 AdblockPlus::NotificationType type;
30 try 46 try
(...skipping 13 matching lines...) Expand all
44 enumName = "INFORMATION"; 60 enumName = "INFORMATION";
45 break; 61 break;
46 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION: 62 case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION:
47 enumName = "QUESTION"; 63 enumName = "QUESTION";
48 break; 64 break;
49 default: 65 default:
50 enumName = "INVALID"; 66 enumName = "INVALID";
51 break; 67 break;
52 } 68 }
53 69
54 JniLocalReference<jclass> enumClass(
55 env,
56 env->FindClass(PKG("Notification$Type")));
57
58 jfieldID enumField = env->GetStaticFieldID( 70 jfieldID enumField = env->GetStaticFieldID(
59 *enumClass, 71 notificationEnumClass->Get(),
60 enumName, 72 enumName,
61 TYP("Notification$Type")); 73 TYP("Notification$Type"));
62 74
63 return env->GetStaticObjectField(*enumClass, enumField); 75 return env->GetStaticObjectField(notificationEnumClass->Get(), enumField);
64 } 76 }
65 77
66 static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr) 78 static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr)
67 { 79 {
68 try 80 try
69 { 81 {
70 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTexts().title.c_str()); 82 return env->NewStringUTF(GetNotificationPtr(ptr)->GetTexts().title.c_str());
71 } 83 }
72 CATCH_THROW_AND_RETURN(env, 0) 84 CATCH_THROW_AND_RETURN(env, 0)
73 } 85 }
(...skipping 23 matching lines...) Expand all
97 { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle }, 109 { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle },
98 { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetTyp e } 110 { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetTyp e }
99 }; 111 };
100 112
101 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notificati on_registerNatives( 113 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notificati on_registerNatives(
102 JNIEnv *env, jclass clazz) 114 JNIEnv *env, jclass clazz)
103 { 115 {
104 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 116 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
105 } 117 }
106 118
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniNotification.h ('k') | libadblockplus-android/jni/JniShowNotificationCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld