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

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

Issue 29332926: Issue 3446 - Remove code migrating prefs and files to chrome.storage (Closed)
Patch Set: Created Dec. 21, 2015, 2:48 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 | « no previous file | lib/io.js » ('j') | no next file with comments »
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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 set: function(key, value, callback) 524 set: function(key, value, callback)
525 { 525 {
526 let items = {}; 526 let items = {};
527 items[key] = value; 527 items[key] = value;
528 chrome.storage.local.set(items, callback); 528 chrome.storage.local.set(items, callback);
529 }, 529 },
530 remove: function(key, callback) 530 remove: function(key, callback)
531 { 531 {
532 chrome.storage.local.remove(key, callback); 532 chrome.storage.local.remove(key, callback);
533 }, 533 },
534 onChanged: chrome.storage.onChanged, 534 onChanged: chrome.storage.onChanged
535
536 // Migrate localStorage to chrome.storage.local,
537 // ignoring unkown and invalid preferences.
538 migratePrefs: function(hooks)
539 {
540 var items = {};
541
542 for (let key in localStorage)
543 {
544 var item = hooks.map(key, localStorage[key]);
545 if (item)
546 items[item.key] = item.value;
547 }
548
549 chrome.storage.local.set(items, function() {
550 localStorage.clear();
551 hooks.done();
552 });
553 },
554
555 // Migrate FileSystem API to chrome.storage.local. For simplicity
556 // only patterns.ini is considered. Backups are left behind.
557 migrateFiles: function(callback)
558 {
559 if ("webkitRequestFileSystem" in window)
560 {
561 webkitRequestFileSystem(PERSISTENT, 0, function(fs)
562 {
563 fs.root.getFile("patterns.ini", {}, function(entry)
564 {
565 entry.getMetadata(function(metadata)
566 {
567 entry.file(function(file)
568 {
569 var reader = new FileReader();
570 reader.onloadend = function()
571 {
572 if (!reader.error)
573 {
574 chrome.storage.local.set(
575 {
576 "file:patterns.ini": {
577 content: reader.result.split(/[\r\n]+/),
578 lastModified: metadata.modificationTime.getTime()
579 }
580 },
581 function()
582 {
583 fs.root.createReader().readEntries(function(entries)
584 {
585 var emptyFunc = function() {};
586
587 for (var i = 0; i < entries.length; i++)
588 {
589 var entry = entries[i];
590 if (entry.isDirectory)
591 entry.removeRecursively(emptyFunc, emptyFunc);
592 else
593 entry.remove(emptyFunc, emptyFunc);
594 }
595 });
596
597 callback();
598 }
599 );
600 }
601 else
602 {
603 callback();
604 }
605 };
606 reader.readAsText(file);
607 }, callback);
608 }, callback);
609 }, callback);
610 }, callback);
611 }
612 else
613 {
614 callback();
615 }
616 }
617 }; 535 };
618 536
619 /* Options */ 537 /* Options */
620 538
621 ext.showOptions = function(callback) 539 ext.showOptions = function(callback)
622 { 540 {
623 chrome.windows.getLastFocused(function(win) 541 chrome.windows.getLastFocused(function(win)
624 { 542 {
625 var optionsUrl = chrome.extension.getURL("options.html"); 543 var optionsUrl = chrome.extension.getURL("options.html");
626 var queryInfo = {url: optionsUrl}; 544 var queryInfo = {url: optionsUrl};
(...skipping 17 matching lines...) Expand all
644 callback(new Page(tab)); 562 callback(new Page(tab));
645 } 563 }
646 else 564 else
647 { 565 {
648 ext.pages.open(optionsUrl, callback); 566 ext.pages.open(optionsUrl, callback);
649 } 567 }
650 }); 568 });
651 }); 569 });
652 }; 570 };
653 })(); 571 })();
OLDNEW
« no previous file with comments | « no previous file | lib/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld