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: @sergz Created June 14, 2017, 2:57 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/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..2ac25851f62521c5d09cf3a11ce310f593283963 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java
@@ -202,7 +202,24 @@ 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");
anton 2017/06/15 05:51:53 previously we invoked updateSubscriptions 1 time f
sergei 2017/06/16 11:12:09 OK, but why error (Log.e)?
anton 2017/06/16 11:25:12 Yes, obviously not `.e`. My bad.
+ if (this.adblockEngine.filterEngine != null)
anton 2017/06/15 05:51:53 "{" required
sergei 2017/06/16 11:12:09 Done.
+ this.adblockEngine.filterEngine.updateFiltersAsync(url);
anton 2017/06/15 05:51:53 "}" required
sergei 2017/06/16 11:12:08 Done.
+ }
+ }.init(this.engine));
engine.webRequest = wrapper;
}
@@ -259,40 +276,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 +478,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;

Powered by Google App Engine
This is Rietveld