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

Unified Diff: edge/ext/background.js

Issue 29367151: Issue 4721 - Use IndexedDB for storage in Edge (Closed)
Patch Set: Created Dec. 9, 2016, 6:38 a.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
« README.md ('K') | « README.md ('k') | edge/localforage.min.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: edge/ext/background.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/edge/ext/background.js
@@ -0,0 +1,79 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+(function()
+{
+ /* Storage redirection to localforage */
kzar 2016/12/12 14:17:50 If you're going to add a comment here you might as
Oleksandr 2016/12/13 06:21:19 Done. There is no bug report in Microsoft Edge iss
+
+ ext.storage = {
+ get: function(keys, callback)
+ {
+ var promisedValues = keys.map(function(key)
kzar 2016/12/12 14:17:50 Why not just use localforage.getItem directly? Als
Oleksandr 2016/12/13 06:21:18 localForage.getItem can't handle the array of keys
kzar 2016/12/13 10:24:04 I know. I don't think I worded my suggestion very
+ {
+ return localforage.getItem(key);
+ });
+ Promise.all(promisedValues).then(function(values)
+ {
+ if (!Array.isArray(keys))
kzar 2016/12/12 14:17:50 If it's possible that keys isn't an array then wou
Oleksandr 2016/12/13 06:21:19 Fair enough. Removed this check.
kzar 2016/12/13 10:24:04 Well are you sure that keys will always be an Arra
+ {
+ callback(values[0]);
+ return;
+ }
+ var items = {};
+ keys.forEach(function(key, idx)
kzar 2016/12/12 14:17:50 Would be clearer like this: for (let i = 0; i < k
Oleksandr 2016/12/13 06:21:19 Done. I thought functional way was less C++'y :)
kzar 2016/12/13 10:24:04 Thanks. (It's not functional to iteratively mutate
+ {
+ if (values[idx] != null)
+ items[key] = values[idx];
+ });
+ callback(items);
+ }).catch(function(err)
+ {
+ callback(null);
+ });
+ },
+ set: function(key, value, callback)
+ {
+ localforage.getItem(key).then(function(oldValue)
+ {
+ localforage.setItem(key, value, callback);
kzar 2016/12/12 14:17:50 Shouldn't we wait until setItem finishes before di
Oleksandr 2016/12/13 06:21:19 Done.
+
+ var changes = {};
+ var change = changes[key] = {};
+ change.oldValue = oldValue;
+ change.newValue = value;
+
+ ext.storage.onChanged._dispatch(changes);
+ }).catch(function(err)
+ {
+ localforage.setItem(key, value, callback);
kzar 2016/12/12 14:17:50 Seems ugly how this nearly identical logic is dupl
Oleksandr 2016/12/13 06:21:19 Done.
+
+ var changes = {};
+ var change = changes[key] = {};
+ change.oldValue = null;
+ change.newValue = value;
+
+ ext.storage.onChanged._dispatch(changes);
+ });
+ },
+ remove: function(key, callback)
+ {
+ localforage.removeItem(key);
kzar 2016/12/12 14:17:50 What about the callback?
Oleksandr 2016/12/13 06:21:19 Done.
+ },
+ onChanged: new ext._EventTarget()
+ };
+
kzar 2016/12/12 14:17:50 Nit: No need for this blank line.
Oleksandr 2016/12/13 06:21:19 Done.
+})();
« README.md ('K') | « README.md ('k') | edge/localforage.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld