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: Created Feb. 20, 2017, 10:02 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 /* globals URL, XMLHttpRequest */
19
20 "use strict"; 18 "use strict";
21 19
22 /** 20 /**
23 * @fileOverview Manages synchronization of filter subscriptions. 21 * @fileOverview Manages synchronization of filter subscriptions.
24 */ 22 */
25 23
26 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 24 const {Downloader, Downloadable,
27 Cu.import("resource://gre/modules/Services.jsm"); 25 MILLIS_IN_SECOND, MILLIS_IN_MINUTE,
28 26 MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader");
29 let {Downloader, Downloadable, 27 const {Filter} = require("filterClasses");
30 MILLIS_IN_SECOND, MILLIS_IN_MINUTE, 28 const {FilterStorage} = require("filterStorage");
31 MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); 29 const {FilterNotifier} = require("filterNotifier");
32 let {Filter, CommentFilter} = require("filterClasses"); 30 const {Prefs} = require("prefs");
33 let {FilterStorage} = require("filterStorage"); 31 const {Subscription, DownloadableSubscription} = require("subscriptionClasses");
34 let {FilterNotifier} = require("filterNotifier"); 32 const {Utils} = require("utils");
35 let {Prefs} = require("prefs"); 33
36 let {Subscription, DownloadableSubscription} = require("subscriptionClasses"); 34 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE;
37 let {Utils} = require("utils"); 35 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
38 36 const DEFAULT_EXPIRATION_INTERVAL = 5 * MILLIS_IN_DAY;
39 let INITIAL_DELAY = 1 * MILLIS_IN_MINUTE;
40 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
41 let DEFAULT_EXPIRATION_INTERVAL = 5 * MILLIS_IN_DAY;
42 37
43 /** 38 /**
44 * The object providing actual downloading functionality. 39 * The object providing actual downloading functionality.
45 * @type {Downloader} 40 * @type {Downloader}
46 */ 41 */
47 let downloader = null; 42 let downloader = null;
48 43
49 /** 44 /**
50 * This object is responsible for downloading filter subscriptions whenever 45 * This object is responsible for downloading filter subscriptions whenever
51 * necessary. 46 * necessary.
(...skipping 14 matching lines...) Expand all
66 }); 61 });
67 62
68 downloader.onExpirationChange = this._onExpirationChange.bind(this); 63 downloader.onExpirationChange = this._onExpirationChange.bind(this);
69 downloader.onDownloadStarted = this._onDownloadStarted.bind(this); 64 downloader.onDownloadStarted = this._onDownloadStarted.bind(this);
70 downloader.onDownloadSuccess = this._onDownloadSuccess.bind(this); 65 downloader.onDownloadSuccess = this._onDownloadSuccess.bind(this);
71 downloader.onDownloadError = this._onDownloadError.bind(this); 66 downloader.onDownloadError = this._onDownloadError.bind(this);
72 }, 67 },
73 68
74 /** 69 /**
75 * Checks whether a subscription is currently being downloaded. 70 * Checks whether a subscription is currently being downloaded.
76 * @param {String} url URL of the subscription 71 * @param {string} url URL of the subscription
77 * @return {Boolean} 72 * @return {boolean}
78 */ 73 */
79 isExecuting(url) 74 isExecuting(url)
80 { 75 {
81 return downloader.isDownloading(url); 76 return downloader.isDownloading(url);
82 }, 77 },
83 78
84 /** 79 /**
85 * Starts the download of a subscription. 80 * Starts the download of a subscription.
86 * @param {DownloadableSubscription} subscription Subscription to be 81 * @param {DownloadableSubscription} subscription
87 * downloaded 82 * Subscription to be downloaded
88 * @param {Boolean} manual true for a manually started download 83 * @param {boolean} manual
89 * (should not trigger fallback requests) 84 * true for a manually started download (should not trigger fallback
85 * requests)
90 */ 86 */
91 execute(subscription, manual) 87 execute(subscription, manual)
92 { 88 {
93 downloader.download(this._getDownloadable(subscription, manual)); 89 downloader.download(this._getDownloadable(subscription, manual));
94 }, 90 },
95 91
96 /** 92 /**
97 * Yields Downloadable instances for all subscriptions that can be downloaded. 93 * Yields Downloadable instances for all subscriptions that can be downloaded.
98 */ 94 */
99 *_getDownloadables() 95 *_getDownloadables()
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 { 301 {
306 subscription.errors++; 302 subscription.errors++;
307 303
308 if (redirectCallback && 304 if (redirectCallback &&
309 subscription.errors >= Prefs.subscriptions_fallbackerrors && 305 subscription.errors >= Prefs.subscriptions_fallbackerrors &&
310 /^https?:\/\//i.test(subscription.url)) 306 /^https?:\/\//i.test(subscription.url))
311 { 307 {
312 subscription.errors = 0; 308 subscription.errors = 0;
313 309
314 let fallbackURL = Prefs.subscriptions_fallbackurl; 310 let fallbackURL = Prefs.subscriptions_fallbackurl;
315 let {addonVersion} = require("info"); 311 const {addonVersion} = require("info");
316 fallbackURL = fallbackURL.replace(/%VERSION%/g, 312 fallbackURL = fallbackURL.replace(/%VERSION%/g,
317 encodeURIComponent(addonVersion)); 313 encodeURIComponent(addonVersion));
318 fallbackURL = fallbackURL.replace(/%SUBSCRIPTION%/g, 314 fallbackURL = fallbackURL.replace(/%SUBSCRIPTION%/g,
319 encodeURIComponent(subscription.url)); 315 encodeURIComponent(subscription.url));
320 fallbackURL = fallbackURL.replace(/%URL%/g, 316 fallbackURL = fallbackURL.replace(/%URL%/g,
321 encodeURIComponent(downloadURL)); 317 encodeURIComponent(downloadURL));
322 fallbackURL = fallbackURL.replace(/%ERROR%/g, 318 fallbackURL = fallbackURL.replace(/%ERROR%/g,
323 encodeURIComponent(error)); 319 encodeURIComponent(error));
324 fallbackURL = fallbackURL.replace(/%CHANNELSTATUS%/g, 320 fallbackURL = fallbackURL.replace(/%CHANNELSTATUS%/g,
325 encodeURIComponent(channelStatus)); 321 encodeURIComponent(channelStatus));
326 fallbackURL = fallbackURL.replace(/%RESPONSESTATUS%/g, 322 fallbackURL = fallbackURL.replace(/%RESPONSESTATUS%/g,
327 encodeURIComponent(responseStatus)); 323 encodeURIComponent(responseStatus));
328 324
329 let request = new XMLHttpRequest(); 325 let request = new XMLHttpRequest();
330 request.mozBackgroundRequest = true; 326 request.mozBackgroundRequest = true;
331 request.open("GET", fallbackURL); 327 request.open("GET", fallbackURL);
332 request.overrideMimeType("text/plain"); 328 request.overrideMimeType("text/plain");
333 request.channel.loadFlags = request.channel.loadFlags | 329 request.channel.loadFlags = request.channel.loadFlags |
334 request.channel.INHIBIT_CACHING | 330 request.channel.INHIBIT_CACHING |
335 request.channel.VALIDATE_ALWAYS; 331 request.channel.VALIDATE_ALWAYS;
336 request.addEventListener("load", ev => 332 request.addEventListener("load", ev =>
337 { 333 {
338 if (onShutdown.done) 334 if (onShutdown.done)
339 return; 335 return;
340 336
341 if (!(subscription.url in FilterStorage.knownSubscriptions)) 337 if (!(subscription.url in FilterStorage.knownSubscriptions))
342 return; 338 return;
343 339
344 let match = /^(\d+)(?:\s+(\S+))?$/.exec(request.responseText); 340 let match = /^(\d+)(?:\s+(\S+))?$/.exec(request.responseText);
345 if (match && match[1] == "301" && // Moved permanently 341 if (match && match[1] == "301" && // Moved permanently
346 match[2] && /^https?:\/\//i.test(match[2])) 342 match[2] && /^https?:\/\//i.test(match[2]))
343 {
347 redirectCallback(match[2]); 344 redirectCallback(match[2]);
348 else if (match && match[1] == "410") // Gone 345 }
346 else if (match && match[1] == "410") // Gone
349 { 347 {
350 let data = "[Adblock]\n" + 348 let data = "[Adblock]\n" +
351 subscription.filters.map((f) => f.text).join("\n"); 349 subscription.filters.map(f => f.text).join("\n");
352 redirectCallback("data:text/plain," + encodeURIComponent(data)); 350 redirectCallback("data:text/plain," + encodeURIComponent(data));
353 } 351 }
354 }, false); 352 }, false);
355 request.send(null); 353 request.send(null);
356 } 354 }
357 } 355 }
358 } 356 }
359 }; 357 };
360 Synchronizer.init(); 358 Synchronizer.init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld