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

Delta Between Two Patch Sets: lib/crawler.js

Issue 29338153: Issue 3780 - wait for the loading of filters and only afterwards start to fetch pages (Closed)
Left Patch Set: make crawl_urls function Created March 15, 2016, 2:36 p.m.
Right Patch Set: remove onFiltersLoaded listener and fit 80 chars Created March 15, 2016, 2:57 p.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 | « no previous file | no next file » | 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 Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 /** 7 /**
8 * @module crawler 8 * @module crawler
9 */ 9 */
10 10
11 Cu.import("resource://gre/modules/Services.jsm"); 11 Cu.import("resource://gre/modules/Services.jsm");
12 Cu.import("resource://gre/modules/Task.jsm"); 12 Cu.import("resource://gre/modules/Task.jsm");
13 Cu.import("resource://gre/modules/Promise.jsm"); 13 Cu.import("resource://gre/modules/Promise.jsm");
14 14
15 function abprequire(module) 15 function abprequire(module)
16 { 16 {
17 let result = {}; 17 let result = {};
18 result.wrappedJSObject = result; 18 result.wrappedJSObject = result;
19 Services.obs.notifyObservers(result, "adblockplus-require", module); 19 Services.obs.notifyObservers(result, "adblockplus-require", module);
20 return result.exports; 20 return result.exports;
21 } 21 }
22 22
23 let {RequestNotifier} = abprequire("requestNotifier"); 23 let {RequestNotifier} = abprequire("requestNotifier");
24
25 let {FilterNotifier} = abprequire("filterNotifier"); 24 let {FilterNotifier} = abprequire("filterNotifier");
26 let {FilterStorage} = abprequire("filterStorage"); 25 let {FilterStorage} = abprequire("filterStorage");
27 26
28 /** 27 /**
29 * Creates a pool of tabs and allocates them to tasks on request. 28 * Creates a pool of tabs and allocates them to tasks on request.
30 * 29 *
31 * @param {tabbrowser} browser 30 * @param {tabbrowser} browser
32 * The tabbed browser where tabs should be created 31 * The tabbed browser where tabs should be created
33 * @param {int} maxtabs 32 * @param {int} maxtabs
34 * The maximum number of tabs to be allocated 33 * The maximum number of tabs to be allocated
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 * Maximum number of tabs to be opened 204 * Maximum number of tabs to be opened
206 * @param {String} targetURL 205 * @param {String} targetURL
207 * URL that should receive the results 206 * URL that should receive the results
208 * @param {Function} onDone 207 * @param {Function} onDone
209 * The callback which is called after finishing of crawling of all URLs. 208 * The callback which is called after finishing of crawling of all URLs.
210 */ 209 */
211 function run(window, urls, timeout, maxtabs, targetURL, onDone) 210 function run(window, urls, timeout, maxtabs, targetURL, onDone)
212 { 211 {
213 new Promise((resolve, reject) => 212 new Promise((resolve, reject) =>
214 { 213 {
215 if (FilterStorage.subscriptions.length > 0 && !FilterStorage._loading) 214 if (FilterStorage.subscriptions.length > 0)
216 { 215 {
217 resolve(); 216 resolve();
218 return; 217 return;
219 } 218 }
220 FilterNotifier.addListener((action, item, newValue, oldValue) => 219 let onFiltersLoaded = (action, item, newValue, oldValue) =>
221 { 220 {
222 if (action == "load") 221 if (action == "load")
223 { 222 {
223 FilterNotifier.removeListener(onFiltersLoaded);
224 resolve(); 224 resolve();
225 } 225 }
226 }); 226 };
227 }).then(() => crawl_urls(window, urls, timeout, maxtabs, targetURL, onDone)).c atch(reportException); 227 FilterNotifier.addListener(onFiltersLoaded);
228 }).then(() => crawl_urls(window, urls, timeout, maxtabs, targetURL, onDone))
229 .catch(reportException);
228 } 230 }
229 exports.run = run; 231 exports.run = run;
230 232
231 /** 233 /**
232 * Spawns a {Task} task to crawl each url from `urls` argument and calls 234 * Spawns a {Task} task to crawl each url from `urls` argument and calls
233 * `onDone` when all tasks are finished. 235 * `onDone` when all tasks are finished.
234 * @param {Window} window 236 * @param {Window} window
235 * The browser window we're operating in 237 * The browser window we're operating in
236 * @param {String[]} urls 238 * @param {String[]} urls
237 * URLs to be crawled 239 * URLs to be crawled
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 356
355 function reportException(e) 357 function reportException(e)
356 { 358 {
357 let stack = ""; 359 let stack = "";
358 if (e && typeof e == "object" && "stack" in e) 360 if (e && typeof e == "object" && "stack" in e)
359 stack = e.stack + "\n"; 361 stack = e.stack + "\n";
360 362
361 Cu.reportError(e); 363 Cu.reportError(e);
362 dump(e + "\n" + stack + "\n"); 364 dump(e + "\n" + stack + "\n");
363 } 365 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld