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: Simplify the code. Fix the "undefined" bug. Created Oct. 5, 2016, 9:02 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,36 @@
ext.storage.get([key], function(items)
{
var entry = items[key];
- if (!entry)
+ if (entry)
+ {
+ resolve(entry);
+ }
+ else
{
try
Sebastian Noack 2016/10/05 21:27:32 I think this try-catch block should be removed now
Oleksandr 2016/10/05 21:49:13 Done.
{
- 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);
-
- 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(key);
+ localforage.setItem(key,
+ { lastModified: Date.now(), content: data },
+ callback
+ );
}
exports.IO = {
resolveFilePath: function(path)
@@ -423,10 +407,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