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

Side by Side Diff: chrome/ext/background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Patch Set: Created Feb. 26, 2015, 12:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « background.js ('k') | lib/prefs.js » ('j') | lib/prefs.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 }); 470 });
471 471
472 // We have to ensure there is at least one listener for the onConnect event. 472 // We have to ensure there is at least one listener for the onConnect event.
473 // Otherwise we can't connect a port later, which we need to do in order to 473 // Otherwise we can't connect a port later, which we need to do in order to
474 // detect when the extension is reloaded, disabled or uninstalled. 474 // detect when the extension is reloaded, disabled or uninstalled.
475 chrome.runtime.onConnect.addListener(function() {}); 475 chrome.runtime.onConnect.addListener(function() {});
476 476
477 477
478 /* Storage */ 478 /* Storage */
479 479
480 ext.storage = localStorage; 480 ext.storage = {
481 get: function(keys, callback)
482 {
483 chrome.storage.local.get(keys, callback);
484 },
485 set: function(key, value, callback)
486 {
487 let items = {};
488 items[key] = value;
489 chrome.storage.local.set(items, callback);
490 },
491 remove: function(key, callback)
492 {
493 chrome.storage.local.remove(key, callback);
494 },
495 onChanged: chrome.storage.onChanged,
481 496
497 // Migrate localStorage to chrome.storage.local,
498 // ignoring unkown and inavlid preferences.
499 migratePrefs: function(prefs)
500 {
501 var items = {};
502
503 for (let key in localStorage)
504 {
505 var value = localStorage[key];
506
507 if (key in prefs)
508 {
509 try
510 {
511 items["pref:" + key] = JSON.parse(value);
kzar 2015/03/09 15:10:29 Nit: Shouldn't this make use of the const keyPrefi
Sebastian Noack 2015/03/09 15:21:37 It's not available here, and IMO not worth beeing
kzar 2015/03/09 15:24:28 Fair enough, yea I agree it doesn't really matter.
512 }
513 catch (e)
514 {
515 }
516 }
517 else if (key == "currentVersion")
518 {
519 items[key] = value;
520 }
521 }
522
523 chrome.storage.local.set(items, function() {
524 localStorage.clear();
525 });
526 }
527 };
482 528
483 /* Options */ 529 /* Options */
484 530
485 ext.showOptions = function(callback) 531 ext.showOptions = function(callback)
486 { 532 {
487 chrome.windows.getLastFocused(function(win) 533 chrome.windows.getLastFocused(function(win)
488 { 534 {
489 var optionsUrl = chrome.extension.getURL("options.html"); 535 var optionsUrl = chrome.extension.getURL("options.html");
490 var queryInfo = {url: optionsUrl}; 536 var queryInfo = {url: optionsUrl};
491 537
(...skipping 22 matching lines...) Expand all
514 callback(new Page(tab)); 560 callback(new Page(tab));
515 } 561 }
516 else 562 else
517 { 563 {
518 ext.pages.open(optionsUrl, callback); 564 ext.pages.open(optionsUrl, callback);
519 } 565 }
520 }); 566 });
521 }); 567 });
522 }; 568 };
523 })(); 569 })();
OLDNEW
« no previous file with comments | « background.js ('k') | lib/prefs.js » ('j') | lib/prefs.js » ('J')

Powered by Google App Engine
This is Rietveld