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

Delta Between Two Patch Sets: lib/adblockplus.js

Issue 29355962: Issue 4023 - Use localforage (IndexedDB) instead of localStorage (Closed)
Left Patch Set: Make sure we always return asynchronously from loadFile. Add try-catch block. Created Oct. 6, 2016, 11:26 p.m.
Right Patch Set: Don't call both successCallback and errorCallback Created Oct. 11, 2016, 1:50 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 | « background.html ('k') | qunit/index.html » ('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
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 var keyPrefix = "file:"; 353 var keyPrefix = "file:";
354 354
355 function fileToKey(file) 355 function fileToKey(file)
356 { 356 {
357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); 357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec);
358 } 358 }
359 359
360 function loadFile(file, successCallback, errorCallback) 360 function loadFile(file, successCallback, errorCallback)
361 { 361 {
362 var key = fileToKey(file); 362 var key = fileToKey(file);
363 // Make sure we do not have subscriptions in localStorage from older version s first
363 var entry = localStorage.getItem(key); 364 var entry = localStorage.getItem(key);
364 if (entry) 365 if (typeof entry == "string")
365 { 366 {
366 try 367 try
367 { 368 {
368 setTimeout(successCallback(JSON.parse(entry)), 0); 369 entry = JSON.parse(entry);
Sebastian Noack 2016/10/06 23:38:35 Not too important but you can call setTimout() wit
Oleksandr 2016/10/07 16:29:17 Done. But I think it wouldn't hurt catching an err
kzar 2016/10/07 17:00:00 Wouldn't this also catch an exception thrown by th
Oleksandr 2016/10/07 17:21:06 Yes, but I think that's expected, no?
369 } 370 }
370 catch(err) 371 catch(err)
371 { 372 {
372 setTimeout(errorCallback(new Error("File is corrupted")), 0); 373 setTimeout(errorCallback(new Error("File is corrupted")));
373 } 374 return;
374 } 375 }
375 else 376 setTimeout(successCallback(entry));
376 { 377 return;
377 localforage.getItem(key, function(err, value) 378 }
378 { 379 // Now try to read from IndexedDB
379 if (err || !value) 380 localforage.getItem(key, function(err, value)
380 errorCallback(new Error("File doesn't exist")); 381 {
381 else 382 if (err || !value)
382 successCallback(value); 383 errorCallback(new Error("File doesn't exist"));
383 }); 384 else
384 } 385 successCallback(value);
386 });
385 } 387 }
386 388
387 function saveFile(file, data, callback) 389 function saveFile(file, data, callback)
388 { 390 {
389 var key = fileToKey(file); 391 var key = fileToKey(file);
390 var entry = { 392 var entry = {
391 lastModified: Date.now(), 393 lastModified: Date.now(),
392 content: data 394 content: data
393 }; 395 };
394 396
(...skipping 6160 matching lines...) Expand 10 before | Expand all | Expand 10 after
6555 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); 6557 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount));
6556 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); 6558 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&"));
6557 } 6559 }
6558 if ("setUninstallURL" in chrome.runtime) 6560 if ("setUninstallURL" in chrome.runtime)
6559 { 6561 {
6560 Prefs.untilLoaded.then(setUninstallURL); 6562 Prefs.untilLoaded.then(setUninstallURL);
6561 Prefs.on("notificationdata", setUninstallURL); 6563 Prefs.on("notificationdata", setUninstallURL);
6562 } 6564 }
6563 return exports; 6565 return exports;
6564 })(); 6566 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld