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

Side by Side Diff: libadblockplus-android/jni/JniCallbacks.h

Issue 29354787: Issue 4442 - Cache class and ctors references in JNI_Load/UnLoad (Closed)
Patch Set: Created Sept. 23, 2016, 12:55 p.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 #ifndef JNICALLBACKS_H 18 #ifndef JNICALLBACKS_H
19 #define JNICALLBACKS_H 19 #define JNICALLBACKS_H
20 20
21 #include <AdblockPlus.h> 21 #include <AdblockPlus.h>
22 #include "Utils.h" 22 #include "Utils.h"
23 #include "JniJsValue.h" 23 #include "JniJsValue.h"
24 24
25 void JniCallbacks_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved);
26
27 void JniCallbacks_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved);
28
25 class JniCallbackBase 29 class JniCallbackBase
26 { 30 {
27 public: 31 public:
28 JniCallbackBase(JNIEnv* env, jobject callbackObject); 32 JniCallbackBase(JNIEnv* env, jobject callbackObject);
29 virtual ~JniCallbackBase(); 33 virtual ~JniCallbackBase();
30 void LogException(JNIEnv* env, jthrowable throwable) const; 34 void LogException(JNIEnv* env, jthrowable throwable) const;
31 void CheckAndLogJavaException(JNIEnv* env) const; 35 void CheckAndLogJavaException(JNIEnv* env) const;
32 36
33 JavaVM* GetJavaVM() const 37 JavaVM* GetJavaVM() const
34 { 38 {
35 return javaVM; 39 return javaVM;
36 } 40 }
37 41
38 jobject GetCallbackObject() const 42 jobject GetCallbackObject() const
39 { 43 {
40 return callbackObject->Get(); 44 return callbackObject->Get();
41 } 45 }
42 46
43 private: 47 private:
44 JavaVM* javaVM; 48 JavaVM* javaVM;
45 const JniGlobalReference<jobject>::Ptr callbackObject; 49 const JniGlobalReference<jobject>::Ptr callbackObject;
46 const JniGlobalReference<jclass>::Ptr exceptionLoggerClass;
47 }; 50 };
48 51
49 class JniEventCallback : public JniCallbackBase 52 class JniEventCallback : public JniCallbackBase
50 { 53 {
51 public: 54 public:
52 JniEventCallback(JNIEnv* env, jobject callbackObject); 55 JniEventCallback(JNIEnv* env, jobject callbackObject);
53 void Callback(AdblockPlus::JsValueList& params); 56 void Callback(AdblockPlus::JsValueList& params);
54 }; 57 };
55 58
56 class JniUpdateAvailableCallback : public JniCallbackBase 59 class JniUpdateAvailableCallback : public JniCallbackBase
57 { 60 {
58 public: 61 public:
59 JniUpdateAvailableCallback(JNIEnv* env, jobject callbackObject); 62 JniUpdateAvailableCallback(JNIEnv* env, jobject callbackObject);
60 void Callback(const std::string& arg); 63 void Callback(const std::string& arg);
61 }; 64 };
62 65
63 class JniUpdateCheckDoneCallback : public JniCallbackBase 66 class JniUpdateCheckDoneCallback : public JniCallbackBase
64 { 67 {
65 public: 68 public:
66 JniUpdateCheckDoneCallback(JNIEnv* env, jobject callbackObject); 69 JniUpdateCheckDoneCallback(JNIEnv* env, jobject callbackObject);
67 void Callback(const std::string& arg); 70 void Callback(const std::string& arg);
68 }; 71 };
69 72
70 class JniFilterChangeCallback : public JniCallbackBase 73 class JniFilterChangeCallback : public JniCallbackBase
71 { 74 {
72 public: 75 public:
73 JniFilterChangeCallback(JNIEnv* env, jobject callbackObject); 76 JniFilterChangeCallback(JNIEnv* env, jobject callbackObject);
74 void Callback(const std::string& arg, const AdblockPlus::JsValuePtr jsValue); 77 void Callback(const std::string& arg, const AdblockPlus::JsValuePtr jsValue);
75
76 private:
77 const JniGlobalReference<jclass>::Ptr jsValueClass;
78 }; 78 };
79 79
80 class JniLogSystemCallback : public JniCallbackBase, public AdblockPlus::LogSyst em 80 class JniLogSystemCallback : public JniCallbackBase, public AdblockPlus::LogSyst em
81 { 81 {
82 public: 82 public:
83 JniLogSystemCallback(JNIEnv* env, jobject callbackObject); 83 JniLogSystemCallback(JNIEnv* env, jobject callbackObject);
84 void operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source); 84 void operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source);
85
86 private:
87 const JniGlobalReference<jclass>::Ptr logLevelClass;
88 }; 85 };
89 86
90 class JniShowNotificationCallback : public JniCallbackBase 87 class JniShowNotificationCallback : public JniCallbackBase
91 { 88 {
92 public: 89 public:
93 JniShowNotificationCallback(JNIEnv* env, jobject callbackObject); 90 JniShowNotificationCallback(JNIEnv* env, jobject callbackObject);
94 void Callback(const AdblockPlus::NotificationPtr&); 91 void Callback(const AdblockPlus::NotificationPtr&);
95
96 private:
97 const JniGlobalReference<jclass>::Ptr notificationClass;
98 }; 92 };
99 93
100 class JniWebRequest : public JniCallbackBase, public AdblockPlus::WebRequest 94 class JniWebRequest : public JniCallbackBase, public AdblockPlus::WebRequest
101 { 95 {
102 public: 96 public:
103 JniWebRequest(JNIEnv* env, jobject callbackObject); 97 JniWebRequest(JNIEnv* env, jobject callbackObject);
104 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const; 98 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const;
105 99
106 private: 100 private:
107 jobject NewTuple(JNIEnv* env, const std::string& a, const std::string& b) cons t; 101 jobject NewHeaderEntry(JNIEnv* env, const std::string& a, const std::string& b ) const;
anton 2016/09/23 13:05:25 "NewTuple" is misleading in WebRequest context, "N
Felix Dahlke 2016/11/18 10:42:23 Pretty unrelated change though, hm? Given how many
anton 2016/11/21 08:26:38 Acknowledged. Fixed in patch set #2
108
109 const JniGlobalReference<jclass>::Ptr tupleClass;
110 const JniGlobalReference<jclass>::Ptr serverResponseClass;
111 }; 102 };
112 103
113 #endif /* JNICALLBACKS_H */ 104 #endif /* JNICALLBACKS_H */
OLDNEW
« no previous file with comments | « no previous file | libadblockplus-android/jni/JniCallbacks.cpp » ('j') | libadblockplus-android/jni/JniFilter.h » ('J')

Powered by Google App Engine
This is Rietveld