Left: | ||
Right: |
OLD | NEW |
---|---|
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 24 matching lines...) Expand all Loading... | |
35 import org.adblockplus.libadblockplus.JsEngine; | 35 import org.adblockplus.libadblockplus.JsEngine; |
36 import org.adblockplus.libadblockplus.JsValue; | 36 import org.adblockplus.libadblockplus.JsValue; |
37 import org.adblockplus.libadblockplus.LogSystem; | 37 import org.adblockplus.libadblockplus.LogSystem; |
38 import org.adblockplus.libadblockplus.ShowNotificationCallback; | 38 import org.adblockplus.libadblockplus.ShowNotificationCallback; |
39 import org.adblockplus.libadblockplus.Subscription; | 39 import org.adblockplus.libadblockplus.Subscription; |
40 import org.adblockplus.libadblockplus.UpdateAvailableCallback; | 40 import org.adblockplus.libadblockplus.UpdateAvailableCallback; |
41 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; | 41 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; |
42 import org.adblockplus.libadblockplus.WebRequest; | 42 import org.adblockplus.libadblockplus.WebRequest; |
43 | 43 |
44 import android.content.Context; | 44 import android.content.Context; |
45 import android.content.pm.PackageInfo; | |
46 import android.content.pm.PackageManager.NameNotFoundException; | |
anton
2017/04/03 06:17:54
not related by the task, but desired clean-up
| |
47 import android.os.Build.VERSION; | 45 import android.os.Build.VERSION; |
48 import android.os.Handler; | 46 import android.os.Handler; |
49 import android.os.Looper; | 47 import android.os.Looper; |
50 import android.util.Log; | 48 import android.util.Log; |
51 | 49 |
52 public final class AdblockEngine | 50 public final class AdblockEngine |
53 { | 51 { |
54 // default base path to store subscription files in android app | 52 // default base path to store subscription files in android app |
55 public static final String BASE_PATH_DIRECTORY = "adblock"; | 53 public static final String BASE_PATH_DIRECTORY = "adblock"; |
56 | 54 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 } | 242 } |
245 | 243 |
246 public static Builder builder(AppInfo appInfo, String basePath) | 244 public static Builder builder(AppInfo appInfo, String basePath) |
247 { | 245 { |
248 return new Builder(appInfo, basePath); | 246 return new Builder(appInfo, basePath); |
249 } | 247 } |
250 | 248 |
251 private final AndroidWebRequestResourceWrapper.Listener resourceWrapperListene r = | 249 private final AndroidWebRequestResourceWrapper.Listener resourceWrapperListene r = |
252 new AndroidWebRequestResourceWrapper.Listener() | 250 new AndroidWebRequestResourceWrapper.Listener() |
253 { | 251 { |
254 private static final int UPDATE_DELAY_MS = 1 * 1000; | 252 private static final int REFRESH_DELAY_MS = 1 * 1000; |
anton
2017/04/03 06:17:54
I'm not sure that 'refresh' is better than 'update
diegocarloslima
2017/04/07 09:36:54
Well, I think that update is a better term in this
Felix Dahlke
2017/04/10 11:59:47
I'd also go for "update", since that's the termino
| |
255 | 253 |
256 private final Handler handler = new Handler(Looper.getMainLooper()); | 254 private final Handler handler = new Handler(Looper.getMainLooper()); |
257 | 255 |
258 private final Runnable forceUpdateRunnable = new Runnable() | 256 private final Runnable forceRefreshRunnable = new Runnable() |
259 { | 257 { |
260 public void run() { | 258 public void run() { |
261 // Filter Engine can be already disposed | 259 // Filter Engine can be already disposed |
262 if (filterEngine != null) | 260 if (filterEngine != null) |
263 { | 261 { |
264 Log.d(TAG, "Force update subscriptions"); | 262 Log.d(TAG, "Force refresh subscriptions"); |
265 List<Subscription> subscriptions = filterEngine.getListedSubscriptions (); | 263 AdblockEngine.this.refreshSubscriptions(); |
266 for (Subscription eachSubscription : subscriptions) | |
267 { | |
268 try | |
269 { | |
270 eachSubscription.updateFilters(); | |
271 } | |
272 finally | |
273 { | |
274 eachSubscription.dispose(); | |
275 } | |
276 } | |
277 } | 264 } |
278 } | 265 } |
279 }; | 266 }; |
280 | 267 |
281 @Override | 268 @Override |
282 public void onIntercepted(String url, int resourceId) | 269 public void onIntercepted(String url, int resourceId) |
283 { | 270 { |
284 // we need to force update subscriptions ASAP after preloaded one is retur ned | 271 // we need to force refresh subscriptions ASAP after preloaded one is retu rned |
285 // but we should note that multiple interceptions (for main easylist and A A) and force update once only | 272 // but we should note that multiple interceptions (for main easylist and A A) and force refresh once only |
286 | 273 |
287 // adding into main thread queue to avoid concurrency issues (start update while updating) | 274 // adding into main thread queue to avoid concurrency issues (start refres h while refreshing) |
288 // as usually onIntercepted() is invoked in background thread | 275 // as usually onIntercepted() is invoked in background thread |
289 handler.removeCallbacks(forceUpdateRunnable); | 276 handler.removeCallbacks(forceRefreshRunnable); |
290 handler.postDelayed(forceUpdateRunnable, UPDATE_DELAY_MS); | 277 handler.postDelayed(forceRefreshRunnable, REFRESH_DELAY_MS); |
291 | 278 |
292 Log.d(TAG, "Scheduled force update in " + UPDATE_DELAY_MS); | 279 Log.d(TAG, "Scheduled force refresh in " + REFRESH_DELAY_MS); |
293 } | 280 } |
294 }; | 281 }; |
295 | 282 |
296 public void dispose() | 283 public void dispose() |
297 { | 284 { |
298 Log.w(TAG, "Dispose"); | 285 Log.w(TAG, "Dispose"); |
299 | 286 |
300 // engines first | 287 // engines first |
301 if (this.filterEngine != null) | 288 if (this.filterEngine != null) |
302 { | 289 { |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 public void setWhitelistedDomains(List<String> domains) | 714 public void setWhitelistedDomains(List<String> domains) |
728 { | 715 { |
729 this.whitelistedDomains = domains; | 716 this.whitelistedDomains = domains; |
730 } | 717 } |
731 | 718 |
732 public List<String> getWhitelistedDomains() | 719 public List<String> getWhitelistedDomains() |
733 { | 720 { |
734 return whitelistedDomains; | 721 return whitelistedDomains; |
735 } | 722 } |
736 } | 723 } |
OLD | NEW |