| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 function didTruncate(e) | 81 function didTruncate(e) |
| 82 { | 82 { |
| 83 this._writer = writer; | 83 this._writer = writer; |
| 84 writer.onwrite = null; | 84 writer.onwrite = null; |
| 85 writer.onerror = null; | 85 writer.onerror = null; |
| 86 callback(this); | 86 callback(this); |
| 87 } | 87 } |
| 88 | 88 |
| 89 function onTruncateError(e) | 89 function onTruncateError(e) |
| 90 { | 90 { |
| 91 WebInspector.console.addErrorMessage("Failed to truncate temp file "
+ e.code + " : " + e.message); | 91 WebInspector.console.error("Failed to truncate temp file " + e.code
+ " : " + e.message); |
| 92 callback(null); | 92 callback(null); |
| 93 } | 93 } |
| 94 | 94 |
| 95 if (writer.length) { | 95 if (writer.length) { |
| 96 writer.onwrite = didTruncate.bind(this); | 96 writer.onwrite = didTruncate.bind(this); |
| 97 writer.onerror = onTruncateError; | 97 writer.onerror = onTruncateError; |
| 98 writer.truncate(0); | 98 writer.truncate(0); |
| 99 } else { | 99 } else { |
| 100 this._writer = writer; | 100 this._writer = writer; |
| 101 callback(this); | 101 callback(this); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 function errorHandler(e) | 105 function errorHandler(e) |
| 106 { | 106 { |
| 107 WebInspector.console.addErrorMessage("Failed to create temp file " + e.c
ode + " : " + e.message); | 107 WebInspector.console.error("Failed to create temp file " + e.code + " :
" + e.message); |
| 108 callback(null); | 108 callback(null); |
| 109 } | 109 } |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * @this {WebInspector.TempFile} | 112 * @this {WebInspector.TempFile} |
| 113 */ | 113 */ |
| 114 function didClearTempStorage() | 114 function didClearTempStorage() |
| 115 { | 115 { |
| 116 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), err
orHandler); | 116 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), err
orHandler); |
| 117 } | 117 } |
| 118 WebInspector.TempFile._ensureTempStorageCleared(didClearTempStorage.bind(thi
s)); | 118 WebInspector.TempFile._ensureTempStorageCleared(didClearTempStorage.bind(thi
s)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 WebInspector.TempFile.prototype = { | 121 WebInspector.TempFile.prototype = { |
| 122 /** | 122 /** |
| 123 * @param {!string} data | 123 * @param {!string} data |
| 124 * @param {!function(boolean)} callback | 124 * @param {!function(boolean)} callback |
| 125 */ | 125 */ |
| 126 write: function(data, callback) | 126 write: function(data, callback) |
| 127 { | 127 { |
| 128 var blob = new Blob([data], {type: 'text/plain'}); | 128 var blob = new Blob([data], {type: 'text/plain'}); |
| 129 this._writer.onerror = function(e) | 129 this._writer.onerror = function(e) |
| 130 { | 130 { |
| 131 WebInspector.console.addErrorMessage("Failed to write into a temp fi
le: " + e.message); | 131 WebInspector.console.error("Failed to write into a temp file: " + e.
message); |
| 132 callback(false); | 132 callback(false); |
| 133 } | 133 } |
| 134 this._writer.onwrite = function(e) | 134 this._writer.onwrite = function(e) |
| 135 { | 135 { |
| 136 callback(true); | 136 callback(true); |
| 137 } | 137 } |
| 138 this._writer.write(blob); | 138 this._writer.write(blob); |
| 139 }, | 139 }, |
| 140 | 140 |
| 141 finishWriting: function() | 141 finishWriting: function() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * @this {FileReader} | 159 * @this {FileReader} |
| 160 */ | 160 */ |
| 161 reader.onloadend = function(e) | 161 reader.onloadend = function(e) |
| 162 { | 162 { |
| 163 callback(/** @type {?string} */ (this.result)); | 163 callback(/** @type {?string} */ (this.result)); |
| 164 } | 164 } |
| 165 reader.onerror = function(error) | 165 reader.onerror = function(error) |
| 166 { | 166 { |
| 167 WebInspector.console.addErrorMessage("Failed to read from temp f
ile: " + error.message); | 167 WebInspector.console.error("Failed to read from temp file: " + e
rror.message); |
| 168 } | 168 } |
| 169 reader.readAsText(file); | 169 reader.readAsText(file); |
| 170 } | 170 } |
| 171 function didFailToGetFile(error) | 171 function didFailToGetFile(error) |
| 172 { | 172 { |
| 173 WebInspector.console.addErrorMessage("Failed to load temp file: " +
error.message); | 173 WebInspector.console.error("Failed to load temp file: " + error.mess
age); |
| 174 callback(null); | 174 callback(null); |
| 175 } | 175 } |
| 176 this._fileEntry.file(didGetFile, didFailToGetFile); | 176 this._fileEntry.file(didGetFile, didFailToGetFile); |
| 177 }, | 177 }, |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * @param {!WebInspector.OutputStream} outputStream | 180 * @param {!WebInspector.OutputStream} outputStream |
| 181 * @param {!WebInspector.OutputStreamDelegate} delegate | 181 * @param {!WebInspector.OutputStreamDelegate} delegate |
| 182 */ | 182 */ |
| 183 writeToOutputSteam: function(outputStream, delegate) | 183 writeToOutputSteam: function(outputStream, delegate) |
| 184 { | 184 { |
| 185 /** | 185 /** |
| 186 * @param {!File} file | 186 * @param {!File} file |
| 187 */ | 187 */ |
| 188 function didGetFile(file) | 188 function didGetFile(file) |
| 189 { | 189 { |
| 190 var reader = new WebInspector.ChunkedFileReader(file, 10*1000*1000,
delegate); | 190 var reader = new WebInspector.ChunkedFileReader(file, 10*1000*1000,
delegate); |
| 191 reader.start(outputStream); | 191 reader.start(outputStream); |
| 192 } | 192 } |
| 193 | 193 |
| 194 function didFailToGetFile(error) | 194 function didFailToGetFile(error) |
| 195 { | 195 { |
| 196 WebInspector.console.addErrorMessage("Failed to load temp file: " +
error.message); | 196 WebInspector.console.error("Failed to load temp file: " + error.mess
age); |
| 197 outputStream.close(); | 197 outputStream.close(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 this._fileEntry.file(didGetFile, didFailToGetFile); | 200 this._fileEntry.file(didGetFile, didFailToGetFile); |
| 201 }, | 201 }, |
| 202 | 202 |
| 203 remove: function() | 203 remove: function() |
| 204 { | 204 { |
| 205 if (this._fileEntry) | 205 if (this._fileEntry) |
| 206 this._fileEntry.remove(function() {}); | 206 this._fileEntry.remove(function() {}); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 if (this._callbacks) | 321 if (this._callbacks) |
| 322 this._callbacks.push(callback); | 322 this._callbacks.push(callback); |
| 323 else | 323 else |
| 324 callback(); | 324 callback(); |
| 325 }, | 325 }, |
| 326 | 326 |
| 327 _handleMessage: function(event) | 327 _handleMessage: function(event) |
| 328 { | 328 { |
| 329 if (event.data.type === "tempStorageCleared") { | 329 if (event.data.type === "tempStorageCleared") { |
| 330 if (event.data.error) | 330 if (event.data.error) |
| 331 WebInspector.console.addErrorMessage(event.data.error); | 331 WebInspector.console.error(event.data.error); |
| 332 this._notifyCallbacks(); | 332 this._notifyCallbacks(); |
| 333 } | 333 } |
| 334 }, | 334 }, |
| 335 | 335 |
| 336 _handleError: function(event) | 336 _handleError: function(event) |
| 337 { | 337 { |
| 338 WebInspector.console.addErrorMessage(WebInspector.UIString("Failed to cl
ear temp storage: %s", event.data)); | 338 WebInspector.console.error(WebInspector.UIString("Failed to clear temp s
torage: %s", event.data)); |
| 339 this._notifyCallbacks(); | 339 this._notifyCallbacks(); |
| 340 }, | 340 }, |
| 341 | 341 |
| 342 _notifyCallbacks: function() | 342 _notifyCallbacks: function() |
| 343 { | 343 { |
| 344 var callbacks = this._callbacks; | 344 var callbacks = this._callbacks; |
| 345 this._callbacks = null; | 345 this._callbacks = null; |
| 346 for (var i = 0; i < callbacks.length; i++) | 346 for (var i = 0; i < callbacks.length; i++) |
| 347 callbacks[i](); | 347 callbacks[i](); |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 | 350 |
| 351 /** | 351 /** |
| 352 * @param {!function()} callback | 352 * @param {!function()} callback |
| 353 */ | 353 */ |
| 354 WebInspector.TempFile._ensureTempStorageCleared = function(callback) | 354 WebInspector.TempFile._ensureTempStorageCleared = function(callback) |
| 355 { | 355 { |
| 356 if (!WebInspector.TempFile._storageCleaner) | 356 if (!WebInspector.TempFile._storageCleaner) |
| 357 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea
ner(); | 357 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea
ner(); |
| 358 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback); | 358 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback); |
| 359 } | 359 } |
| OLD | NEW |