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

Unified Diff: lib/adblockplus.js

Issue 29355962: Issue 4023 - Use localforage (IndexedDB) instead of localStorage (Closed)
Patch Set: Patch set 1 - Address the comments Created Oct. 5, 2016, 1:28 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « background.html ('k') | qunit/index.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/adblockplus.js
===================================================================
--- a/lib/adblockplus.js
+++ b/lib/adblockplus.js
@@ -365,52 +365,37 @@
ext.storage.get([key], function(items)
{
var entry = items[key];
- if (!entry)
+ if (entry)
+ {
+ resolve(entry);
+ }
+ else
{
try
{
- entry = JSON.parse(window.localStorage.getItem(key));
+ entry = localforage.getItem(key, function(err, value)
+ {
+ if (err || !value)
+ reject(new Error("File doesn't exist"));
+ else
+ resolve(value);
+ });
}
catch (err)
{}
}
- if (entry)
- {
- resolve(entry);
- }
- else
- {
- reject(new Error("File doesn't exist"));
- }
});
}.bind(this));
}
function saveFile(file, data, callback)
{
- var entry = {};
- var key = fileToKey(file);
+ var entry = {
+ lastModified: Date.now(),
+ content: data
+ };
- if (typeof browser == "undefined")
- {
- entry[key] = {
- lastModified: Date.now(),
- content: data
- };
- ext.storage.set(entry, callback);
- }
- else
- {
- var processedData = LZString.compressToUTF16(JSON.stringify(data));
- ext.storage.remove(key);
- entry[key] = {
- lastModified: Date.now(),
- content: processedData,
- compressed: true
- };
- window.localStorage.setItem(key, JSON.stringify(entry[key]));
- setTimeout(callback, 0);
- }
- callback();
+ ext.storage.remove(fileToKey(file));
+ localforage.setItem(key, entry, callback);
kzar 2016/10/05 13:46:53 Did you test this? Isn't `key` undefined now?
kzar 2016/10/05 13:46:53 Why not just pass in `{lastModified: Date.now(), c
Oleksandr 2016/10/05 21:07:40 I am not sure this is prettier, but I don't have a
Sebastian Noack 2016/10/05 21:27:31 Also considering that we'd have to wrap this line
Sebastian Noack 2016/10/05 21:28:38 ...as it was, I meant.
Oleksandr 2016/10/05 21:49:12 Done.
}
exports.IO = {
resolveFilePath: function(path)
@@ -423,10 +408,6 @@
{
if ("content" in entry)
{
- if (entry["compressed"])
- {
- entry.content = JSON.parse(LZString.decompressFromUTF16(entry.content));
- }
for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loopIndex15)
{
var line = entry.content[_loopIndex15];
« no previous file with comments | « background.html ('k') | qunit/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld