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

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

Issue 5768064935133184: Issue 2021 - Replaced FileSystem API with chrome.storage.local (Closed)
Patch Set: Rebased Created March 13, 2015, 10:32 a.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/filesystem/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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 for (let key in localStorage) 525 for (let key in localStorage)
526 { 526 {
527 var item = mapFunc(key, localStorage[key]); 527 var item = mapFunc(key, localStorage[key]);
528 if (item) 528 if (item)
529 items[item.key] = item.value; 529 items[item.key] = item.value;
530 } 530 }
531 531
532 chrome.storage.local.set(items, function() { 532 chrome.storage.local.set(items, function() {
533 localStorage.clear(); 533 localStorage.clear();
534 }); 534 });
535 },
536
537 // Migrate FileSystem API to chrome.storage.local. For simplicity
538 // only patterns.ini is considered. Backups are left behind.
539 migrateFiles: function(callback)
540 {
541 if ("webkitRequestFileSystem" in window)
542 {
543 webkitRequestFileSystem(PERSISTENT, 0, function(fs)
544 {
545 fs.root.getFile("patterns.ini", {}, function(entry)
546 {
547 entry.getMetadata(function(metadata)
548 {
549 entry.file(function(file)
550 {
551 var reader = new FileReader();
552 reader.onloadend = function()
553 {
554 if (!reader.error)
555 {
556 chrome.storage.local.set(
557 {
558 "file:patterns.ini": {
559 content: reader.result.split(/[\r\n]+/),
560 lastModified: metadata.modificationTime.getTime()
561 }
562 },
563 function()
564 {
565 fs.root.removeRecursively(callback, callback);
566 }
567 );
568 }
569 else
570 {
571 callback();
572 }
573 };
574 reader.readAsText(file);
575 }, callback);
576 }, callback);
577 }, callback);
578 }, callback);
579 }
580 else
581 {
582 callback();
583 }
535 } 584 }
536 }; 585 };
537 586
538 /* Options */ 587 /* Options */
539 588
540 ext.showOptions = function(callback) 589 ext.showOptions = function(callback)
541 { 590 {
542 chrome.windows.getLastFocused(function(win) 591 chrome.windows.getLastFocused(function(win)
543 { 592 {
544 var optionsUrl = chrome.extension.getURL("options.html"); 593 var optionsUrl = chrome.extension.getURL("options.html");
(...skipping 18 matching lines...) Expand all
563 callback(new Page(tab)); 612 callback(new Page(tab));
564 } 613 }
565 else 614 else
566 { 615 {
567 ext.pages.open(optionsUrl, callback); 616 ext.pages.open(optionsUrl, callback);
568 } 617 }
569 }); 618 });
570 }); 619 });
571 }; 620 };
572 })(); 621 })();
OLDNEW
« no previous file with comments | « no previous file | lib/filesystem/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld