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

Delta Between Two Patch Sets: libadblockplus-android/jni/JniWebRequest.cpp

Issue 29354787: Issue 4442 - Cache class and ctors references in JNI_Load/UnLoad (Closed)
Left Patch Set: Created Sept. 23, 2016, 12:55 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « libadblockplus-android/jni/JniWebRequest.h ('k') | libadblockplus-android/jni/Utils.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 *JniLocalReference<jclass>(*env, 72 *JniLocalReference<jclass>(*env,
73 env->GetObjectClass(GetCallbackObject())), 73 env->GetObjectClass(GetCallbackObject())),
74 "httpGET", 74 "httpGET",
75 "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse")); 75 "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse"));
76 76
77 AdblockPlus::ServerResponse sResponse; 77 AdblockPlus::ServerResponse sResponse;
78 sResponse.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; 78 sResponse.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE;
79 79
80 if (method) 80 if (method)
81 { 81 {
82 JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env)); 82 JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env));
anton 2016/09/23 13:05:25 Consider using LinkedList instead of ArrayList - f
diegocarloslima 2016/11/04 11:34:19 Yeah, LinkedList are better for insertion while Ar
83 jmethodID addMethod = JniGetAddToListMethod(*env, *arrayList); 83 jmethodID addMethod = JniGetAddToListMethod(*env, *arrayList);
anton 2016/09/23 13:05:25 Now searching for the method once
84 84
85 for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(), 85 for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(),
86 end = requestHeaders.end(); it != end; it++) 86 end = requestHeaders.end(); it != end; it++)
87 { 87 {
88 JniLocalReference<jobject> headerEntry(*env, NewHeaderEntry(*env, it->firs t, it->second)); 88 JniLocalReference<jobject> headerEntry(*env, NewTuple(*env, it->first, it- >second));
89 JniAddObjectToList(*env, *arrayList, addMethod, *headerEntry); 89 JniAddObjectToList(*env, *arrayList, addMethod, *headerEntry);
90 } 90 }
91 91
92 JniLocalReference<jobject> response(*env, 92 JniLocalReference<jobject> response(*env,
93 env->CallObjectMethod(GetCallbackObject(), method, 93 env->CallObjectMethod(GetCallbackObject(), method,
94 *JniLocalReference<jstring>(*env, env->NewStringUTF(url.c_str())), 94 *JniLocalReference<jstring>(*env, env->NewStringUTF(url.c_str())),
95 *arrayList)); 95 *arrayList));
96 96
97 if (!env->ExceptionCheck()) 97 if (!env->ExceptionCheck())
98 { 98 {
(...skipping 30 matching lines...) Expand all
129 } 129 }
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 CheckAndLogJavaException(*env); 134 CheckAndLogJavaException(*env);
135 135
136 return sResponse; 136 return sResponse;
137 } 137 }
138 138
139 jobject JniWebRequest::NewHeaderEntry(JNIEnv* env, const std::string& a, 139 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a,
140 const std::string& b) const 140 const std::string& b) const
141 { 141 {
142 jmethodID factory = env->GetMethodID(headerEntryClass->Get(), "<init>", 142 jmethodID factory = env->GetMethodID(headerEntryClass->Get(), "<init>",
143 "(Ljava/lang/String;Ljava/lang/String;)V"); 143 "(Ljava/lang/String;Ljava/lang/String;)V");
144 144
145 JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str())); 145 JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str()));
146 JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str())); 146 JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str()));
147 147
148 return env->NewObject(headerEntryClass->Get(), factory, *strA, *strB); 148 return env->NewObject(headerEntryClass->Get(), factory, *strA, *strB);
149 } 149 }
150 150
151 static JNINativeMethod methods[] = 151 static JNINativeMethod methods[] =
152 { 152 {
153 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 153 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
154 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 154 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
155 }; 155 };
156 156
157 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz) 157 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz)
158 { 158 {
159 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 159 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
160 } 160 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld