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

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

Issue 132993009: Use mock temp file in profiler tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 months 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
« no previous file with comments | « Source/devtools/front_end/HeapSnapshotView.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 function didFailToGetFile(error) 167 function didFailToGetFile(error)
168 { 168 {
169 WebInspector.log("Failed to load temp file: " + error.message, 169 WebInspector.log("Failed to load temp file: " + error.message,
170 WebInspector.ConsoleMessage.MessageLevel.Error); 170 WebInspector.ConsoleMessage.MessageLevel.Error);
171 callback(null); 171 callback(null);
172 } 172 }
173 this._fileEntry.file(didGetFile.bind(this), didFailToGetFile.bind(this)) ; 173 this._fileEntry.file(didGetFile.bind(this), didFailToGetFile.bind(this)) ;
174 }, 174 },
175 175
176 /** 176 /**
177 * @param {!function(?File)} callback 177 * @param {!WebInspector.OutputStream} outputStream
178 * @param {!WebInspector.OutputStreamDelegate} delegate
178 */ 179 */
179 getFile: function(callback) 180 writeToOutputSteam: function(outputStream, delegate)
180 { 181 {
182 /**
183 * @param {!File} file
184 * @this {WebInspector.TempFile}
185 */
186 function didGetFile(file)
187 {
188 var reader = new WebInspector.ChunkedFileReader(file, 10*1000*1000, delegate)
alph 2014/01/15 15:29:31 missing ;
yurys 2014/01/15 15:39:11 Done.
189 reader.start(outputStream);
190 }
181 function didFailToGetFile(error) 191 function didFailToGetFile(error)
182 { 192 {
183 WebInspector.log("Failed to load temp file: " + error.message, 193 WebInspector.log("Failed to load temp file: " + error.message,
184 WebInspector.ConsoleMessage.MessageLevel.Error); 194 WebInspector.ConsoleMessage.MessageLevel.Error);
185 callback(null); 195 outputStream.close();
186 } 196 }
187 this._fileEntry.file(callback, didFailToGetFile.bind(this)); 197 this._fileEntry.file(didGetFile.bind(this), didFailToGetFile.bind(this)) ;
188 } 198 }
189 } 199 }
190 200
191 /** 201 /**
192 * @constructor 202 * @constructor
193 * @param {!string} dirPath 203 * @param {!string} dirPath
194 * @param {!string} name 204 * @param {!string} name
195 */ 205 */
196 WebInspector.BufferedTempFileWriter = function(dirPath, name) 206 WebInspector.BufferedTempFileWriter = function(dirPath, name)
197 { 207 {
(...skipping 21 matching lines...) Expand all
219 }, 229 },
220 230
221 /** 231 /**
222 * @param {!function(?WebInspector.TempFile)} callback 232 * @param {!function(?WebInspector.TempFile)} callback
223 */ 233 */
224 close: function(callback) 234 close: function(callback)
225 { 235 {
226 this._finishCallback = callback; 236 this._finishCallback = callback;
227 if (this._isFinished) 237 if (this._isFinished)
228 callback(this._tempFile); 238 callback(this._tempFile);
239 else if (!this._isWriting && !this._chunks.length)
240 this._notifyFinished();
229 }, 241 },
230 242
231 _didCreateTempFile: function(tempFile) 243 _didCreateTempFile: function(tempFile)
232 { 244 {
233 this._tempFile = tempFile; 245 this._tempFile = tempFile;
234 if (!tempFile) { 246 if (!tempFile) {
235 this._chunks = null; 247 this._chunks = null;
236 this._notifyFinished(); 248 this._notifyFinished();
237 return; 249 return;
238 } 250 }
239 if (this._chunks.length) 251 if (this._chunks.length)
240 this._writeNextChunk(); 252 this._writeNextChunk();
241 }, 253 },
242 254
243 _writeNextChunk: function() 255 _writeNextChunk: function()
244 { 256 {
245 var chunkSize = 0; 257 var chunkSize = 0;
246 var endIndex = 0; 258 var endIndex = 0;
247 for (; endIndex < this._chunks.length; endIndex++) { 259 for (; endIndex < this._chunks.length; endIndex++) {
248 chunkSize += this._chunks[endIndex].length; 260 chunkSize += this._chunks[endIndex].length;
249 if (chunkSize > 10 * 1000 * 1000) 261 if (chunkSize > 10 * 1000 * 1000)
250 break; 262 break;
251 } 263 }
252 var chunk = this._chunks.slice(0, endIndex + 1).join(""); 264 var chunk = this._chunks.slice(0, endIndex + 1).join("");
253 this._chunks.splice(0, endIndex + 1); 265 this._chunks.splice(0, endIndex + 1);
266 this._isWriting = true;
254 this._tempFile.write(chunk, this._didWriteChunk.bind(this)); 267 this._tempFile.write(chunk, this._didWriteChunk.bind(this));
255 this._isWriting = true;
256 }, 268 },
257 269
258 _didWriteChunk: function(success) 270 _didWriteChunk: function(success)
259 { 271 {
260 this._isWriting = false; 272 this._isWriting = false;
261 if (!success) { 273 if (!success) {
262 this._tempFile = null; 274 this._tempFile = null;
263 this._chunks = null; 275 this._chunks = null;
264 this._notifyFinished(); 276 this._notifyFinished();
265 return; 277 return;
266 } 278 }
267 if (this._chunks.length) 279 if (this._chunks.length)
268 this._writeNextChunk(); 280 this._writeNextChunk();
269 else if (this._finishCallback) 281 else if (this._finishCallback)
270 this._notifyFinished(); 282 this._notifyFinished();
271 }, 283 },
272 284
273 _notifyFinished: function() 285 _notifyFinished: function()
274 { 286 {
275 this._isFinished = true; 287 this._isFinished = true;
276 if (this._tempFile) 288 if (this._tempFile)
277 this._tempFile.finishWriting(); 289 this._tempFile.finishWriting();
278 if (this._finishCallback) 290 if (this._finishCallback)
279 this._finishCallback(this._tempFile); 291 this._finishCallback(this._tempFile);
280 } 292 }
281 } 293 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/HeapSnapshotView.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698