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

Unified Diff: libadblockplus-android/src/org/adblockplus/libadblockplus/android/SingleInstanceEngineProvider.java

Issue 29678590: Issue 6307 - Introduce external engine created callback (Closed)
Patch Set: Created Jan. 24, 2018, 12:46 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/src/org/adblockplus/libadblockplus/android/SingleInstanceEngineProvider.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/SingleInstanceEngineProvider.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/SingleInstanceEngineProvider.java
index 66b346e49e6fe66ed73aa1a03f9b2e84517f228e..51900ee8c68d7325b3d9cf4a5695e47b17e02b89 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/SingleInstanceEngineProvider.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/SingleInstanceEngineProvider.java
@@ -23,6 +23,8 @@ import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.util.Log;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
@@ -42,8 +44,8 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
private AdblockEngine engine;
private CountDownLatch engineCreated;
private Long v8IsolateProviderPtr;
- private Runnable engineCreatedCallback;
- private Runnable engineDisposedCallback;
+ private List<Runnable> engineCreatedCallbacks = new LinkedList<Runnable>();
+ private List<Runnable> engineDisposedCallbacks = new LinkedList<Runnable>();
/*
Simple ARC management for AdblockEngine
@@ -89,18 +91,28 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
return this;
}
- public SingleInstanceEngineProvider setEngineCreatedCallback(Runnable callback)
+ public SingleInstanceEngineProvider addEngineCreatedCallback(Runnable callback)
{
- this.engineCreatedCallback = callback;
+ this.engineCreatedCallbacks.add(callback);
return this;
}
- public SingleInstanceEngineProvider setEngineDisposedCallback(Runnable callback)
+ public void removeEngineCreatedCallback(Runnable callback)
anton 2018/01/24 12:51:08 "remove.." methods are not used anywhere but could
sergei 2018/01/24 13:33:02 I would say if someone wants to remove or clear th
jens 2018/01/26 08:15:22 Even if Sergejs idea is also fine I would prefer t
anton 2018/01/26 08:22:58 Acknowledged.
{
- this.engineDisposedCallback = callback;
+ this.engineCreatedCallbacks.remove(callback);
+ }
+
+ public SingleInstanceEngineProvider addEngineDisposedCallback(Runnable callback)
+ {
+ this.engineDisposedCallbacks.add(callback);
return this;
}
+ public void removeEngineDisposedCallback(Runnable callback)
+ {
+ this.engineDisposedCallbacks.remove(callback);
+ }
+
private void createAdblock()
{
ConnectivityManager connectivityManager =
@@ -139,9 +151,9 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
Log.d(TAG, "AdblockHelper engine created");
// sometimes we need to init AdblockEngine instance, eg. set user settings
- if (engineCreatedCallback != null)
+ for (Runnable callback : engineCreatedCallbacks)
{
- engineCreatedCallback.run();
+ callback.run();
}
}
@@ -241,9 +253,9 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
// sometimes we need to deinit something after AdblockEngine instance disposed
// eg. release user settings
- if (engineDisposedCallback != null)
+ for (Runnable callback : engineDisposedCallbacks)
{
- engineDisposedCallback.run();
+ callback.run();
}
}

Powered by Google App Engine
This is Rietveld