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

Delta Between Two Patch Sets: chrome/ext/background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Left Patch Set: Rebased Created March 3, 2015, 3:11 p.m.
Right Patch Set: Fixed typo in comment Created April 13, 2015, 10:30 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | lib/prefs.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 items[key] = value; 510 items[key] = value;
511 chrome.storage.local.set(items, callback); 511 chrome.storage.local.set(items, callback);
512 }, 512 },
513 remove: function(key, callback) 513 remove: function(key, callback)
514 { 514 {
515 chrome.storage.local.remove(key, callback); 515 chrome.storage.local.remove(key, callback);
516 }, 516 },
517 onChanged: chrome.storage.onChanged, 517 onChanged: chrome.storage.onChanged,
518 518
519 // Migrate localStorage to chrome.storage.local, 519 // Migrate localStorage to chrome.storage.local,
520 // ignoring unkown and inavlid preferences. 520 // ignoring unkown and invalid preferences.
521 migratePrefs: function(prefs) 521 migratePrefs: function(hooks)
522 { 522 {
523 var items = {}; 523 var items = {};
524 524
525 for (let key in localStorage) 525 for (let key in localStorage)
526 { 526 {
527 var value = localStorage[key]; 527 var item = hooks.map(key, localStorage[key]);
528 528 if (item)
529 if (key in prefs) 529 items[item.key] = item.value;
530 {
531 try
532 {
533 items["pref:" + key] = JSON.parse(value);
534 }
535 catch (e)
536 {
537 }
538 }
539 else if (key == "currentVersion")
540 {
541 items[key] = value;
542 }
543 } 530 }
Sebastian Noack 2015/03/12 23:35:29 Well, where doese code with a different implementa
544 531
545 chrome.storage.local.set(items, function() { 532 chrome.storage.local.set(items, function() {
546 localStorage.clear(); 533 localStorage.clear();
534 hooks.done();
547 }); 535 });
548 } 536 }
549 }; 537 };
550 538
551 /* Options */ 539 /* Options */
552 540
553 ext.showOptions = function(callback) 541 ext.showOptions = function(callback)
554 { 542 {
555 chrome.windows.getLastFocused(function(win) 543 chrome.windows.getLastFocused(function(win)
556 { 544 {
(...skipping 19 matching lines...) Expand all
576 callback(new Page(tab)); 564 callback(new Page(tab));
577 } 565 }
578 else 566 else
579 { 567 {
580 ext.pages.open(optionsUrl, callback); 568 ext.pages.open(optionsUrl, callback);
581 } 569 }
582 }); 570 });
583 }); 571 });
584 }; 572 };
585 })(); 573 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld