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

Side by Side Diff: mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java

Issue 29322610: Issue 2720 - [Adblocking settings] Add the other filter lists category (Closed)
Patch Set: Mostly naming Created July 28, 2015, 10:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
35 public class AddOnBridge 35 public class AddOnBridge
36 { 36 {
37 private static final String TAG = "AdblockBrowser.AddOnBridge"; 37 private static final String TAG = "AdblockBrowser.AddOnBridge";
38 private static final String REQUEST_NAME = "AdblockPlus:Api"; 38 private static final String REQUEST_NAME = "AdblockPlus:Api";
39 // Timeout for checking filter loading (in seconds) 39 // Timeout for checking filter loading (in seconds)
40 private static final int QUERY_GET_FILTERS_LOADED_TIMEOUT = 30; 40 private static final int QUERY_GET_FILTERS_LOADED_TIMEOUT = 30;
41 // How long to wait between retries (in milliseconds) 41 // How long to wait between retries (in milliseconds)
42 private static final int QUERY_GET_FILTERS_LOADED_DELAY = 500; 42 private static final int QUERY_GET_FILTERS_LOADED_DELAY = 500;
43 // Handler+HandlerThread for posting delayed re-tries without interfering with 43 // Handler+HandlerThread for posting delayed re-tries without interfering with
44 // other threads (e.g. the UI or Gecko thread) 44 // other threads (e.g. the UI or Gecko thread)
45 private static final HandlerThread HANDLER_THREAD; 45 private static final HandlerThread PRIVATE_HANDLER_THREAD;
46 private static final Handler HANDLER; 46 private static final Handler PRIVATE_HANDLER;
47 // Global handler, for e.g. UI tasks
48 private static final HandlerThread GLOBAL_HANDLER_THREAD;
49 private static final Handler GLOBAL_HANDLER;
47 50
48 static 51 static
49 { 52 {
50 HANDLER_THREAD = new HandlerThread("abp-bridge"); 53 PRIVATE_HANDLER_THREAD = new HandlerThread("abp-private-handler");
51 HANDLER_THREAD.setDaemon(true); 54 PRIVATE_HANDLER_THREAD.setDaemon(true);
52 HANDLER_THREAD.start(); 55 PRIVATE_HANDLER_THREAD.start();
53 HANDLER = new Handler(HANDLER_THREAD.getLooper()); 56 PRIVATE_HANDLER = new Handler(PRIVATE_HANDLER_THREAD.getLooper());
57
58 GLOBAL_HANDLER_THREAD = new HandlerThread("abp-global-handler");
59 GLOBAL_HANDLER_THREAD.setDaemon(true);
60 GLOBAL_HANDLER_THREAD.start();
61 GLOBAL_HANDLER = new Handler(GLOBAL_HANDLER_THREAD.getLooper());
62 }
63
64 public static void handlerPost(Runnable runnable)
65 {
66 GLOBAL_HANDLER.post(runnable);
67 }
68
69 public static void handlerPostDelayed(Runnable runnable, long delayMillis)
70 {
71 GLOBAL_HANDLER.postDelayed(runnable, delayMillis);
54 } 72 }
55 73
56 public static boolean getBooleanFromJsObject(final NativeJSObject obj, final S tring name, 74 public static boolean getBooleanFromJsObject(final NativeJSObject obj, final S tring name,
57 final boolean defaultValue) 75 final boolean defaultValue)
58 { 76 {
59 try 77 try
60 { 78 {
61 return obj.getBoolean(name); 79 return obj.getBoolean(name);
62 } 80 }
63 catch (final Exception e) 81 catch (final Exception e)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 parameters.put("url", url); 180 parameters.put("url", url);
163 callFunction(callback, "isSubscriptionListed", parameters); 181 callFunction(callback, "isSubscriptionListed", parameters);
164 } 182 }
165 183
166 public static void addSubscription(final AdblockPlusApiCallback callback, 184 public static void addSubscription(final AdblockPlusApiCallback callback,
167 final String url, final String title) 185 final String url, final String title)
168 { 186 {
169 Log.d(TAG, "addSubscription for " + url + " (" + title + ")"); 187 Log.d(TAG, "addSubscription for " + url + " (" + title + ")");
170 final Map<String, Object> parameters = new HashMap<String, Object>(); 188 final Map<String, Object> parameters = new HashMap<String, Object>();
171 parameters.put("url", url); 189 parameters.put("url", url);
172 parameters.put("title", title); 190 if (title != null)
191 {
192 parameters.put("title", title);
193 }
173 callFunction(callback, "addSubscription", parameters); 194 callFunction(callback, "addSubscription", parameters);
174 } 195 }
175 196
197 public static void queryActiveSubscriptions(final AdblockPlusApiCallback callb ack)
198 {
199 Log.d(TAG, "queryActiveSubscriptions");
200 final Map<String, Object> parameters = new HashMap<String, Object>();
201 callFunction(callback, "getActiveSubscriptions", parameters);
202 }
203
176 public static void removeSubscription(final AdblockPlusApiCallback callback, 204 public static void removeSubscription(final AdblockPlusApiCallback callback,
177 final String url) 205 final String url)
178 { 206 {
179 Log.d(TAG, "removeSubscription for " + url); 207 Log.d(TAG, "removeSubscription for " + url);
180 final Map<String, Object> parameters = new HashMap<String, Object>(); 208 final Map<String, Object> parameters = new HashMap<String, Object>();
181 parameters.put("url", url); 209 parameters.put("url", url);
182 callFunction(callback, "removeSubscription", parameters); 210 callFunction(callback, "removeSubscription", parameters);
183 } 211 }
184 212
185 public static void queryIsLocal(final AdblockPlusApiCallback callback, 213 public static void queryIsLocal(final AdblockPlusApiCallback callback,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 private void attemptRetry() 302 private void attemptRetry()
275 { 303 {
276 if (System.currentTimeMillis() - this.creationTime > (QUERY_GET_FILTERS_LO ADED_TIMEOUT * 1000)) 304 if (System.currentTimeMillis() - this.creationTime > (QUERY_GET_FILTERS_LO ADED_TIMEOUT * 1000))
277 { 305 {
278 this.invokeFailureCallback("getFiltersLoaded timeout"); 306 this.invokeFailureCallback("getFiltersLoaded timeout");
279 } 307 }
280 else 308 else
281 { 309 {
282 Log.d(TAG, "Retrying: " + this.value); 310 Log.d(TAG, "Retrying: " + this.value);
283 final ChainedRequest next = this.cloneForRetry(); 311 final ChainedRequest next = this.cloneForRetry();
284 HANDLER.postDelayed(new Runnable() 312 PRIVATE_HANDLER.postDelayed(new Runnable()
285 { 313 {
286 @Override 314 @Override
287 public void run() 315 public void run()
288 { 316 {
289 GeckoAppShell.sendRequestToGecko(next); 317 GeckoAppShell.sendRequestToGecko(next);
290 } 318 }
291 }, QUERY_GET_FILTERS_LOADED_DELAY); 319 }, QUERY_GET_FILTERS_LOADED_DELAY);
292 } 320 }
293 } 321 }
294 322
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 this.invokeSuccessCallback(jsObject); 357 this.invokeSuccessCallback(jsObject);
330 } 358 }
331 else 359 else
332 { 360 {
333 this.invokeFailureCallback(jsObject); 361 this.invokeFailureCallback(jsObject);
334 } 362 }
335 } 363 }
336 } 364 }
337 } 365 }
338 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld