| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 function didFailToGetFile(error) | 175 function didFailToGetFile(error) |
| 176 { | 176 { |
| 177 WebInspector.log("Failed to load temp file: " + error.message, | 177 WebInspector.log("Failed to load temp file: " + error.message, |
| 178 WebInspector.ConsoleMessage.MessageLevel.Error); | 178 WebInspector.ConsoleMessage.MessageLevel.Error); |
| 179 callback(null); | 179 callback(null); |
| 180 } | 180 } |
| 181 this._fileEntry.file(didGetFile.bind(this), didFailToGetFile.bind(this))
; | 181 this._fileEntry.file(didGetFile.bind(this), didFailToGetFile.bind(this))
; |
| 182 }, | 182 }, |
| 183 | 183 |
| 184 /** | 184 /** |
| 185 * @param {!function(?File)} callback | 185 * @param {!WebInspector.OutputStream} outputStream |
| 186 * @param {!WebInspector.OutputStreamDelegate} delegate |
| 186 */ | 187 */ |
| 187 getFile: function(callback) | 188 writeToOutputSteam: function(outputStream, delegate) |
| 188 { | 189 { |
| 190 /** |
| 191 * @param {!File} file |
| 192 * @this {WebInspector.TempFile} |
| 193 */ |
| 194 function didGetFile(file) |
| 195 { |
| 196 var reader = new WebInspector.ChunkedFileReader(file, 10*1000*1000,
delegate); |
| 197 reader.start(outputStream); |
| 198 } |
| 189 function didFailToGetFile(error) | 199 function didFailToGetFile(error) |
| 190 { | 200 { |
| 191 WebInspector.log("Failed to load temp file: " + error.message, | 201 WebInspector.log("Failed to load temp file: " + error.message, |
| 192 WebInspector.ConsoleMessage.MessageLevel.Error); | 202 WebInspector.ConsoleMessage.MessageLevel.Error); |
| 193 callback(null); | 203 outputStream.close(); |
| 194 } | 204 } |
| 195 this._fileEntry.file(callback, didFailToGetFile.bind(this)); | 205 this._fileEntry.file(didGetFile.bind(this), didFailToGetFile.bind(this))
; |
| 196 }, | 206 }, |
| 197 | 207 |
| 198 remove: function() | 208 remove: function() |
| 199 { | 209 { |
| 200 if (this._fileEntry) | 210 if (this._fileEntry) |
| 201 this._fileEntry.remove(function() {}); | 211 this._fileEntry.remove(function() {}); |
| 202 } | 212 } |
| 203 } | 213 } |
| 204 | 214 |
| 205 /** | 215 /** |
| (...skipping 27 matching lines...) Expand all Loading... |
| 233 }, | 243 }, |
| 234 | 244 |
| 235 /** | 245 /** |
| 236 * @param {!function(?WebInspector.TempFile)} callback | 246 * @param {!function(?WebInspector.TempFile)} callback |
| 237 */ | 247 */ |
| 238 close: function(callback) | 248 close: function(callback) |
| 239 { | 249 { |
| 240 this._finishCallback = callback; | 250 this._finishCallback = callback; |
| 241 if (this._isFinished) | 251 if (this._isFinished) |
| 242 callback(this._tempFile); | 252 callback(this._tempFile); |
| 253 else if (!this._isWriting && !this._chunks.length) |
| 254 this._notifyFinished(); |
| 243 }, | 255 }, |
| 244 | 256 |
| 245 _didCreateTempFile: function(tempFile) | 257 _didCreateTempFile: function(tempFile) |
| 246 { | 258 { |
| 247 this._tempFile = tempFile; | 259 this._tempFile = tempFile; |
| 248 if (!tempFile) { | 260 if (!tempFile) { |
| 249 this._chunks = null; | 261 this._chunks = null; |
| 250 this._notifyFinished(); | 262 this._notifyFinished(); |
| 251 return; | 263 return; |
| 252 } | 264 } |
| 253 if (this._chunks.length) | 265 if (this._chunks.length) |
| 254 this._writeNextChunk(); | 266 this._writeNextChunk(); |
| 255 }, | 267 }, |
| 256 | 268 |
| 257 _writeNextChunk: function() | 269 _writeNextChunk: function() |
| 258 { | 270 { |
| 259 var chunkSize = 0; | 271 var chunkSize = 0; |
| 260 var endIndex = 0; | 272 var endIndex = 0; |
| 261 for (; endIndex < this._chunks.length; endIndex++) { | 273 for (; endIndex < this._chunks.length; endIndex++) { |
| 262 chunkSize += this._chunks[endIndex].length; | 274 chunkSize += this._chunks[endIndex].length; |
| 263 if (chunkSize > 10 * 1000 * 1000) | 275 if (chunkSize > 10 * 1000 * 1000) |
| 264 break; | 276 break; |
| 265 } | 277 } |
| 266 var chunk = this._chunks.slice(0, endIndex + 1).join(""); | 278 var chunk = this._chunks.slice(0, endIndex + 1).join(""); |
| 267 this._chunks.splice(0, endIndex + 1); | 279 this._chunks.splice(0, endIndex + 1); |
| 280 this._isWriting = true; |
| 268 this._tempFile.write(chunk, this._didWriteChunk.bind(this)); | 281 this._tempFile.write(chunk, this._didWriteChunk.bind(this)); |
| 269 this._isWriting = true; | |
| 270 }, | 282 }, |
| 271 | 283 |
| 272 _didWriteChunk: function(success) | 284 _didWriteChunk: function(success) |
| 273 { | 285 { |
| 274 this._isWriting = false; | 286 this._isWriting = false; |
| 275 if (!success) { | 287 if (!success) { |
| 276 this._tempFile = null; | 288 this._tempFile = null; |
| 277 this._chunks = null; | 289 this._chunks = null; |
| 278 this._notifyFinished(); | 290 this._notifyFinished(); |
| 279 return; | 291 return; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 356 |
| 345 /** | 357 /** |
| 346 * @param {!function()} callback | 358 * @param {!function()} callback |
| 347 */ | 359 */ |
| 348 WebInspector.TempFile._ensureTempStorageCleared = function(callback) | 360 WebInspector.TempFile._ensureTempStorageCleared = function(callback) |
| 349 { | 361 { |
| 350 if (!WebInspector.TempFile._storageCleaner) | 362 if (!WebInspector.TempFile._storageCleaner) |
| 351 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea
ner(); | 363 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea
ner(); |
| 352 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback); | 364 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback); |
| 353 } | 365 } |
| OLD | NEW |