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 April 10, 2015, 6:54 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 { 526 {
527 var item = hooks.map(key, localStorage[key]); 527 var item = hooks.map(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 hooks.done(); 534 hooks.done();
535 }); 535 });
536 },
537
538 // Migrate FileSystem API to chrome.storage.local. For simplicity
539 // only patterns.ini is considered. Backups are left behind.
540 migrateFiles: function(callback)
541 {
542 if ("webkitRequestFileSystem" in window)
543 {
544 webkitRequestFileSystem(PERSISTENT, 0, function(fs)
545 {
546 fs.root.getFile("patterns.ini", {}, function(entry)
547 {
548 entry.getMetadata(function(metadata)
549 {
550 entry.file(function(file)
551 {
552 var reader = new FileReader();
553 reader.onloadend = function()
554 {
555 if (!reader.error)
556 {
557 chrome.storage.local.set(
558 {
559 "file:patterns.ini": {
560 content: reader.result.split(/[\r\n]+/),
561 lastModified: metadata.modificationTime.getTime()
562 }
563 },
564 function()
565 {
566 fs.root.removeRecursively(callback, callback);
567 }
568 );
569 }
570 else
571 {
572 callback();
573 }
574 };
575 reader.readAsText(file);
576 }, callback);
577 }, callback);
578 }, callback);
579 }, callback);
580 }
581 else
582 {
583 callback();
584 }
536 } 585 }
537 }; 586 };
538 587
539 /* Options */ 588 /* Options */
540 589
541 ext.showOptions = function(callback) 590 ext.showOptions = function(callback)
542 { 591 {
543 chrome.windows.getLastFocused(function(win) 592 chrome.windows.getLastFocused(function(win)
544 { 593 {
545 var optionsUrl = chrome.extension.getURL("options.html"); 594 var optionsUrl = chrome.extension.getURL("options.html");
(...skipping 18 matching lines...) Expand all
564 callback(new Page(tab)); 613 callback(new Page(tab));
565 } 614 }
566 else 615 else
567 { 616 {
568 ext.pages.open(optionsUrl, callback); 617 ext.pages.open(optionsUrl, callback);
569 } 618 }
570 }); 619 });
571 }); 620 });
572 }; 621 };
573 })(); 622 })();
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