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

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

Issue 29422558: Issue 5167 - Update to use libadblockplus revision dca8df9af1a7 (Closed)
Left Patch Set: suggestions by Serge Created April 26, 2017, 10:22 a.m.
Right Patch Set: updated dependencies (..-binaries) Created May 10, 2017, 6:54 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/Utils.h ('k') | no next file » | 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 JNIEnvAcquire::~JNIEnvAcquire() 158 JNIEnvAcquire::~JNIEnvAcquire()
159 { 159 {
160 if (attachmentStatus == JNI_EDETACHED) 160 if (attachmentStatus == JNI_EDETACHED)
161 { 161 {
162 javaVM->DetachCurrentThread(); 162 javaVM->DetachCurrentThread();
163 } 163 }
164 } 164 }
165 165
166 template<typename T> 166 template<typename T>
167 static jobject NewJniObject(JNIEnv* env, const T& value, jclass clazz, jmethodID ctor) 167 static jobject NewJniObject(JNIEnv* env, T&& value, jclass clazz, jmethodID ctor )
168 { 168 {
169 return env->NewObject(clazz, ctor, JniPtrToLong(new T(value))); 169 return env->NewObject(clazz, ctor, JniPtrToLong(new T(std::forward<T>(value))) );
170 } 170 }
171 171
172 template<typename T> 172 jobject NewJniFilter(JNIEnv* env, AdblockPlus::Filter&& filter)
173 static jobject NewJniObject(JNIEnv* env, const T& value, const char* javaClass)
174 { 173 {
175 JniLocalReference<jclass> clazz( env, env->FindClass(javaClass)); 174 return NewJniObject<AdblockPlus::Filter>(
176 jmethodID ctor = env->GetMethodID(*clazz, "<init>", "(J)V"); 175 env, std::move(filter), filterClass->Get(), filterCtor);
177 return NewJniObject(env, value, *clazz, ctor);
178 } 176 }
179 177
180 jobject NewJniFilter(JNIEnv* env, const AdblockPlus::Filter& filter) 178 jobject NewJniSubscription(JNIEnv* env, AdblockPlus::Subscription&& subscription )
181 { 179 {
182 return NewJniObject(env, filter, filterClass->Get(), filterCtor); 180 return NewJniObject<AdblockPlus::Subscription>(
181 env, std::move(subscription), subscriptionClass->Get(), subscriptionCtor);
183 } 182 }
184 183
185 jobject NewJniSubscription(JNIEnv* env, const AdblockPlus::Subscription& subscri ption) 184 jobject NewJniNotification(JNIEnv* env, AdblockPlus::Notification&& notification )
186 { 185 {
187 return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionC tor); 186 return NewJniObject<AdblockPlus::Notification>(
187 env, std::move(notification), notificationClass->Get(), notificationCtor);
188 } 188 }
189
190 jobject NewJniNotification(JNIEnv* env, const AdblockPlus::Notification& notific ation)
191 {
192 return NewJniObject(env, notification, notificationClass->Get(), notificationC tor);
193 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld