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: Fixed typo in variable name Created March 20, 2015, 3:36 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') | lib/prefs.js » ('j') | no next file with comments »
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,42 @@
/* 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(hooks)
+ {
+ var items = {};
+
+ for (let key in localStorage)
+ {
+ var item = hooks.map(key, localStorage[key]);
+ if (item)
+ items[item.key] = item.value;
+ }
+
+ chrome.storage.local.set(items, function() {
+ localStorage.clear();
+ hooks.done();
+ });
+ }
+ };
/* Options */
« no previous file with comments | « background.js ('k') | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld