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

Unified Diff: adblock-android/jni/JniUpdater.cpp

Issue 29908555: Issue 7035 - Update libadblockplus dependency (Closed) Base URL: git@github.com:adblockplus/libadblockplus-android.git@d150f08d5d72de8938c7ebbdccd9b0c4e06b4070
Patch Set: Issue 7035 - Update libadblockplus dependency Created Oct. 15, 2018, 9:53 a.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: adblock-android/jni/JniUpdater.cpp
diff --git a/adblock-android/jni/JniUpdater.cpp b/adblock-android/jni/JniUpdater.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0e9a7150d64b1eaedeba02a3c6aca8f5534061c5
--- /dev/null
+++ b/adblock-android/jni/JniUpdater.cpp
@@ -0,0 +1,122 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <AdblockPlus.h>
+#include "Utils.h"
+#include "JniCallbacks.h"
+#include <thread>
+#include "JniPlatform.h"
+
+namespace
+{
+ AdblockPlus::Updater& GetUpdaterRef(jlong jniPlatformPtr)
+ {
+ return JniLongToTypePtr<JniPlatform>(jniPlatformPtr)->platform->GetUpdater();
+ }
+}
+
+static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz,
+ jlong ptr)
+{
+ AdblockPlus::Updater& engine = GetUpdaterRef(ptr);
+ try
+ {
+ engine.RemoveUpdateAvailableCallback();
+ }
+ CATCH_AND_THROW(env)
+}
+
+static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
+ jlong ptr, jlong callbackPtr)
+{
+ AdblockPlus::Updater& updater = GetUpdaterRef(ptr);
+ JniUpdateAvailableCallback* const callback =
+ JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr);
+
+ const AdblockPlus::Updater::UpdateAvailableCallback updateAvailableCallback =
+ std::bind(&JniUpdateAvailableCallback::Callback, callback,
+ std::placeholders::_1);
+ try
+ {
+ updater.SetUpdateAvailableCallback(updateAvailableCallback);
+ }
+ CATCH_AND_THROW(env)
+}
+
+static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jlong updaterPtr)
+{
+ AdblockPlus::Updater& updater = GetUpdaterRef(ptr);
+ JniUpdateCheckDoneCallback* callback =
+ JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
+
+ AdblockPlus::Updater::UpdateCheckDoneCallback
+ updateCheckDoneCallback = 0;
+
+ if (updaterPtr)
+ {
+ updateCheckDoneCallback =
+ std::bind(&JniUpdateCheckDoneCallback::Callback, callback,
+ std::placeholders::_1);
+ }
+
+ try
+ {
+ updater.ForceUpdateCheck(updateCheckDoneCallback);
+ }
+ CATCH_AND_THROW(env)
+}
+
+static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref)
+{
+ AdblockPlus::Updater& updater = GetUpdaterRef(ptr);
+
+ std::string pref = JniJavaToStdString(env, jPref);
+
+ try
+ {
+ return NewJniJsValue(env, updater.GetPref(pref));
+ }
+ CATCH_THROW_AND_RETURN(env, 0)
+}
+
+static void JNICALL JniSetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref, jlong jsValue)
+{
+ AdblockPlus::Updater& updater = GetUpdaterRef(ptr);
+
+ std::string pref = JniJavaToStdString(env, jPref);
+ const AdblockPlus::JsValue& value = JniGetJsValue(jsValue);
+
+ try
+ {
+ updater.SetPref(pref, value);
+ }
+ CATCH_AND_THROW(env)
+}
+
+static JNINativeMethod methods[] =
+{
+ { (char*)"setUpdateAvailableCallback", (char*)"(JJ)V", (void*)JniSetUpdateAvailableCallback },
+ { (char*)"removeUpdateAvailableCallback", (char*)"(J)V", (void*)JniRemoveUpdateAvailableCallback },
+ { (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck },
+ { (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniGetPref },
+ { (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }
+};
+
+extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Updater_registerNatives(JNIEnv *env, jclass clazz)
+{
+ env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
+}

Powered by Google App Engine
This is Rietveld