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

Side by Side 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: rebase Created July 5, 2017, 1:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libadblockplus-android/src/org/adblockplus/libadblockplus/FilterEngine.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 private void initRequests() 196 private void initRequests()
197 { 197 {
198 androidWebRequest = new AndroidWebRequest(engine.elemhideEnabled, true); 198 androidWebRequest = new AndroidWebRequest(engine.elemhideEnabled, true);
199 engine.webRequest = androidWebRequest; 199 engine.webRequest = androidWebRequest;
200 200
201 if (urlToResourceIdMap != null) 201 if (urlToResourceIdMap != null)
202 { 202 {
203 AndroidWebRequestResourceWrapper wrapper = new AndroidWebRequestResource Wrapper( 203 AndroidWebRequestResourceWrapper wrapper = new AndroidWebRequestResource Wrapper(
204 context, engine.webRequest, urlToResourceIdMap, resourceStorage); 204 context, engine.webRequest, urlToResourceIdMap, resourceStorage);
205 wrapper.setListener(engine.resourceWrapperListener); 205 wrapper.setListener(new AndroidWebRequestResourceWrapper.Listener()
206 {
207 @Override
208 public void onIntercepted(String url, int resourceId)
209 {
210 Log.d(TAG, "Force subscription update for intercepted URL " + url);
211 if (engine.filterEngine != null)
212 {
213 engine.filterEngine.updateFiltersAsync(url);
214 }
215 }
216 });
206 217
207 engine.webRequest = wrapper; 218 engine.webRequest = wrapper;
208 } 219 }
209 } 220 }
210 221
211 private void initCallbacks() 222 private void initCallbacks()
212 { 223 {
213 if (engine.updateAvailableCallback != null) 224 if (engine.updateAvailableCallback != null)
214 { 225 {
215 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCal lback); 226 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCal lback);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 263
253 engine.filterEngine = new FilterEngine(engine.jsEngine, isAllowedConnectio nCallback); 264 engine.filterEngine = new FilterEngine(engine.jsEngine, isAllowedConnectio nCallback);
254 } 265 }
255 } 266 }
256 267
257 public static Builder builder(AppInfo appInfo, String basePath) 268 public static Builder builder(AppInfo appInfo, String basePath)
258 { 269 {
259 return new Builder(appInfo, basePath); 270 return new Builder(appInfo, basePath);
260 } 271 }
261 272
262 private final AndroidWebRequestResourceWrapper.Listener resourceWrapperListene r =
263 new AndroidWebRequestResourceWrapper.Listener()
264 {
265 private static final int UPDATE_DELAY_MS = 1 * 1000;
266
267 private final Handler handler = new Handler(Looper.getMainLooper());
268
269 private final Runnable forceUpdateRunnable = new Runnable()
270 {
271 public void run() {
272 // Filter Engine can be already disposed
273 if (filterEngine != null)
274 {
275 Log.d(TAG, "Force update subscriptions");
276 AdblockEngine.this.updateSubscriptions();
277 }
278 }
279 };
280
281 @Override
282 public void onIntercepted(String url, int resourceId)
283 {
284 // we need to force update subscriptions ASAP after preloaded one is retur ned
285 // but we should note that multiple interceptions (for main easylist and A A) and force update once only
286
287 // adding into main thread queue to avoid concurrency issues (start update while updating)
288 // as usually onIntercepted() is invoked in background thread
289 handler.removeCallbacks(forceUpdateRunnable);
290 handler.postDelayed(forceUpdateRunnable, UPDATE_DELAY_MS);
291
292 Log.d(TAG, "Scheduled force update in " + UPDATE_DELAY_MS);
293 }
294 };
295
296 public void dispose() 273 public void dispose()
297 { 274 {
298 Log.w(TAG, "Dispose"); 275 Log.w(TAG, "Dispose");
299 276
300 // engines first 277 // engines first
301 if (this.filterEngine != null) 278 if (this.filterEngine != null)
302 { 279 {
303 if (this.updateAvailableCallback != null) 280 if (this.updateAvailableCallback != null)
304 { 281 {
305 this.filterEngine.removeUpdateAvailableCallback(); 282 this.filterEngine.removeUpdateAvailableCallback();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 sub.addToList(); 465 sub.addToList();
489 } 466 }
490 finally 467 finally
491 { 468 {
492 sub.dispose(); 469 sub.dispose();
493 } 470 }
494 } 471 }
495 } 472 }
496 } 473 }
497 474
498 public void updateSubscriptions()
499 {
500 for (final Subscription s : this.filterEngine.getListedSubscriptions())
501 {
502 try
503 {
504 s.updateFilters();
505 }
506 finally
507 {
508 s.dispose();
509 }
510 }
511 }
512
513 public void setEnabled(final boolean enabled) 475 public void setEnabled(final boolean enabled)
514 { 476 {
515 this.enabled = enabled; 477 this.enabled = enabled;
516 } 478 }
517 479
518 public boolean isEnabled() 480 public boolean isEnabled()
519 { 481 {
520 return enabled; 482 return enabled;
521 } 483 }
522 484
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 public void setWhitelistedDomains(List<String> domains) 632 public void setWhitelistedDomains(List<String> domains)
671 { 633 {
672 this.whitelistedDomains = domains; 634 this.whitelistedDomains = domains;
673 } 635 }
674 636
675 public List<String> getWhitelistedDomains() 637 public List<String> getWhitelistedDomains()
676 { 638 {
677 return whitelistedDomains; 639 return whitelistedDomains;
678 } 640 }
679 } 641 }
OLDNEW
« 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