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

Unified Diff: libadblockplus-android/jni/JniFilterEngine.cpp

Issue 29536629: Issue 5556 - Update to use libadblockplus revision hg:566f64c8a2a8 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: Created Sept. 5, 2017, 12:59 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: libadblockplus-android/jni/JniFilterEngine.cpp
diff --git a/libadblockplus-android/jni/JniFilterEngine.cpp b/libadblockplus-android/jni/JniFilterEngine.cpp
index 3f6c0d4870391cabf213397131cf11c53a34153c..6d6d582c0f38e5162db51431710286084895e90f 100644
--- a/libadblockplus-android/jni/JniFilterEngine.cpp
+++ b/libadblockplus-android/jni/JniFilterEngine.cpp
@@ -19,7 +19,7 @@
#include "Utils.h"
#include "JniCallbacks.h"
#include <thread>
-#include "JniJsEngine.h"
+#include "JniPlatform.h"
static jobject SubscriptionsToArrayList(JNIEnv* env, std::vector<AdblockPlus::Subscription>&& subscriptions)
{
@@ -48,63 +48,12 @@ static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env,
namespace
{
- struct JniFilterEngine
- {
- AdblockPlus::ITimer* timer;
- AdblockPlus::FilterEnginePtr filterEngine;
- };
-
AdblockPlus::FilterEngine& GetFilterEngineRef(jlong ptr)
anton 2017/09/06 06:21:27 rename to `platformPtr`
sergei 2017/09/08 09:45:01 renamed to jniPlatformPtr
{
- return *JniLongToTypePtr<JniFilterEngine>(ptr)->filterEngine;
+ return JniLongToTypePtr<JniPlatform>(ptr)->platform->GetFilterEngine();
}
}
-static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jniJsEnginePtr, jobject jIsSubscriptionDownloadAllowedCallback)
-{
- try
- {
- auto jniJsEngine = JniLongToTypePtr<JniJsEngine>(jniJsEnginePtr);
- auto jsEngine = jniJsEngine->jsEngine;
- auto jniFilterEngine = new JniFilterEngine();
- jniFilterEngine->timer = jniJsEngine->timer;
-
- if (jIsSubscriptionDownloadAllowedCallback)
- {
- AdblockPlus::FilterEngine::CreationParameters creationParameters;
- auto callback = std::make_shared<JniIsAllowedConnectionTypeCallback>(env, jIsSubscriptionDownloadAllowedCallback);
-
- creationParameters.isSubscriptionDownloadAllowedCallback =
- [callback](const std::string* allowedConnectionTypeArg, const std::function<void(bool)>& doneCallback)
- {
- std::shared_ptr<std::string> allowedConnectionType;
- if (allowedConnectionTypeArg)
- {
- allowedConnectionType = std::make_shared<std::string>(*allowedConnectionTypeArg);
- }
- std::thread([callback, allowedConnectionType, doneCallback]
- {
- doneCallback(callback->Callback(allowedConnectionType.get()));
- }).detach();
- };
-
- jniFilterEngine->filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, creationParameters);
- }
- else
- {
- jniFilterEngine->filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
- }
-
- return JniPtrToLong(jniFilterEngine);
- }
- CATCH_THROW_AND_RETURN(env, 0)
-}
-
-static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
-{
- delete JniLongToTypePtr<JniFilterEngine>(ptr);
-}
-
static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr)
anton 2017/09/06 06:21:27 i'd suggest to rename all `ptr` to `platformPtr` i
sergei 2017/09/08 09:45:01 I'm not sure that there is a real necessity in it
anton 2017/09/08 10:19:18 i'd prefer it to be renamed as previously it was c
sergei 2017/09/08 12:25:30 I would like to wait for the third opinion here. I
diegocarloslima 2017/09/08 20:42:41 As I could see, the only place where the ptr had a
{
try
@@ -535,10 +484,10 @@ static jstring JNICALL JniGetAcceptableAdsSubscriptionURL(JNIEnv* env, jclass cl
static void JNICALL JniUpdateFiltersAsync(JNIEnv* env, jclass clazz, jlong ptr, jstring jSubscriptionUrl)
{
std::string subscriptionUrl = JniJavaToStdString(env, jSubscriptionUrl);
- auto jniFilterEngine = JniLongToTypePtr<JniFilterEngine>(ptr);
- jniFilterEngine->timer->SetTimer(std::chrono::milliseconds(0), [jniFilterEngine, subscriptionUrl]
+ auto jniPlatform = JniLongToTypePtr<JniPlatform>(ptr);
+ jniPlatform->scheduler([jniPlatform, subscriptionUrl]
{
- auto& filterEngine = *jniFilterEngine->filterEngine;
+ auto& filterEngine = jniPlatform->platform->GetFilterEngine();
for (auto& subscription : filterEngine.GetListedSubscriptions())
{
if (stringBeginsWith(subscriptionUrl, subscription.GetProperty("url").AsString()))
@@ -552,7 +501,6 @@ static void JNICALL JniUpdateFiltersAsync(JNIEnv* env, jclass clazz, jlong ptr,
static JNINativeMethod methods[] =
{
- { (char*)"ctor", (char*)"(J" TYP("IsAllowedConnectionCallback") ")J", (void*)JniCtor },
{ (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun },
{ (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)JniGetFilter },
{ (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListedFilters },
@@ -580,7 +528,6 @@ static JNINativeMethod methods[] =
{ (char*)"setAcceptableAdsEnabled", (char*)"(JZ)V", (void*)JniSetAcceptableAdsEnabled },
{ (char*)"isAcceptableAdsEnabled", (char*)"(J)Z", (void*)JniIsAcceptableAdsEnabled },
{ (char*)"getAcceptableAdsSubscriptionURL", (char*)"(J)Ljava/lang/String;", (void*)JniGetAcceptableAdsSubscriptionURL },
- { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
{ (char*)"updateFiltersAsync", (char*)"(JLjava/lang/String;)V", (void*)JniUpdateFiltersAsync }
};

Powered by Google App Engine
This is Rietveld