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

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

Issue 29465639: Issue 5309 - Subscriptions update causes ANR (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: address comments@sergz Created June 16, 2017, 11:11 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/src/org/adblockplus/libadblockplus/FilterEngine.java ('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/AdblockEngine.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
index 3afec963c4a28cd2c762b6522536e2daad8c69f9..8a433df778c13ac951dd445cfaa5cc2bb83bc0fb 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
@@ -202,7 +202,26 @@ public final class AdblockEngine
{
AndroidWebRequestResourceWrapper wrapper = new AndroidWebRequestResourceWrapper(
context, engine.webRequest, urlToResourceIdMap, resourceStorage);
- wrapper.setListener(engine.resourceWrapperListener);
+ wrapper.setListener(new AndroidWebRequestResourceWrapper.Listener()
+ {
+ private AdblockEngine adblockEngine;
+
+ AndroidWebRequestResourceWrapper.Listener init(AdblockEngine adblockEngine)
+ {
+ this.adblockEngine = adblockEngine;
+ return this;
+ }
+
+ @Override
+ public void onIntercepted(String url, int resourceId)
+ {
+ Log.d(TAG, "Force subscription update for intercepted URL " + url);
+ if (this.adblockEngine.filterEngine != null)
+ {
+ this.adblockEngine.filterEngine.updateFiltersAsync(url);
+ }
+ }
+ }.init(this.engine));
engine.webRequest = wrapper;
}
@@ -259,40 +278,6 @@ public final class AdblockEngine
return new Builder(appInfo, basePath);
}
- private final AndroidWebRequestResourceWrapper.Listener resourceWrapperListener =
- new AndroidWebRequestResourceWrapper.Listener()
- {
- private static final int UPDATE_DELAY_MS = 1 * 1000;
-
- private final Handler handler = new Handler(Looper.getMainLooper());
-
- private final Runnable forceUpdateRunnable = new Runnable()
- {
- public void run() {
- // Filter Engine can be already disposed
- if (filterEngine != null)
- {
- Log.d(TAG, "Force update subscriptions");
- AdblockEngine.this.updateSubscriptions();
- }
- }
- };
-
- @Override
- public void onIntercepted(String url, int resourceId)
- {
- // we need to force update subscriptions ASAP after preloaded one is returned
- // but we should note that multiple interceptions (for main easylist and AA) and force update once only
-
- // adding into main thread queue to avoid concurrency issues (start update while updating)
- // as usually onIntercepted() is invoked in background thread
- handler.removeCallbacks(forceUpdateRunnable);
- handler.postDelayed(forceUpdateRunnable, UPDATE_DELAY_MS);
-
- Log.d(TAG, "Scheduled force update in " + UPDATE_DELAY_MS);
- }
- };
-
public void dispose()
{
Log.w(TAG, "Dispose");
@@ -495,21 +480,6 @@ public final class AdblockEngine
}
}
- public void updateSubscriptions()
- {
- for (final Subscription s : this.filterEngine.getListedSubscriptions())
- {
- try
- {
- s.updateFilters();
- }
- finally
- {
- s.dispose();
- }
- }
- }
-
public void setEnabled(final boolean enabled)
{
this.enabled = enabled;
« no previous file with comments | « libadblockplus-android/src/org/adblockplus/libadblockplus/FilterEngine.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld