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: Get back to async loadFile. Don't return a promise. Check localStorage. Created Oct. 5, 2016, 10:55 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 successCallback(JSON.parse(entry)); 367 try
Sebastian Noack 2016/10/06 12:07:36 Don't we have to respond asynchronously here (i.e.
Oleksandr 2016/10/06 23:28:13 Indeed, we should. Great catch! For reference, thi
Sebastian Noack 2016/10/06 23:38:35 Yes, that is what I remember, and why I brought it
367 } 368 {
368 else 369 entry = JSON.parse(entry);
369 { 370 }
370 entry = localforage.getItem(key, function(err, value) 371 catch(err)
Sebastian Noack 2016/10/06 12:07:36 It seems unnecessary to assign to "entry" here. It
Oleksandr 2016/10/06 23:28:13 Done.
371 { 372 {
372 if (err || !value) 373 setTimeout(errorCallback(new Error("File is corrupted")));
373 errorCallback(new Error("File doesn't exist")); 374 return;
374 else 375 }
375 successCallback(value); 376 setTimeout(successCallback(entry));
376 }); 377 return;
377 } 378 }
379 // Now try to read from IndexedDB
380 localforage.getItem(key, function(err, value)
381 {
382 if (err || !value)
383 errorCallback(new Error("File doesn't exist"));
384 else
385 successCallback(value);
386 });
378 } 387 }
379 388
380 function saveFile(file, data, callback) 389 function saveFile(file, data, callback)
381 { 390 {
382 var key = fileToKey(file); 391 var key = fileToKey(file);
383 var entry = { 392 var entry = {
384 lastModified: Date.now(), 393 lastModified: Date.now(),
385 content: data 394 content: data
386 }; 395 };
387 396
(...skipping 6160 matching lines...) Expand 10 before | Expand all | Expand 10 after
6548 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); 6557 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount));
6549 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); 6558 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&"));
6550 } 6559 }
6551 if ("setUninstallURL" in chrome.runtime) 6560 if ("setUninstallURL" in chrome.runtime)
6552 { 6561 {
6553 Prefs.untilLoaded.then(setUninstallURL); 6562 Prefs.untilLoaded.then(setUninstallURL);
6554 Prefs.on("notificationdata", setUninstallURL); 6563 Prefs.on("notificationdata", setUninstallURL);
6555 } 6564 }
6556 return exports; 6565 return exports;
6557 })(); 6566 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld