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

Unified Diff: jni/JniLogSystem.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: Removed member variable prefixes Created Jan. 23, 2015, 1:16 p.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
Index: jni/JniLogSystem.cpp
diff --git a/jni/JniLogSystem.cpp b/jni/JniLogSystem.cpp
index 275b5ef85b7d0b56a91ba9a02434448db08de437..714f3189a291bf27cd756eefc4549c3dff3e69d1 100644
--- a/jni/JniLogSystem.cpp
+++ b/jni/JniLogSystem.cpp
@@ -36,12 +36,16 @@ JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject)
{
}
-void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source)
+void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel,
+ const std::string& message, const std::string& source)
{
JNIEnvAcquire env(GetJavaVM());
- jclass clazz = env->GetObjectClass(GetCallbackObject());
- jmethodID method = env->GetMethodID(clazz, "logCallback", "(" TYP("LogSystem$LogLevel") "Ljava/lang/String;Ljava/lang/String;)V");
+ jmethodID method = env->GetMethodID(
+ *JniLocalReference<jclass>(*env,
+ env->GetObjectClass(GetCallbackObject())),
+ "logCallback",
+ "(" TYP("LogSystem$LogLevel") "Ljava/lang/String;Ljava/lang/String;)V");
// TODO: Set log level from Java and handle it here (to reduce C++->Java calls)
@@ -51,34 +55,39 @@ void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel,
switch (logLevel)
{
- default:
- case AdblockPlus::LogSystem::LOG_LEVEL_TRACE:
- enumName = "TRACE";
- break;
- case AdblockPlus::LogSystem::LOG_LEVEL_LOG:
- enumName = "LOG";
- break;
- case AdblockPlus::LogSystem::LOG_LEVEL_INFO:
- enumName = "INFO";
- break;
- case AdblockPlus::LogSystem::LOG_LEVEL_WARN:
- enumName = "WARN";
- break;
- case AdblockPlus::LogSystem::LOG_LEVEL_ERROR:
- enumName = "ERROR";
- break;
+ default:
Felix Dahlke 2015/02/03 05:22:50 This was fine as it was actually - we don't indent
René Jeschke 2015/02/03 13:51:26 We do this in libadblockplus, the old JNI code her
Felix Dahlke 2015/02/04 04:11:50 Oops, you're right :P But still, unrelated change
René Jeschke 2015/02/04 12:02:47 Yep, you're right on this, too. Will up a 'Noissue
+ case AdblockPlus::LogSystem::LOG_LEVEL_TRACE:
+ enumName = "TRACE";
+ break;
+ case AdblockPlus::LogSystem::LOG_LEVEL_LOG:
+ enumName = "LOG";
+ break;
+ case AdblockPlus::LogSystem::LOG_LEVEL_INFO:
+ enumName = "INFO";
+ break;
+ case AdblockPlus::LogSystem::LOG_LEVEL_WARN:
+ enumName = "WARN";
+ break;
+ case AdblockPlus::LogSystem::LOG_LEVEL_ERROR:
+ enumName = "ERROR";
+ break;
}
jclass enumClass = logLevelClass->Get();
if (enumClass)
{
- jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("LogSystem$LogLevel"));
- jobject jLogLevel = env->GetStaticObjectField(enumClass, enumField);
+ jfieldID enumField = env->GetStaticFieldID(enumClass, enumName,
+ TYP("LogSystem$LogLevel"));
+ JniLocalReference<jobject> jLogLevel(*env,
+ env->GetStaticObjectField(enumClass, enumField));
- jstring jMessage = env->NewStringUTF(message.c_str());
- jstring jSource = env->NewStringUTF(source.c_str());
+ JniLocalReference<jstring> jMessage(*env,
+ env->NewStringUTF(message.c_str()));
+ JniLocalReference<jstring> jSource(*env,
+ env->NewStringUTF(source.c_str()));
- env->CallVoidMethod(GetCallbackObject(), method, jLogLevel, jMessage, jSource);
+ env->CallVoidMethod(GetCallbackObject(), method, *jLogLevel, *jMessage,
+ *jSource);
}
CheckAndLogJavaException(*env);

Powered by Google App Engine
This is Rietveld