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

Unified Diff: lib/adblockplus.js

Issue 29348698: NoIssue - Use localStorage for storing filters in current Windows Store version of ABP for Edge (Closed)
Patch Set: Fallback to chrome.storage.local to read initialization data Created July 27, 2016, 4:11 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 | « no previous file | manifest.json » ('j') | manifest.json » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/adblockplus.js
===================================================================
--- a/lib/adblockplus.js
+++ b/lib/adblockplus.js
@@ -360,27 +360,47 @@
function loadFile(file, successCallback, errorCallback)
{
var key = fileToKey(file);
- ext.storage.get([key], function(items)
- {
- var entry = items[key];
- if (entry)
- {
- successCallback(entry);
- }
- else
- {
- errorCallback(new Error("File doesn't exist"));
- }
- });
+ var fileDoesNotExistMessage = "File doesn't exist";
Sebastian Noack 2016/07/27 16:18:16 Any reason to put this text into a variable rather
kzar 2016/07/27 16:22:03 Nit: Don't see the purpose of this variable.
+ entry = localStorage.getItem(key);
Sebastian Noack 2016/07/27 16:18:16 Did you forget the var statement here?
kzar 2016/07/27 16:22:03 You've missed the `var` again.
+ if (entry)
+ successCallback(JSON.parse(entry));
kzar 2016/07/27 16:22:02 Nit: Mind adding the { } braces for the if clause
+ else
+ {
+ // Also check the chrome.storage.local
Sebastian Noack 2016/07/27 16:18:16 Just to clarify, so this is for when migrating fro
Oleksandr 2016/07/27 16:33:30 No, this is for the first run when there is no pat
Sebastian Noack 2016/07/27 16:45:43 Then I don't understand what this workaround does.
Oleksandr 2016/07/27 18:23:40 I misdiagnosed it, you are right. It is only neede
Sebastian Noack 2016/07/27 18:29:43 Well, using setTimeout() would be much simpler. Al
Sebastian Noack 2016/07/27 21:33:16 (Not quite) LGTM but since the code as-is already
+ // We may have a init data there
+ ext.storage.get([key], function(items)
+ {
+ var entry = items[key];
+ if (entry)
+ {
Sebastian Noack 2016/07/27 16:18:16 Nit: The inner braces can be omitted.
kzar 2016/07/27 16:22:02 Nit: Mind removing the braces for the if + else he
+ successCallback(entry);
+ }
+ else
+ {
+ errorCallback(new Error(fileDoesNotExistMessage));
+ }
+ });
+ }
}
-
function saveFile(file, data, callback)
{
- ext.storage.set(fileToKey(file),
- {
- content: data,
- lastModified: Date.now()
- }, callback);
+ try
+ {
+ localStorage.setItem(fileToKey(file), JSON.stringify({
+ content: data,
+ lastModified: Date.now()
+ }));
+ }
+ catch(error)
+ {
+ // QuotaExceededError can happen. Notify the user and ignore
+ var errorMessage = "Subscription storage is full. " +
+ "Please remove some subscriptions and try again.";
+ alert(errorMessage);
+ callback(new Error(errorMessage));
+ return;
+ }
+ callback();
}
exports.IO = {
resolveFilePath: function(path)
« no previous file with comments | « no previous file | manifest.json » ('j') | manifest.json » ('J')

Powered by Google App Engine
This is Rietveld