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

Unified Diff: jni/JniCallbacks.h

Issue 6606493159784448: New JNI bindings (Closed)
Patch Set: Style review fixes Created March 28, 2014, 11 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jni/Android.mk ('k') | jni/JniCallbacks.cpp » ('j') | jni/JniJsEngine.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jni/JniCallbacks.h
diff --git a/jni/JniCallbacks.h b/jni/JniCallbacks.h
index 7ead721c7ca16a7a304547f51138ee8d811d4680..11165769d1c303cf6de6f4ba0689a40f58677252 100644
--- a/jni/JniCallbacks.h
+++ b/jni/JniCallbacks.h
@@ -15,68 +15,38 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef JNICALLBACKS_H_
-#define JNICALLBACKS_H_
+#ifndef JNICALLBACKS_H
Felix Dahlke 2014/03/28 11:27:18 We also typically use underscores for word separat
+#define JNICALLBACKS_H
#include <AdblockPlus.h>
#include "Utils.h"
#include "JniJsValue.h"
-namespace AdblockPlus
-{
-namespace Android
-{
-
class JniCallbackBase
{
public:
- JniCallbackBase(JNIEnv* env, jobject callbackObject)
- {
- env->GetJavaVM(&m_JavaVM);
- m_CallbackObject.reset(new JniGlobalReference<jobject>(env, callbackObject));
- m_ExceptionLoggerClass.reset(new JniGlobalReference<jclass>(env, env->FindClass(PKG("JniExceptionHandler"))));
- }
+ JniCallbackBase(JNIEnv* env, jobject callbackObject);
+ virtual ~JniCallbackBase();
+ void LogException(JNIEnv* env, jthrowable throwable) const;
+ void CheckAndLogJavaException(JNIEnv* env) const;
- virtual ~JniCallbackBase()
+ JavaVM* GetJavaVM() const
{
+ return javaVM;
}
- inline JavaVM* GetJavaVM() const
+ jobject GetCallbackObject() const
{
- return m_JavaVM;
- }
-
- inline jobject GetCallbackObject() const
- {
- return m_CallbackObject->get();
- }
-
- void LogException(JNIEnv* env, jthrowable throwable) const
- {
- jmethodID logMethod = env->GetStaticMethodID(m_ExceptionLoggerClass->get(), "logException", "(Ljava/lang/Throwable;)V");
- if (logMethod)
- {
- env->CallStaticVoidMethod(m_ExceptionLoggerClass->get(), logMethod, throwable);
- }
- }
-
- void CheckAndLogJavaException(JNIEnv* env) const
- {
- if (env->ExceptionCheck())
- {
- jthrowable throwable = env->ExceptionOccurred();
- env->ExceptionClear();
- LogException(env, throwable);
- }
+ return callbackObject->get();
}
private:
- JavaVM* m_JavaVM;
- JniGlobalReference<jobject>::PTR m_CallbackObject;
- JniGlobalReference<jclass>::PTR m_ExceptionLoggerClass;
+ JavaVM* javaVM;
+ JniGlobalReference<jobject>::Ptr callbackObject;
+ JniGlobalReference<jclass>::Ptr exceptionLoggerClass;
};
-class JniEventCallback: public JniCallbackBase
+class JniEventCallback : public JniCallbackBase
{
public:
JniEventCallback(JNIEnv* env, jobject callbackObject);
@@ -84,7 +54,7 @@ public:
void Callback(AdblockPlus::JsValueList& params);
};
-class JniUpdaterCallback: public JniCallbackBase
+class JniUpdaterCallback : public JniCallbackBase
{
public:
JniUpdaterCallback(JNIEnv* env, jobject callbackObject);
@@ -92,7 +62,7 @@ public:
void Callback(const std::string& arg);
};
-class JniFilterChangeCallback: public JniCallbackBase
+class JniFilterChangeCallback : public JniCallbackBase
{
public:
JniFilterChangeCallback(JNIEnv* env, jobject callbackObject);
@@ -100,30 +70,29 @@ public:
void Callback(const std::string& arg, const AdblockPlus::JsValuePtr jsValue);
};
-class JniLogSystemCallback: public JniCallbackBase, public AdblockPlus::LogSystem
+class JniLogSystemCallback : public JniCallbackBase, public AdblockPlus::LogSystem
{
public:
JniLogSystemCallback(JNIEnv* env, jobject callbackObject);
virtual ~JniLogSystemCallback();
void operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source);
+
private:
- JniGlobalReference<jclass>::PTR m_LogLevelClass;
+ JniGlobalReference<jclass>::Ptr logLevelClass;
};
-class JniWebRequest: public JniCallbackBase, public AdblockPlus::WebRequest
+class JniWebRequest : public JniCallbackBase, public AdblockPlus::WebRequest
{
public:
JniWebRequest(JNIEnv* env, jobject callbackObject);
virtual ~JniWebRequest();
AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const;
+
private:
jobject NewTuple(JNIEnv* env, const std::string& a, const std::string& b) const;
- JniGlobalReference<jclass>::PTR m_TupleClass;
- JniGlobalReference<jclass>::PTR m_ServerResponseClass;
+ JniGlobalReference<jclass>::Ptr tupleClass;
+ JniGlobalReference<jclass>::Ptr serverResponseClass;
};
-} // namespace Android
-} // namespace AdblockPlus
-
-#endif /* JNICALLBACKS_H_ */
+#endif /* JNICALLBACKS_H */
« no previous file with comments | « jni/Android.mk ('k') | jni/JniCallbacks.cpp » ('j') | jni/JniJsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld