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

Side by Side Diff: libadblockplus-android/jni/Utils.cpp

Issue 29422558: Issue 5167 - Update to use libadblockplus revision dca8df9af1a7 (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « libadblockplus-android/jni/Utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 if (!value.get()) 169 return env->NewObject(clazz, ctor, JniPtrToLong(new T(std::forward<T>(value))) );
170 {
171 return 0;
172 }
173
174 return env->NewObject(clazz, ctor, JniPtrToLong(new T(value)));
175 } 170 }
176 171
177 template<typename T> 172 jobject NewJniFilter(JNIEnv* env, AdblockPlus::Filter&& filter)
178 static jobject NewJniObject(JNIEnv* env, const T& value, const char* javaClass)
179 { 173 {
180 JniLocalReference<jclass> clazz( env, env->FindClass(javaClass)); 174 return NewJniObject<AdblockPlus::Filter>(
181 jmethodID ctor = env->GetMethodID(*clazz, "<init>", "(J)V"); 175 env, std::move(filter), filterClass->Get(), filterCtor);
182 return NewJniObject(env, value, *clazz, ctor);
183 } 176 }
184 177
185 jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter) 178 jobject NewJniSubscription(JNIEnv* env, AdblockPlus::Subscription&& subscription )
186 { 179 {
187 return NewJniObject(env, filter, filterClass->Get(), filterCtor); 180 return NewJniObject<AdblockPlus::Subscription>(
181 env, std::move(subscription), subscriptionClass->Get(), subscriptionCtor);
188 } 182 }
189 183
190 jobject NewJniSubscription(JNIEnv* env, 184 jobject NewJniNotification(JNIEnv* env, AdblockPlus::Notification&& notification )
191 const AdblockPlus::SubscriptionPtr& subscription)
192 { 185 {
193 return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionC tor); 186 return NewJniObject<AdblockPlus::Notification>(
187 env, std::move(notification), notificationClass->Get(), notificationCtor);
194 } 188 }
195
196 jobject NewJniNotification(JNIEnv* env,
197 const AdblockPlus::NotificationPtr& notification)
198 {
199 return NewJniObject(env, notification, notificationClass->Get(), notificationC tor);
200 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/Utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld