OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 callback(this); | 100 callback(this); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 function errorHandler(e) | 104 function errorHandler(e) |
105 { | 105 { |
106 WebInspector.log("Failed to create temp file " + e.code + " : " + e.mess age, | 106 WebInspector.log("Failed to create temp file " + e.code + " : " + e.mess age, |
107 WebInspector.ConsoleMessage.MessageLevel.Error); | 107 WebInspector.ConsoleMessage.MessageLevel.Error); |
108 callback(null); | 108 callback(null); |
109 } | 109 } |
110 | |
110 var boundErrorHandler = errorHandler.bind(this) | 111 var boundErrorHandler = errorHandler.bind(this) |
111 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), errorHa ndler.bind(this)); | 112 /** |
113 * @this {WebInspector.TempFile} | |
114 */ | |
115 function didClearTempStorage() | |
116 { | |
117 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), bou ndErrorHandler); | |
118 } | |
119 WebInspector.TempFile._ensureTempStorageCleared(didClearTempStorage.bind(thi s)); | |
112 } | 120 } |
113 | 121 |
114 WebInspector.TempFile.prototype = { | 122 WebInspector.TempFile.prototype = { |
115 /** | 123 /** |
116 * @param {!string} data | 124 * @param {!string} data |
117 * @param {!function(boolean)} callback | 125 * @param {!function(boolean)} callback |
118 */ | 126 */ |
119 write: function(data, callback) | 127 write: function(data, callback) |
120 { | 128 { |
121 var blob = new Blob([data], {type: 'text/plain'}); | 129 var blob = new Blob([data], {type: 'text/plain'}); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 */ | 186 */ |
179 getFile: function(callback) | 187 getFile: function(callback) |
180 { | 188 { |
181 function didFailToGetFile(error) | 189 function didFailToGetFile(error) |
182 { | 190 { |
183 WebInspector.log("Failed to load temp file: " + error.message, | 191 WebInspector.log("Failed to load temp file: " + error.message, |
184 WebInspector.ConsoleMessage.MessageLevel.Error); | 192 WebInspector.ConsoleMessage.MessageLevel.Error); |
185 callback(null); | 193 callback(null); |
186 } | 194 } |
187 this._fileEntry.file(callback, didFailToGetFile.bind(this)); | 195 this._fileEntry.file(callback, didFailToGetFile.bind(this)); |
196 }, | |
197 | |
198 remove: function() | |
199 { | |
200 function didRemove() {} | |
201 if (this._fileEntry) | |
202 this._fileEntry.remove(didRemove, didRemove); | |
pfeldman
2014/01/14 16:26:28
function() {}, function() {}
yurys
2014/01/15 08:30:11
Done.
| |
188 } | 203 } |
189 } | 204 } |
190 | 205 |
191 /** | 206 /** |
192 * @constructor | 207 * @constructor |
193 * @param {!string} dirPath | 208 * @param {!string} dirPath |
194 * @param {!string} name | 209 * @param {!string} name |
195 */ | 210 */ |
196 WebInspector.BufferedTempFileWriter = function(dirPath, name) | 211 WebInspector.BufferedTempFileWriter = function(dirPath, name) |
197 { | 212 { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 | 287 |
273 _notifyFinished: function() | 288 _notifyFinished: function() |
274 { | 289 { |
275 this._isFinished = true; | 290 this._isFinished = true; |
276 if (this._tempFile) | 291 if (this._tempFile) |
277 this._tempFile.finishWriting(); | 292 this._tempFile.finishWriting(); |
278 if (this._finishCallback) | 293 if (this._finishCallback) |
279 this._finishCallback(this._tempFile); | 294 this._finishCallback(this._tempFile); |
280 } | 295 } |
281 } | 296 } |
297 | |
298 /** | |
299 * @constructor | |
300 */ | |
301 WebInspector.TempStorageCleaner = function() | |
302 { | |
303 this._worker = new SharedWorker("TempStorageSharedWorker.js", "TempStorage") ; | |
304 this._callbacks = []; | |
305 this._worker.port.onmessage = this._handleMessage.bind(this); | |
306 this._worker.port.onerror = this._handleError.bind(this); | |
307 } | |
308 | |
309 WebInspector.TempStorageCleaner.prototype = { | |
310 /** | |
311 * @param {!function()} callback | |
312 */ | |
313 ensureStorageCleared: function(callback) | |
314 { | |
315 if (this._callbacks) | |
316 this._callbacks.push(callback); | |
317 else | |
318 callback(); | |
319 }, | |
320 | |
321 _handleMessage: function(event) | |
322 { | |
323 if (event.data.type === "tempStorageCleared") | |
324 this._notifyCallbacks(); | |
325 }, | |
326 | |
327 _handleError: function(event) | |
328 { | |
329 WebInspector.log("Failed to clear temp storage: " + event.data, | |
pfeldman
2014/01/14 16:26:28
WebInspector.UIString("Failed: ... %s", event.data
yurys
2014/01/15 08:30:11
Done.
| |
330 WebInspector.ConsoleMessage.MessageLevel.Error); | |
331 this._notifyCallbacks(); | |
332 }, | |
333 | |
334 _notifyCallbacks: function() | |
335 { | |
336 var callbacks = this._callbacks; | |
337 this._callbacks = null; | |
338 for (var i = 0; i < callbacks.length; i++) | |
339 callbacks[i](); | |
340 } | |
341 } | |
342 | |
343 /** | |
344 * @param {!function()} callback | |
345 */ | |
346 WebInspector.TempFile._ensureTempStorageCleared = function(callback) | |
347 { | |
348 if (!WebInspector.TempFile._storageCleaner) | |
349 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea ner(); | |
350 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback); | |
351 } | |
OLD | NEW |