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

Delta Between Two Patch Sets: lib/synchronizer.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Left Patch Set: Addressed Sebastian's initial feedback Created Feb. 21, 2017, 6:12 a.m.
Right Patch Set: Removed unused imports Created March 15, 2017, 3:11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/subscriptionClasses.js ('k') | test/.eslintrc.json » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Manages synchronization of filter subscriptions. 21 * @fileOverview Manages synchronization of filter subscriptions.
22 */ 22 */
23 23
24 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 24 const {Downloader, Downloadable,
25 Cu.import("resource://gre/modules/Services.jsm"); 25 MILLIS_IN_SECOND, MILLIS_IN_MINUTE,
26 26 MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader");
27 let {Downloader, Downloadable, 27 const {Filter} = require("filterClasses");
28 MILLIS_IN_SECOND, MILLIS_IN_MINUTE, 28 const {FilterStorage} = require("filterStorage");
29 MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); 29 const {FilterNotifier} = require("filterNotifier");
30 let {Filter, CommentFilter} = require("filterClasses"); 30 const {Prefs} = require("prefs");
31 let {FilterStorage} = require("filterStorage"); 31 const {Subscription, DownloadableSubscription} = require("subscriptionClasses");
32 let {FilterNotifier} = require("filterNotifier"); 32 const {Utils} = require("utils");
33 let {Prefs} = require("prefs"); 33
34 let {Subscription, DownloadableSubscription} = require("subscriptionClasses"); 34 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE;
35 let {Utils} = require("utils"); 35 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
36 36 const DEFAULT_EXPIRATION_INTERVAL = 5 * MILLIS_IN_DAY;
37 let INITIAL_DELAY = 1 * MILLIS_IN_MINUTE;
38 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
39 let DEFAULT_EXPIRATION_INTERVAL = 5 * MILLIS_IN_DAY;
40 37
41 /** 38 /**
42 * The object providing actual downloading functionality. 39 * The object providing actual downloading functionality.
43 * @type {Downloader} 40 * @type {Downloader}
44 */ 41 */
45 let downloader = null; 42 let downloader = null;
46 43
47 /** 44 /**
48 * This object is responsible for downloading filter subscriptions whenever 45 * This object is responsible for downloading filter subscriptions whenever
49 * necessary. 46 * necessary.
(...skipping 24 matching lines...) Expand all
74 * @param {string} url URL of the subscription 71 * @param {string} url URL of the subscription
75 * @return {boolean} 72 * @return {boolean}
76 */ 73 */
77 isExecuting(url) 74 isExecuting(url)
78 { 75 {
79 return downloader.isDownloading(url); 76 return downloader.isDownloading(url);
80 }, 77 },
81 78
82 /** 79 /**
83 * Starts the download of a subscription. 80 * Starts the download of a subscription.
84 * @param {DownloadableSubscription} subscription Subscription to be 81 * @param {DownloadableSubscription} subscription
85 * downloaded 82 * Subscription to be downloaded
86 * @param {boolean} manual true for a manually started download 83 * @param {boolean} manual
87 * (should not trigger fallback requests) 84 * true for a manually started download (should not trigger fallback
85 * requests)
88 */ 86 */
89 execute(subscription, manual) 87 execute(subscription, manual)
90 { 88 {
91 downloader.download(this._getDownloadable(subscription, manual)); 89 downloader.download(this._getDownloadable(subscription, manual));
92 }, 90 },
93 91
94 /** 92 /**
95 * Yields Downloadable instances for all subscriptions that can be downloaded. 93 * Yields Downloadable instances for all subscriptions that can be downloaded.
96 */ 94 */
97 *_getDownloadables() 95 *_getDownloadables()
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 { 301 {
304 subscription.errors++; 302 subscription.errors++;
305 303
306 if (redirectCallback && 304 if (redirectCallback &&
307 subscription.errors >= Prefs.subscriptions_fallbackerrors && 305 subscription.errors >= Prefs.subscriptions_fallbackerrors &&
308 /^https?:\/\//i.test(subscription.url)) 306 /^https?:\/\//i.test(subscription.url))
309 { 307 {
310 subscription.errors = 0; 308 subscription.errors = 0;
311 309
312 let fallbackURL = Prefs.subscriptions_fallbackurl; 310 let fallbackURL = Prefs.subscriptions_fallbackurl;
313 let {addonVersion} = require("info"); 311 const {addonVersion} = require("info");
314 fallbackURL = fallbackURL.replace(/%VERSION%/g, 312 fallbackURL = fallbackURL.replace(/%VERSION%/g,
315 encodeURIComponent(addonVersion)); 313 encodeURIComponent(addonVersion));
316 fallbackURL = fallbackURL.replace(/%SUBSCRIPTION%/g, 314 fallbackURL = fallbackURL.replace(/%SUBSCRIPTION%/g,
317 encodeURIComponent(subscription.url)); 315 encodeURIComponent(subscription.url));
318 fallbackURL = fallbackURL.replace(/%URL%/g, 316 fallbackURL = fallbackURL.replace(/%URL%/g,
319 encodeURIComponent(downloadURL)); 317 encodeURIComponent(downloadURL));
320 fallbackURL = fallbackURL.replace(/%ERROR%/g, 318 fallbackURL = fallbackURL.replace(/%ERROR%/g,
321 encodeURIComponent(error)); 319 encodeURIComponent(error));
322 fallbackURL = fallbackURL.replace(/%CHANNELSTATUS%/g, 320 fallbackURL = fallbackURL.replace(/%CHANNELSTATUS%/g,
323 encodeURIComponent(channelStatus)); 321 encodeURIComponent(channelStatus));
324 fallbackURL = fallbackURL.replace(/%RESPONSESTATUS%/g, 322 fallbackURL = fallbackURL.replace(/%RESPONSESTATUS%/g,
325 encodeURIComponent(responseStatus)); 323 encodeURIComponent(responseStatus));
326 324
327 let request = new XMLHttpRequest(); 325 let request = new XMLHttpRequest();
328 request.mozBackgroundRequest = true; 326 request.mozBackgroundRequest = true;
329 request.open("GET", fallbackURL); 327 request.open("GET", fallbackURL);
330 request.overrideMimeType("text/plain"); 328 request.overrideMimeType("text/plain");
331 request.channel.loadFlags = request.channel.loadFlags | 329 request.channel.loadFlags = request.channel.loadFlags |
332 request.channel.INHIBIT_CACHING | 330 request.channel.INHIBIT_CACHING |
333 request.channel.VALIDATE_ALWAYS; 331 request.channel.VALIDATE_ALWAYS;
334 request.addEventListener("load", ev => 332 request.addEventListener("load", ev =>
335 { 333 {
336 if (onShutdown.done) 334 if (onShutdown.done)
337 return; 335 return;
338 336
339 if (!(subscription.url in FilterStorage.knownSubscriptions)) 337 if (!(subscription.url in FilterStorage.knownSubscriptions))
340 return; 338 return;
341 339
342 let match = /^(\d+)(?:\s+(\S+))?$/.exec(request.responseText); 340 let match = /^(\d+)(?:\s+(\S+))?$/.exec(request.responseText);
343 if (match && match[1] == "301" && // Moved permanently 341 if (match && match[1] == "301" && // Moved permanently
Sebastian Noack 2017/02/21 09:19:32 Why so many spaces?
kzar 2017/02/21 10:37:02 Done.
344 match[2] && /^https?:\/\//i.test(match[2])) 342 match[2] && /^https?:\/\//i.test(match[2]))
343 {
345 redirectCallback(match[2]); 344 redirectCallback(match[2]);
346 else if (match && match[1] == "410") // Gone 345 }
346 else if (match && match[1] == "410") // Gone
347 { 347 {
348 let data = "[Adblock]\n" + 348 let data = "[Adblock]\n" +
349 subscription.filters.map((f) => f.text).join("\n"); 349 subscription.filters.map(f => f.text).join("\n");
Sebastian Noack 2017/02/21 09:19:32 The parentheses around the arrow function's argume
kzar 2017/02/21 10:37:02 Done.
350 redirectCallback("data:text/plain," + encodeURIComponent(data)); 350 redirectCallback("data:text/plain," + encodeURIComponent(data));
351 } 351 }
352 }, false); 352 }, false);
353 request.send(null); 353 request.send(null);
354 } 354 }
355 } 355 }
356 } 356 }
357 }; 357 };
358 Synchronizer.init(); 358 Synchronizer.init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld