Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Side by Side Diff: Source/devtools/front_end/bindings/TempFile.js

Issue 685203003: DevTools: Get rid of synchronous XHRs in the frontend code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
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 * @param {!string} dirPath 35 * @param {string} dirPath
36 * @param {!string} name 36 * @param {string} name
37 * @param {!function(?WebInspector.TempFile)} callback 37 * @param {function(?WebInspector.TempFile)} callback
38 */ 38 */
39 WebInspector.TempFile = function(dirPath, name, callback) 39 WebInspector.TempFile = function(dirPath, name, callback)
40 { 40 {
41 this._fileEntry = null; 41 this._fileEntry = null;
42 this._writer = null; 42 this._writer = null;
43 43
44 /** 44 /**
45 * @param {!FileSystem} fs 45 * @param {!FileSystem} fs
46 * @this {WebInspector.TempFile} 46 * @this {WebInspector.TempFile}
47 */ 47 */
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {!Array.<string>} strings 123 * @param {!Array.<string>} strings
124 * @param {!function(boolean)} callback 124 * @param {function(boolean)} callback
125 */ 125 */
126 write: function(strings, callback) 126 write: function(strings, callback)
127 { 127 {
128 var blob = new Blob(strings, {type: 'text/plain'}); 128 var blob = new Blob(strings, {type: 'text/plain'});
129 this._writer.onerror = function(e) 129 this._writer.onerror = function(e)
130 { 130 {
131 WebInspector.console.error("Failed to write into a temp file: " + e. target.error.message); 131 WebInspector.console.error("Failed to write into a temp file: " + e. target.error.message);
132 callback(false); 132 callback(false);
133 } 133 }
134 this._writer.onwriteend = function(e) 134 this._writer.onwriteend = function(e)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 remove: function() 215 remove: function()
216 { 216 {
217 if (this._fileEntry) 217 if (this._fileEntry)
218 this._fileEntry.remove(function() {}); 218 this._fileEntry.remove(function() {});
219 } 219 }
220 } 220 }
221 221
222 /** 222 /**
223 * @constructor 223 * @constructor
224 * @param {!string} dirPath 224 * @param {string} dirPath
225 * @param {!string} name 225 * @param {string} name
226 */ 226 */
227 WebInspector.DeferredTempFile = function(dirPath, name) 227 WebInspector.DeferredTempFile = function(dirPath, name)
228 { 228 {
229 this._chunks = []; 229 this._chunks = [];
230 this._tempFile = null; 230 this._tempFile = null;
231 this._isWriting = false; 231 this._isWriting = false;
232 this._finishCallback = null; 232 this._finishCallback = null;
233 this._finishedWriting = false; 233 this._finishedWriting = false;
234 this._callsPendingOpen = []; 234 this._callsPendingOpen = [];
235 this._pendingReads = []; 235 this._pendingReads = [];
236 new WebInspector.TempFile(dirPath, name, this._didCreateTempFile.bind(this)) ; 236 new WebInspector.TempFile(dirPath, name, this._didCreateTempFile.bind(this)) ;
237 } 237 }
238 238
239 WebInspector.DeferredTempFile.prototype = { 239 WebInspector.DeferredTempFile.prototype = {
240 /** 240 /**
241 * @param {!Array.<string>} strings 241 * @param {!Array.<string>} strings
242 */ 242 */
243 write: function(strings) 243 write: function(strings)
244 { 244 {
245 if (!this._chunks) 245 if (!this._chunks)
246 return; 246 return;
247 if (this._finishCallback) 247 if (this._finishCallback)
248 throw new Error("No writes are allowed after close."); 248 throw new Error("No writes are allowed after close.");
249 this._chunks.push.apply(this._chunks, strings); 249 this._chunks.push.apply(this._chunks, strings);
250 if (this._tempFile && !this._isWriting) 250 if (this._tempFile && !this._isWriting)
251 this._writeNextChunk(); 251 this._writeNextChunk();
252 }, 252 },
253 253
254 /** 254 /**
255 * @param {!function(?WebInspector.TempFile)} callback 255 * @param {function(?WebInspector.TempFile)} callback
256 */ 256 */
257 finishWriting: function(callback) 257 finishWriting: function(callback)
258 { 258 {
259 this._finishCallback = callback; 259 this._finishCallback = callback;
260 if (this._finishedWriting) 260 if (this._finishedWriting)
261 callback(this._tempFile); 261 callback(this._tempFile);
262 else if (!this._isWriting && !this._chunks.length) 262 else if (!this._isWriting && !this._chunks.length)
263 this._notifyFinished(); 263 this._notifyFinished();
264 }, 264 },
265 265
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (this._tempFile) 356 if (this._tempFile)
357 this._tempFile.remove(); 357 this._tempFile.remove();
358 } 358 }
359 } 359 }
360 360
361 /** 361 /**
362 * @constructor 362 * @constructor
363 */ 363 */
364 WebInspector.TempStorageCleaner = function() 364 WebInspector.TempStorageCleaner = function()
365 { 365 {
366 this._worker = Runtime.startSharedWorker("temp_storage_shared_worker", "Temp Storage"); 366 Runtime.startSharedWorker("temp_storage_shared_worker", "TempStorage").then( this._init.bind(this)).done();
367 this._worker.onerror = this._handleError.bind(this);
368 this._callbacks = [];
369 this._worker.port.onmessage = this._handleMessage.bind(this);
370 this._worker.port.onerror = this._handleError.bind(this);
371 } 367 }
372 368
373 WebInspector.TempStorageCleaner.prototype = { 369 WebInspector.TempStorageCleaner.prototype = {
374 /** 370 /**
375 * @param {!function()} callback 371 * @param {!SharedWorker} worker
372 */
373 _init: function(worker)
374 {
375 this._worker = worker;
376 this._worker.onerror = this._handleError.bind(this);
377 this._callbacks = [];
378 this._worker.port.onmessage = this._handleMessage.bind(this);
379 this._worker.port.onerror = this._handleError.bind(this);
380 },
381
382 /**
383 * @param {function()} callback
376 */ 384 */
377 ensureStorageCleared: function(callback) 385 ensureStorageCleared: function(callback)
378 { 386 {
379 if (this._callbacks) 387 if (this._callbacks)
380 this._callbacks.push(callback); 388 this._callbacks.push(callback);
381 else 389 else
382 callback(); 390 callback();
383 }, 391 },
384 392
385 _handleMessage: function(event) 393 _handleMessage: function(event)
(...skipping 14 matching lines...) Expand all
400 _notifyCallbacks: function() 408 _notifyCallbacks: function()
401 { 409 {
402 var callbacks = this._callbacks; 410 var callbacks = this._callbacks;
403 this._callbacks = null; 411 this._callbacks = null;
404 for (var i = 0; i < callbacks.length; i++) 412 for (var i = 0; i < callbacks.length; i++)
405 callbacks[i](); 413 callbacks[i]();
406 } 414 }
407 } 415 }
408 416
409 /** 417 /**
410 * @param {!function()} callback 418 * @param {function()} callback
411 */ 419 */
412 WebInspector.TempFile._ensureTempStorageCleared = function(callback) 420 WebInspector.TempFile._ensureTempStorageCleared = function(callback)
413 { 421 {
414 if (!WebInspector.TempFile._storageCleaner) 422 if (!WebInspector.TempFile._storageCleaner)
415 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea ner(); 423 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea ner();
416 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback); 424 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback);
417 } 425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698