| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileS
ystem; | 31 window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileS
ystem; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * @constructor | 34 * @constructor |
| 35 */ | 35 */ |
| 36 WebInspector.TempFile = function() | 36 WebInspector.TempFile = function() |
| 37 { | 37 { |
| 38 this._fileEntry = null; | 38 this._fileEntry = null; |
| 39 this._writer = null; | 39 this._writer = null; |
| 40 } | 40 }; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @param {string} dirPath | 43 * @param {string} dirPath |
| 44 * @param {string} name | 44 * @param {string} name |
| 45 * @return {!Promise.<!WebInspector.TempFile>} | 45 * @return {!Promise.<!WebInspector.TempFile>} |
| 46 */ | 46 */ |
| 47 WebInspector.TempFile.create = function(dirPath, name) | 47 WebInspector.TempFile.create = function(dirPath, name) |
| 48 { | 48 { |
| 49 var file = new WebInspector.TempFile(); | 49 var file = new WebInspector.TempFile(); |
| 50 | 50 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 return new Promise(truncate).then(didTruncate, onTruncateError); | 117 return new Promise(truncate).then(didTruncate, onTruncateError); |
| 118 } | 118 } |
| 119 | 119 |
| 120 return WebInspector.TempFile.ensureTempStorageCleared() | 120 return WebInspector.TempFile.ensureTempStorageCleared() |
| 121 .then(requestTempFileSystem) | 121 .then(requestTempFileSystem) |
| 122 .then(getDirectoryEntry) | 122 .then(getDirectoryEntry) |
| 123 .then(getFileEntry) | 123 .then(getFileEntry) |
| 124 .then(createFileWriter) | 124 .then(createFileWriter) |
| 125 .then(truncateFile); | 125 .then(truncateFile); |
| 126 } | 126 }; |
| 127 | 127 |
| 128 WebInspector.TempFile.prototype = { | 128 WebInspector.TempFile.prototype = { |
| 129 /** | 129 /** |
| 130 * @param {!Array.<string>} strings | 130 * @param {!Array.<string>} strings |
| 131 * @param {function(number)} callback | 131 * @param {function(number)} callback |
| 132 */ | 132 */ |
| 133 write: function(strings, callback) | 133 write: function(strings, callback) |
| 134 { | 134 { |
| 135 var blob = new Blob(strings, {type: "text/plain"}); | 135 var blob = new Blob(strings, {type: "text/plain"}); |
| 136 this._writer.onerror = function(e) | 136 this._writer.onerror = function(e) |
| 137 { | 137 { |
| 138 WebInspector.console.error("Failed to write into a temp file: " + e.
target.error.message); | 138 WebInspector.console.error("Failed to write into a temp file: " + e.
target.error.message); |
| 139 callback(-1); | 139 callback(-1); |
| 140 } | 140 }; |
| 141 this._writer.onwriteend = function(e) | 141 this._writer.onwriteend = function(e) |
| 142 { | 142 { |
| 143 callback(e.target.length); | 143 callback(e.target.length); |
| 144 } | 144 }; |
| 145 this._writer.write(blob); | 145 this._writer.write(blob); |
| 146 }, | 146 }, |
| 147 | 147 |
| 148 finishWriting: function() | 148 finishWriting: function() |
| 149 { | 149 { |
| 150 this._writer = null; | 150 this._writer = null; |
| 151 }, | 151 }, |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @param {function(?string)} callback | 154 * @param {function(?string)} callback |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 this._fileEntry.file(didGetFile, didFailToGetFile); | 219 this._fileEntry.file(didGetFile, didFailToGetFile); |
| 220 }, | 220 }, |
| 221 | 221 |
| 222 remove: function() | 222 remove: function() |
| 223 { | 223 { |
| 224 if (this._fileEntry) | 224 if (this._fileEntry) |
| 225 this._fileEntry.remove(function() {}); | 225 this._fileEntry.remove(function() {}); |
| 226 } | 226 } |
| 227 } | 227 }; |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * @constructor | 230 * @constructor |
| 231 * @param {string} dirPath | 231 * @param {string} dirPath |
| 232 * @param {string} name | 232 * @param {string} name |
| 233 */ | 233 */ |
| 234 WebInspector.DeferredTempFile = function(dirPath, name) | 234 WebInspector.DeferredTempFile = function(dirPath, name) |
| 235 { | 235 { |
| 236 /** @type {!Array.<!{strings: !Array.<string>, callback: ?function(number)}>
} */ | 236 /** @type {!Array.<!{strings: !Array.<string>, callback: ?function(number)}>
} */ |
| 237 this._chunks = []; | 237 this._chunks = []; |
| 238 this._tempFile = null; | 238 this._tempFile = null; |
| 239 this._isWriting = false; | 239 this._isWriting = false; |
| 240 this._finishCallback = null; | 240 this._finishCallback = null; |
| 241 this._finishedWriting = false; | 241 this._finishedWriting = false; |
| 242 this._callsPendingOpen = []; | 242 this._callsPendingOpen = []; |
| 243 this._pendingReads = []; | 243 this._pendingReads = []; |
| 244 WebInspector.TempFile.create(dirPath, name) | 244 WebInspector.TempFile.create(dirPath, name) |
| 245 .then(this._didCreateTempFile.bind(this), this._failedToCreateTempFile.b
ind(this)); | 245 .then(this._didCreateTempFile.bind(this), this._failedToCreateTempFile.b
ind(this)); |
| 246 } | 246 }; |
| 247 | 247 |
| 248 WebInspector.DeferredTempFile.prototype = { | 248 WebInspector.DeferredTempFile.prototype = { |
| 249 /** | 249 /** |
| 250 * @param {!Array.<string>} strings | 250 * @param {!Array.<string>} strings |
| 251 * @param {function(number)=} callback | 251 * @param {function(number)=} callback |
| 252 */ | 252 */ |
| 253 write: function(strings, callback) | 253 write: function(strings, callback) |
| 254 { | 254 { |
| 255 if (this._finishCallback) | 255 if (this._finishCallback) |
| 256 throw new Error("No writes are allowed after close."); | 256 throw new Error("No writes are allowed after close."); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 remove: function() | 378 remove: function() |
| 379 { | 379 { |
| 380 if (this._callsPendingOpen) { | 380 if (this._callsPendingOpen) { |
| 381 this._callsPendingOpen.push(this.remove.bind(this)); | 381 this._callsPendingOpen.push(this.remove.bind(this)); |
| 382 return; | 382 return; |
| 383 } | 383 } |
| 384 if (this._tempFile) | 384 if (this._tempFile) |
| 385 this._tempFile.remove(); | 385 this._tempFile.remove(); |
| 386 this._tempFile = null; | 386 this._tempFile = null; |
| 387 } | 387 } |
| 388 } | 388 }; |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * @return {!Promise.<undefined>} | 391 * @return {!Promise.<undefined>} |
| 392 */ | 392 */ |
| 393 WebInspector.TempFile.ensureTempStorageCleared = function() | 393 WebInspector.TempFile.ensureTempStorageCleared = function() |
| 394 { | 394 { |
| 395 if (!WebInspector.TempFile._storageCleanerPromise) { | 395 if (!WebInspector.TempFile._storageCleanerPromise) { |
| 396 WebInspector.TempFile._storageCleanerPromise = WebInspector.serviceManag
er.createAppService("utility_shared_worker", "TempStorage", true).then(service =
> { | 396 WebInspector.TempFile._storageCleanerPromise = WebInspector.serviceManag
er.createAppService("utility_shared_worker", "TempStorage", true).then(service =
> { |
| 397 if (service) | 397 if (service) |
| 398 return service.send("clear"); | 398 return service.send("clear"); |
| 399 }); | 399 }); |
| 400 } | 400 } |
| 401 return WebInspector.TempFile._storageCleanerPromise; | 401 return WebInspector.TempFile._storageCleanerPromise; |
| 402 } | 402 }; |
| 403 | 403 |
| 404 /** | 404 /** |
| 405 * @constructor | 405 * @constructor |
| 406 * @implements {WebInspector.BackingStorage} | 406 * @implements {WebInspector.BackingStorage} |
| 407 * @param {string} dirName | 407 * @param {string} dirName |
| 408 */ | 408 */ |
| 409 WebInspector.TempFileBackingStorage = function(dirName) | 409 WebInspector.TempFileBackingStorage = function(dirName) |
| 410 { | 410 { |
| 411 this._dirName = dirName; | 411 this._dirName = dirName; |
| 412 this.reset(); | 412 this.reset(); |
| 413 } | 413 }; |
| 414 | 414 |
| 415 /** | 415 /** |
| 416 * @typedef {{ | 416 * @typedef {{ |
| 417 * string: ?string, | 417 * string: ?string, |
| 418 * startOffset: number, | 418 * startOffset: number, |
| 419 * endOffset: number | 419 * endOffset: number |
| 420 * }} | 420 * }} |
| 421 */ | 421 */ |
| 422 WebInspector.TempFileBackingStorage.Chunk; | 422 WebInspector.TempFileBackingStorage.Chunk; |
| 423 | 423 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 }, | 544 }, |
| 545 | 545 |
| 546 /** | 546 /** |
| 547 * @param {!WebInspector.OutputStream} outputStream | 547 * @param {!WebInspector.OutputStream} outputStream |
| 548 * @param {!WebInspector.OutputStreamDelegate} delegate | 548 * @param {!WebInspector.OutputStreamDelegate} delegate |
| 549 */ | 549 */ |
| 550 writeToStream: function(outputStream, delegate) | 550 writeToStream: function(outputStream, delegate) |
| 551 { | 551 { |
| 552 this._file.copyToOutputStream(outputStream, delegate); | 552 this._file.copyToOutputStream(outputStream, delegate); |
| 553 } | 553 } |
| 554 } | 554 }; |
| OLD | NEW |