 Issue 29355962:
  Issue 4023 - Use localforage (IndexedDB) instead of localStorage  (Closed)
    
  
    Issue 29355962:
  Issue 4023 - Use localforage (IndexedDB) instead of localStorage  (Closed) 
  | Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 358 } | 
| 359 | 359 | 
| 360 function loadFile(file) | 360 function loadFile(file) | 
| 361 { | 361 { | 
| 362 return new Promise(function(resolve, reject) | 362 return new Promise(function(resolve, reject) | 
| 363 { | 363 { | 
| 364 var key = fileToKey(file); | 364 var key = fileToKey(file); | 
| 365 ext.storage.get([key], function(items) | 365 ext.storage.get([key], function(items) | 
| 366 { | 366 { | 
| 367 var entry = items[key]; | 367 var entry = items[key]; | 
| 368 if (!entry) | |
| 369 { | |
| 370 try | |
| 
Sebastian Noack
2016/10/05 21:27:32
I think this try-catch block should be removed now
 
Oleksandr
2016/10/05 21:49:13
Done.
 | |
| 371 { | |
| 372 entry = JSON.parse(window.localStorage.getItem(key)); | |
| 373 } | |
| 374 catch (err) | |
| 375 {} | |
| 376 } | |
| 377 if (entry) | 368 if (entry) | 
| 378 { | 369 { | 
| 379 resolve(entry); | 370 resolve(entry); | 
| 380 } | 371 } | 
| 381 else | 372 else | 
| 382 { | 373 { | 
| 383 reject(new Error("File doesn't exist")); | 374 try | 
| 375 { | |
| 376 entry = localforage.getItem(key, function(err, value) | |
| 377 { | |
| 378 if (err || !value) | |
| 379 reject(new Error("File doesn't exist")); | |
| 380 else | |
| 381 resolve(value); | |
| 382 }); | |
| 383 } | |
| 384 catch (err) | |
| 385 {} | |
| 384 } | 386 } | 
| 385 }); | 387 }); | 
| 386 }.bind(this)); | 388 }.bind(this)); | 
| 387 } | 389 } | 
| 388 function saveFile(file, data, callback) | 390 function saveFile(file, data, callback) | 
| 389 { | 391 { | 
| 390 var entry = {}; | |
| 391 var key = fileToKey(file); | 392 var key = fileToKey(file); | 
| 392 | 393 ext.storage.remove(key); | 
| 393 if (typeof browser == "undefined") | 394 localforage.setItem(key, | 
| 394 { | 395 { lastModified: Date.now(), content: data }, | 
| 395 entry[key] = { | 396 callback | 
| 396 lastModified: Date.now(), | 397 ); | 
| 397 content: data | |
| 398 }; | |
| 399 ext.storage.set(entry, callback); | |
| 400 } | |
| 401 else | |
| 402 { | |
| 403 var processedData = LZString.compressToUTF16(JSON.stringify(data)); | |
| 404 ext.storage.remove(key); | |
| 405 entry[key] = { | |
| 406 lastModified: Date.now(), | |
| 407 content: processedData, | |
| 408 compressed: true | |
| 409 }; | |
| 410 window.localStorage.setItem(key, JSON.stringify(entry[key])); | |
| 411 setTimeout(callback, 0); | |
| 412 } | |
| 413 callback(); | |
| 414 } | 398 } | 
| 415 exports.IO = { | 399 exports.IO = { | 
| 416 resolveFilePath: function(path) | 400 resolveFilePath: function(path) | 
| 417 { | 401 { | 
| 418 return new FakeFile(path); | 402 return new FakeFile(path); | 
| 419 }, | 403 }, | 
| 420 readFromFile: function(file, listener, callback) | 404 readFromFile: function(file, listener, callback) | 
| 421 { | 405 { | 
| 422 function onLoaded(entry) | 406 function onLoaded(entry) | 
| 423 { | 407 { | 
| 424 if ("content" in entry) | 408 if ("content" in entry) | 
| 425 { | 409 { | 
| 426 if (entry["compressed"]) | |
| 427 { | |
| 428 entry.content = JSON.parse(LZString.decompressFromUTF16(entry.conten t)); | |
| 429 } | |
| 430 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) | 410 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) | 
| 431 { | 411 { | 
| 432 var line = entry.content[_loopIndex15]; | 412 var line = entry.content[_loopIndex15]; | 
| 433 listener.process(line); | 413 listener.process(line); | 
| 434 } | 414 } | 
| 435 } | 415 } | 
| 436 callback(null); | 416 callback(null); | 
| 437 } | 417 } | 
| 438 loadFile(file).then(onLoaded, callback); | 418 loadFile(file).then(onLoaded, callback); | 
| 439 }, | 419 }, | 
| (...skipping 6136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6576 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6556 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 
| 6577 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 6557 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 
| 6578 } | 6558 } | 
| 6579 if ("setUninstallURL" in chrome.runtime) | 6559 if ("setUninstallURL" in chrome.runtime) | 
| 6580 { | 6560 { | 
| 6581 Prefs.untilLoaded.then(setUninstallURL); | 6561 Prefs.untilLoaded.then(setUninstallURL); | 
| 6582 Prefs.on("notificationdata", setUninstallURL); | 6562 Prefs.on("notificationdata", setUninstallURL); | 
| 6583 } | 6563 } | 
| 6584 return exports; | 6564 return exports; | 
| 6585 })(); | 6565 })(); | 
| OLD | NEW |