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

Delta Between Two Patch Sets: lib/io.js

Issue 29367480: Issue 4721 - Use IndexedDB for storage in Edge (Closed)
Left Patch Set: Cleanup unnecessary changes Created Dec. 20, 2016, 12:14 a.m.
Right Patch Set: Address some nits Created Dec. 20, 2016, 2:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/localforage.min.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 const keyPrefix = "file:"; 18 const keyPrefix = "file:";
19 19
20 function fileToKey(file) 20 function fileToKey(file)
21 { 21 {
22 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); 22 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec);
23 } 23 }
24 24
25 function loadFile(file, successCallback, errorCallback) 25 function loadFile(file, successCallback, errorCallback)
26 { 26 {
27 let key = fileToKey(file); 27 let key = fileToKey(file);
28
28 // Make sure we do not have subscriptions in localStorage from older 29 // Make sure we do not have subscriptions in localStorage from older
29 // versions first 30 // versions first
30 let entry = localStorage.getItem(key); 31 let entry = localStorage.getItem(key);
31 if (typeof entry == "string") 32 if (typeof entry == "string")
32 { 33 {
33 try 34 try
34 { 35 {
35 entry = JSON.parse(entry); 36 entry = JSON.parse(entry);
36 } 37 }
37 catch(err) 38 catch(err)
(...skipping 11 matching lines...) Expand all
49 errorCallback(new Error("File doesn't exist")); 50 errorCallback(new Error("File doesn't exist"));
50 else 51 else
51 successCallback(value); 52 successCallback(value);
52 }); 53 });
53 } 54 }
54 55
55 function saveFile(file, data, callback) 56 function saveFile(file, data, callback)
56 { 57 {
57 var key = fileToKey(file); 58 var key = fileToKey(file);
58 var entry = { 59 var entry = {
59 lastModified: Date.now(), 60 content: Array.from(data),
kzar 2016/12/20 11:09:01 Nit: Mind putting these keys lastModified and cont
Oleksandr 2016/12/20 14:36:50 Done.
60 content: Array.from(data) 61 lastModified: Date.now()
61 }; 62 };
62 63
63 localStorage.removeItem(key); 64 localStorage.removeItem(key);
64 localforage.setItem(key, entry, callback); 65 localforage.setItem(key, entry, callback);
65 } 66 }
67
66 exports.IO = 68 exports.IO =
67 { 69 {
68 resolveFilePath: function(path) 70 resolveFilePath: function(path)
69 { 71 {
70 return new FakeFile(path); 72 return new FakeFile(path);
71 }, 73 },
72 74
73 readFromFile: function(file, listener, callback) 75 readFromFile: function(file, listener, callback)
74 { 76 {
75 function onLoaded(entry) 77 function onLoaded(entry)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 { 127 {
126 callback(null, { 128 callback(null, {
127 exists: true, 129 exists: true,
128 lastModified: entry.lastModified 130 lastModified: entry.lastModified
129 }); 131 });
130 } 132 }
131 133
132 loadFile(file, onLoaded, callback); 134 loadFile(file, onLoaded, callback);
133 } 135 }
134 }; 136 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld