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: added 'clear..()' methods, updated README Created Jan. 26, 2018, 8:24 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
« no previous file with comments | « libadblockplus-android/build.gradle ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cbefd633f79ea7667f4476433bdeb385a550d5fe 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>();
diegocarloslima 2018/01/26 12:30:01 I would prefer the callbacks to be interfaces inst
/*
Simple ARC management for AdblockEngine
@@ -89,18 +91,38 @@ 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)
{
- this.engineDisposedCallback = callback;
+ this.engineCreatedCallbacks.remove(callback);
+ }
+
+ public void clearEngineCreatedCallbacks()
+ {
+ this.engineCreatedCallbacks.clear();
+ }
+
+ public SingleInstanceEngineProvider addEngineDisposedCallback(Runnable callback)
+ {
+ this.engineDisposedCallbacks.add(callback);
return this;
}
+ public void removeEngineDisposedCallback(Runnable callback)
+ {
+ this.engineDisposedCallbacks.remove(callback);
+ }
+
+ public void clearEngineDisposedCallbacks()
+ {
+ this.engineDisposedCallbacks.clear();
+ }
+
private void createAdblock()
{
ConnectivityManager connectivityManager =
@@ -139,9 +161,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 +263,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();
}
}
« no previous file with comments | « libadblockplus-android/build.gradle ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld