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: Don't catch exceptions from successCallback Created Oct. 10, 2016, 9:48 a.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 entry = JSON.parse(entry); 369 entry = JSON.parse(entry);
369 } 370 }
370 catch(err) 371 catch(err)
371 { 372 {
372 setTimeout(errorCallback(new Error("File is corrupted"))); 373 setTimeout(errorCallback(new Error("File is corrupted")));
374 return;
373 } 375 }
374 setTimeout(successCallback(entry)); 376 setTimeout(successCallback(entry));
Sebastian Noack 2016/10/10 14:58:06 So if there is an entry in localStorage but it isn
kzar 2016/10/11 07:22:41 Whoops you're right, sorry I should have spotted t
Oleksandr 2016/10/11 13:52:53 Done.
375 } 377 return;
376 else 378 }
377 { 379 // Now try to read from IndexedDB
378 localforage.getItem(key, function(err, value) 380 localforage.getItem(key, function(err, value)
379 { 381 {
380 if (err || !value) 382 if (err || !value)
Sebastian Noack 2016/10/10 14:58:06 The check for !value seems to be wrong. So if an e
Oleksandr 2016/10/11 13:52:13 I don't think this is generally supported. This is
Sebastian Noack 2016/10/11 17:15:15 Alright, I missed that the value is an object not
Oleksandr 2016/10/11 19:45:54 It does break things if we remove this check. In c
381 errorCallback(new Error("File doesn't exist")); 383 errorCallback(new Error("File doesn't exist"));
382 else 384 else
383 successCallback(value); 385 successCallback(value);
384 }); 386 });
385 }
386 } 387 }
387 388
388 function saveFile(file, data, callback) 389 function saveFile(file, data, callback)
389 { 390 {
390 var key = fileToKey(file); 391 var key = fileToKey(file);
391 var entry = { 392 var entry = {
392 lastModified: Date.now(), 393 lastModified: Date.now(),
393 content: data 394 content: data
394 }; 395 };
395 396
(...skipping 6160 matching lines...) Expand 10 before | Expand all | Expand 10 after
6556 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); 6557 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount));
6557 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); 6558 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&"));
6558 } 6559 }
6559 if ("setUninstallURL" in chrome.runtime) 6560 if ("setUninstallURL" in chrome.runtime)
6560 { 6561 {
6561 Prefs.untilLoaded.then(setUninstallURL); 6562 Prefs.untilLoaded.then(setUninstallURL);
6562 Prefs.on("notificationdata", setUninstallURL); 6563 Prefs.on("notificationdata", setUninstallURL);
6563 } 6564 }
6564 return exports; 6565 return exports;
6565 })(); 6566 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld