| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, successCallback, errorCallback) |
| 361 { | 361 { |
| 362 var key = fileToKey(file); | 362 var key = fileToKey(file); |
| 363 ext.storage.get([key], function(items) | 363 var fileDoesNotExistMessage = "File doesn't exist"; |
|
Sebastian Noack
2016/07/27 16:18:16
Any reason to put this text into a variable rather
kzar
2016/07/27 16:22:03
Nit: Don't see the purpose of this variable.
| |
| 364 entry = localStorage.getItem(key); | |
|
Sebastian Noack
2016/07/27 16:18:16
Did you forget the var statement here?
kzar
2016/07/27 16:22:03
You've missed the `var` again.
| |
| 365 if (entry) | |
| 366 successCallback(JSON.parse(entry)); | |
|
kzar
2016/07/27 16:22:02
Nit: Mind adding the { } braces for the if clause
| |
| 367 else | |
| 364 { | 368 { |
| 365 var entry = items[key]; | 369 // Also check the chrome.storage.local |
|
Sebastian Noack
2016/07/27 16:18:16
Just to clarify, so this is for when migrating fro
Oleksandr
2016/07/27 16:33:30
No, this is for the first run when there is no pat
Sebastian Noack
2016/07/27 16:45:43
Then I don't understand what this workaround does.
Oleksandr
2016/07/27 18:23:40
I misdiagnosed it, you are right. It is only neede
Sebastian Noack
2016/07/27 18:29:43
Well, using setTimeout() would be much simpler. Al
Sebastian Noack
2016/07/27 21:33:16
(Not quite) LGTM but since the code as-is already
| |
| 366 if (entry) | 370 // We may have a init data there |
| 371 ext.storage.get([key], function(items) | |
| 367 { | 372 { |
| 368 successCallback(entry); | 373 var entry = items[key]; |
| 369 } | 374 if (entry) |
| 370 else | 375 { |
|
Sebastian Noack
2016/07/27 16:18:16
Nit: The inner braces can be omitted.
kzar
2016/07/27 16:22:02
Nit: Mind removing the braces for the if + else he
| |
| 371 { | 376 successCallback(entry); |
| 372 errorCallback(new Error("File doesn't exist")); | 377 } |
| 373 } | 378 else |
| 374 }); | 379 { |
| 380 errorCallback(new Error(fileDoesNotExistMessage)); | |
| 381 } | |
| 382 }); | |
| 383 } | |
| 375 } | 384 } |
| 376 | |
| 377 function saveFile(file, data, callback) | 385 function saveFile(file, data, callback) |
| 378 { | 386 { |
| 379 ext.storage.set(fileToKey(file), | 387 try |
| 380 { | 388 { |
| 381 content: data, | 389 localStorage.setItem(fileToKey(file), JSON.stringify({ |
| 382 lastModified: Date.now() | 390 content: data, |
| 383 }, callback); | 391 lastModified: Date.now() |
| 392 })); | |
| 393 } | |
| 394 catch(error) | |
| 395 { | |
| 396 // QuotaExceededError can happen. Notify the user and ignore | |
| 397 var errorMessage = "Subscription storage is full. " + | |
| 398 "Please remove some subscriptions and try again."; | |
| 399 alert(errorMessage); | |
| 400 callback(new Error(errorMessage)); | |
| 401 return; | |
| 402 } | |
| 403 callback(); | |
| 384 } | 404 } |
| 385 exports.IO = { | 405 exports.IO = { |
| 386 resolveFilePath: function(path) | 406 resolveFilePath: function(path) |
| 387 { | 407 { |
| 388 return new FakeFile(path); | 408 return new FakeFile(path); |
| 389 }, | 409 }, |
| 390 readFromFile: function(file, listener, callback) | 410 readFromFile: function(file, listener, callback) |
| 391 { | 411 { |
| 392 function onLoaded(entry) | 412 function onLoaded(entry) |
| 393 { | 413 { |
| (...skipping 6143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6537 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6557 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
| 6538 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 6558 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); |
| 6539 } | 6559 } |
| 6540 if ("setUninstallURL" in chrome.runtime) | 6560 if ("setUninstallURL" in chrome.runtime) |
| 6541 { | 6561 { |
| 6542 Prefs.untilLoaded.then(setUninstallURL); | 6562 Prefs.untilLoaded.then(setUninstallURL); |
| 6543 Prefs.on("notificationdata", setUninstallURL); | 6563 Prefs.on("notificationdata", setUninstallURL); |
| 6544 } | 6564 } |
| 6545 return exports; | 6565 return exports; |
| 6546 })(); | 6566 })(); |
| OLD | NEW |