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

Side by Side Diff: lib/adblockplus.js

Issue 29351586: Issue 4023 - Move storage of subscription lists to localStorage - adblockplusedgems (Closed)
Patch Set: Created Sept. 8, 2016, 7:31 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 | « background.html ('k') | lib/lz-string.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 require.scopes["io"] = (function() 350 require.scopes["io"] = (function()
351 { 351 {
352 var exports = {}; 352 var exports = {};
353 var keyPrefix = "file:"; 353 var keyPrefix = "file:";
354 354
355 function fileToKey(file) 355 function fileToKey(file)
356 { 356 {
357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); 357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec);
358 } 358 }
359 359
360 function loadFile(file, successCallback, errorCallback) 360 function loadFile(file)
361 { 361 {
362 var key = fileToKey(file); 362 return new Promise(function(resolve, reject)
363 ext.storage.get([key], function(items)
364 { 363 {
365 var entry = items[key]; 364 var key = fileToKey(file);
366 if (entry) 365 ext.storage.get([key], function(items)
367 { 366 {
368 successCallback(entry); 367 var entry = items[key];
369 } 368 if (!entry)
370 else 369 {
371 { 370 try
372 errorCallback(new Error("File doesn't exist")); 371 {
373 } 372 entry = JSON.parse(window.localStorage.getItem(key));
374 }); 373 }
374 catch (err)
375 {}
376 }
377 if (entry)
378 {
379 resolve(entry);
380 }
381 else
382 {
383 reject(new Error("File doesn't exist"));
384 }
385 });
386 }.bind(this));
375 } 387 }
376 388
377 function saveFile(file, data, callback) 389 function saveFile(file, data, callback)
378 { 390 {
379 ext.storage.set(fileToKey(file), 391 var entry = {};
392 var key = fileToKey(file);
393
394 if (typeof browser == "undefined")
380 { 395 {
381 content: data, 396 entry[key] = {
382 lastModified: Date.now() 397 lastModified: Date.now(),
383 }, callback); 398 content: data
399 };
400 ext.storage.set(entry, callback);
401 }
402 else
403 {
404 var processedData = LZString.compressToUTF16(JSON.stringify(data));
405 ext.storage.remove(key);
406 entry[key] = {
407 lastModified: Date.now(),
408 content: processedData,
409 compressed: true
410 };
411 window.localStorage.setItem(key, JSON.stringify(entry[key]));
412 setTimeout(callback, 0);
413 }
384 } 414 }
385 exports.IO = { 415 exports.IO = {
386 resolveFilePath: function(path) 416 resolveFilePath: function(path)
387 { 417 {
388 return new FakeFile(path); 418 return new FakeFile(path);
389 }, 419 },
390 readFromFile: function(file, listener, callback) 420 readFromFile: function(file, listener, callback)
391 { 421 {
392 function onLoaded(entry) 422 function onLoaded(entry)
393 { 423 {
394 for (var _loopIndex1 = 0; _loopIndex1 < entry.content.length; ++_loopInd ex1) 424 if ("content" in entry)
395 { 425 {
396 var line = entry.content[_loopIndex1]; 426 if ("compressed" in entry)
397 listener.process(line); 427 {
428 entry.content = JSON.parse(LZString.decompressFromUTF16(entry.conten t));
429 }
430 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15)
431 {
432 var line = entry.content[_loopIndex15];
433 listener.process(line);
434 }
398 } 435 }
399 listener.process(null);
400 callback(null); 436 callback(null);
401 } 437 }
402 loadFile(file, onLoaded, callback); 438 loadFile(file).then(onLoaded, callback);
403 }, 439 },
404 writeToFile: function(file, data, callback) 440 writeToFile: function(file, data, callback)
405 { 441 {
406 saveFile(file, data, callback); 442 saveFile(file, data, callback);
407 }, 443 },
408 copyFile: function(fromFile, toFile, callback) 444 copyFile: function(fromFile, toFile, callback)
409 { 445 {
410 function onLoaded(entry) 446 function onLoaded(entry)
411 { 447 {
412 saveFile(toFile, entry.content, callback); 448 saveFile(toFile, entry.content, callback);
413 } 449 }
414 loadFile(fromFile, onLoaded, callback); 450 loadFile(file).then(onLoaded, callback);
415 }, 451 },
416 renameFile: function(fromFile, newName, callback) 452 renameFile: function(fromFile, newName, callback)
417 { 453 {
418 function onLoaded() 454 function onLoaded()
419 { 455 {
420 ext.storage.remove(fileToKey(fromFile), function() 456 ext.storage.remove(fileToKey(fromFile), function()
421 { 457 {
422 ext.storage.set(keyPrefix + newName, entry, callback); 458 ext.storage.set(keyPrefix + newName, entry, callback);
423 }); 459 });
424 } 460 }
425 loadFile(fromFile, onLoaded, callback); 461 loadFile(file).then(onLoaded, callback);
426 }, 462 },
427 removeFile: function(file, callback) 463 removeFile: function(file, callback)
428 { 464 {
429 ext.storage.remove(fileToKey(file), callback); 465 ext.storage.remove(fileToKey(file), callback);
430 }, 466 },
431 statFile: function(file, callback) 467 statFile: function(file, callback)
432 { 468 {
433 function onLoaded(entry) 469 function onLoaded(entry)
434 { 470 {
435 callback(null, 471 callback(null,
436 { 472 {
437 exists: true, 473 exists: true,
438 lastModified: entry.lastModified 474 lastModified: entry.lastModified
439 }); 475 });
440 } 476 }
441 loadFile(file, onLoaded, callback); 477 loadFile(file).then(onLoaded, callback);
442 } 478 }
443 }; 479 };
444 return exports; 480 return exports;
445 })(); 481 })();
446 require.scopes["downloader"] = (function() 482 require.scopes["downloader"] = (function()
447 { 483 {
448 var exports = {}; 484 var exports = {};
449 var Utils = require("utils").Utils; 485 var Utils = require("utils").Utils;
450 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; 486 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000;
451 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; 487 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND;
(...skipping 6085 matching lines...) Expand 10 before | Expand all | Expand 10 after
6537 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); 6573 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount));
6538 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); 6574 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&"));
6539 } 6575 }
6540 if ("setUninstallURL" in chrome.runtime) 6576 if ("setUninstallURL" in chrome.runtime)
6541 { 6577 {
6542 Prefs.untilLoaded.then(setUninstallURL); 6578 Prefs.untilLoaded.then(setUninstallURL);
6543 Prefs.on("notificationdata", setUninstallURL); 6579 Prefs.on("notificationdata", setUninstallURL);
6544 } 6580 }
6545 return exports; 6581 return exports;
6546 })(); 6582 })();
OLDNEW
« no previous file with comments | « background.html ('k') | lib/lz-string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld