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: introduced custom listener interfaces Created Jan. 26, 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
« 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..4706684fa5327562adc1e54eed3cc42e742fbc5f 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;
@@ -34,6 +36,16 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
{
private static final String TAG = Utils.getTag(SingleInstanceEngineProvider.class);
+ public interface EngineCreatedListener
+ {
+ void onAdblockEngineCreated(AdblockEngine engine);
+ }
+
+ public interface EngineDisposedListener
+ {
+ void onAdblockEngineDisposed();
+ }
+
private Context context;
private String basePath;
private boolean developmentBuild;
@@ -42,8 +54,10 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
private AdblockEngine engine;
private CountDownLatch engineCreated;
private Long v8IsolateProviderPtr;
- private Runnable engineCreatedCallback;
- private Runnable engineDisposedCallback;
+ private List<EngineCreatedListener> engineCreatedListeners =
+ new LinkedList<EngineCreatedListener>();
+ private List<EngineDisposedListener> engineDisposedListeners =
+ new LinkedList<EngineDisposedListener>();
diegocarloslima 2018/01/26 13:04:28 Just one minor thing, the lists could be final
/*
Simple ARC management for AdblockEngine
@@ -89,18 +103,38 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
return this;
}
- public SingleInstanceEngineProvider setEngineCreatedCallback(Runnable callback)
+ public SingleInstanceEngineProvider addEngineCreatedListener(EngineCreatedListener listener)
{
- this.engineCreatedCallback = callback;
+ this.engineCreatedListeners.add(listener);
return this;
}
- public SingleInstanceEngineProvider setEngineDisposedCallback(Runnable callback)
+ public void removeEngineCreatedListener(EngineCreatedListener listener)
+ {
+ this.engineCreatedListeners.remove(listener);
+ }
+
+ public void clearEngineCreatedListeners()
{
- this.engineDisposedCallback = callback;
+ this.engineCreatedListeners.clear();
+ }
+
+ public SingleInstanceEngineProvider addEngineDisposedListener(EngineDisposedListener listener)
+ {
+ this.engineDisposedListeners.add(listener);
return this;
}
+ public void removeEngineDisposedListener(EngineDisposedListener listener)
+ {
+ this.engineDisposedListeners.remove(listener);
+ }
+
+ public void clearEngineDisposedListeners()
+ {
+ this.engineDisposedListeners.clear();
+ }
+
private void createAdblock()
{
ConnectivityManager connectivityManager =
@@ -139,9 +173,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 (EngineCreatedListener listener : engineCreatedListeners)
{
- engineCreatedCallback.run();
+ listener.onAdblockEngineCreated(engine);
}
}
@@ -241,9 +275,9 @@ public class SingleInstanceEngineProvider implements AdblockEngineProvider
// sometimes we need to deinit something after AdblockEngine instance disposed
// eg. release user settings
- if (engineDisposedCallback != null)
+ for (EngineDisposedListener listener : engineDisposedListeners)
{
- engineDisposedCallback.run();
+ listener.onAdblockEngineDisposed();
}
}
« 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