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

Unified Diff: jni/JniWebRequest.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: Removed a Log.d Created Jan. 22, 2015, 6:56 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
« no previous file with comments | « jni/JniUpdateCheckDoneCallback.cpp ('k') | jni/Utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jni/JniWebRequest.cpp
diff --git a/jni/JniWebRequest.cpp b/jni/JniWebRequest.cpp
index a479301fcd31a8fceba2cccf4699c3ed108ef4a2..5c3d5faae4f4bf59efb850b1f55c2b06808fc1ba 100644
--- a/jni/JniWebRequest.cpp
+++ b/jni/JniWebRequest.cpp
@@ -42,28 +42,34 @@ AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, const Adb
{
JNIEnvAcquire env(GetJavaVM());
- jclass clazz = env->GetObjectClass(GetCallbackObject());
- jmethodID method = env->GetMethodID(clazz, "httpGET", "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse"));
+ jmethodID method = env->GetMethodID(
+ *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())),
+ "httpGET", "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse"));
AdblockPlus::ServerResponse sResponse;
sResponse.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE;
if (method)
{
- jobject arrayList = NewJniArrayList(*env);
+ JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env));
for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(), end = requestHeaders.end(); it != end; it++)
{
- JniAddObjectToList(*env, arrayList, NewTuple(*env, it->first, it->second));
+ JniLocalReference<jobject> tuple(*env, NewTuple(*env, it->first, it->second));
+ JniAddObjectToList(*env, *arrayList, *tuple);
}
- jobject response = env->CallObjectMethod(GetCallbackObject(), method, env->NewStringUTF(url.c_str()), arrayList);
+ JniLocalReference<jobject> response(*env, env->CallObjectMethod(
+ GetCallbackObject(),
+ method,
+ *JniLocalReference<jstring>(*env, env->NewStringUTF(url.c_str())),
+ *arrayList));
if (!env->ExceptionCheck())
{
- sResponse.status = JniGetLongField(*env, serverResponseClass->Get(), response, "status");
- sResponse.responseStatus = JniGetIntField(*env, serverResponseClass->Get(), response, "responseStatus");
- sResponse.responseText = JniGetStringField(*env, serverResponseClass->Get(), response, "response");
+ sResponse.status = JniGetLongField(*env, serverResponseClass->Get(), *response, "status");
+ sResponse.responseStatus = JniGetIntField(*env, serverResponseClass->Get(), *response, "responseStatus");
+ sResponse.responseText = JniGetStringField(*env, serverResponseClass->Get(), *response, "response");
// TODO: transform Headers
}
}
@@ -76,7 +82,11 @@ AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, const Adb
jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, const std::string& b) const
{
jmethodID factory = env->GetMethodID(tupleClass->Get(), "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
- return env->NewObject(tupleClass->Get(), factory, env->NewStringUTF(a.c_str()), env->NewStringUTF(b.c_str()));
+
+ JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str()));
+ JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str()));
+
+ return env->NewObject(tupleClass->Get(), factory, *strA, *strB);
}
static JNINativeMethod methods[] =
« no previous file with comments | « jni/JniUpdateCheckDoneCallback.cpp ('k') | jni/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld