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: Don't introduce unnecessary changes from old code Created Dec. 19, 2016, 10:55 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') | metadata.edge » ('J')
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),
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 }
66 exports.IO = { 67
kzar 2016/12/19 13:31:04 Nit: looks like you missed this change, please cou
68 exports.IO =
69 {
67 resolveFilePath: function(path) 70 resolveFilePath: function(path)
68 { 71 {
69 return new FakeFile(path); 72 return new FakeFile(path);
70 }, 73 },
71 74
72 readFromFile: function(file, listener, callback) 75 readFromFile: function(file, listener, callback)
73 { 76 {
74 function onLoaded(entry) 77 function onLoaded(entry)
75 { 78 {
76 if ("content" in entry) 79 if ("content" in entry)
(...skipping 13 matching lines...) Expand all
90 saveFile(file, data, callback); 93 saveFile(file, data, callback);
91 }, 94 },
92 95
93 copyFile: function(fromFile, toFile, callback) 96 copyFile: function(fromFile, toFile, callback)
94 { 97 {
95 function onLoaded(entry) 98 function onLoaded(entry)
96 { 99 {
97 saveFile(toFile, entry.content, callback); 100 saveFile(toFile, entry.content, callback);
98 } 101 }
99 102
100 loadFile(file, onLoaded, callback); 103 loadFile(fromFile, onLoaded, callback);
kzar 2016/12/19 13:31:04 Seems to be a mistake? (Same below.)
Oleksandr 2016/12/20 00:18:28 Yep. We don't use any of these functions anyway, s
101 }, 104 },
102 105
103 renameFile: function(fromFile, newName, callback) 106 renameFile: function(fromFile, newName, callback)
104 { 107 {
105 function onLoaded() 108 function onLoaded()
106 { 109 {
107 ext.storage.remove(fileToKey(fromFile), function() 110 ext.storage.remove(fileToKey(fromFile), function()
108 { 111 {
109 ext.storage.set(keyPrefix + newName, entry, callback); 112 ext.storage.set(keyPrefix + newName, entry, callback);
110 }); 113 });
111 } 114 }
112 115
113 loadFile(file, onLoaded, callback); 116 loadFile(fromFile, onLoaded, callback);
114 }, 117 },
115 118
116 removeFile: function(file, callback) 119 removeFile: function(file, callback)
117 { 120 {
118 ext.storage.remove(fileToKey(file), callback); 121 ext.storage.remove(fileToKey(file), callback);
119 }, 122 },
120 123
121 statFile: function(file, callback) 124 statFile: function(file, callback)
122 { 125 {
123 function onLoaded(entry) 126 function onLoaded(entry)
124 { 127 {
125 callback(null, { 128 callback(null, {
126 exists: true, 129 exists: true,
127 lastModified: entry.lastModified 130 lastModified: entry.lastModified
128 }); 131 });
129 } 132 }
130 133
131 loadFile(file, onLoaded, callback); 134 loadFile(file, onLoaded, callback);
132 } 135 }
133 }; 136 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld