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

Unified Diff: chrome/ext/background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Patch Set: Rebased Created March 3, 2015, 3: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 | « background.js ('k') | include.postload.js » ('j') | safari/ext/background.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
===================================================================
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -499,8 +499,54 @@
/* Storage */
- ext.storage = localStorage;
+ ext.storage = {
+ get: function(keys, callback)
+ {
+ chrome.storage.local.get(keys, callback);
+ },
+ set: function(key, value, callback)
+ {
+ let items = {};
+ items[key] = value;
+ chrome.storage.local.set(items, callback);
+ },
+ remove: function(key, callback)
+ {
+ chrome.storage.local.remove(key, callback);
+ },
+ onChanged: chrome.storage.onChanged,
+ // Migrate localStorage to chrome.storage.local,
+ // ignoring unkown and inavlid preferences.
+ migratePrefs: function(prefs)
+ {
+ var items = {};
+
+ for (let key in localStorage)
+ {
+ var value = localStorage[key];
+
+ if (key in prefs)
+ {
+ try
+ {
+ items["pref:" + key] = JSON.parse(value);
+ }
+ catch (e)
+ {
+ }
+ }
+ else if (key == "currentVersion")
+ {
+ items[key] = value;
+ }
+ }
Sebastian Noack 2015/03/12 23:35:29 Well, where doese code with a different implementa
+
+ chrome.storage.local.set(items, function() {
+ localStorage.clear();
+ });
+ }
+ };
/* Options */
« no previous file with comments | « background.js ('k') | include.postload.js » ('j') | safari/ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld