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

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

Issue 298333003: DevTools: Implement console message logging through an extension (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove duplicate logging Created 6 years, 6 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
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.log("Failed to truncate temp file " + e.code + " : " + e.message, 91 WebInspector.messageSink.addErrorMessage("Failed to truncate temp fi le " + e.code + " : " + e.message);
92 WebInspector.ConsoleMessage.MessageLevel.Error);
93 callback(null); 92 callback(null);
94 } 93 }
95 94
96 if (writer.length) { 95 if (writer.length) {
97 writer.onwrite = didTruncate.bind(this); 96 writer.onwrite = didTruncate.bind(this);
98 writer.onerror = onTruncateError; 97 writer.onerror = onTruncateError;
99 writer.truncate(0); 98 writer.truncate(0);
100 } else { 99 } else {
101 this._writer = writer; 100 this._writer = writer;
102 callback(this); 101 callback(this);
103 } 102 }
104 } 103 }
105 104
106 function errorHandler(e) 105 function errorHandler(e)
107 { 106 {
108 WebInspector.console.log("Failed to create temp file " + e.code + " : " + e.message, 107 WebInspector.messageSink.addErrorMessage("Failed to create temp file " + e.code + " : " + e.message);
109 WebInspector.ConsoleMessage.MessageLevel.Error);
110 callback(null); 108 callback(null);
111 } 109 }
112 110
113 /** 111 /**
114 * @this {WebInspector.TempFile} 112 * @this {WebInspector.TempFile}
115 */ 113 */
116 function didClearTempStorage() 114 function didClearTempStorage()
117 { 115 {
118 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), err orHandler); 116 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), err orHandler);
119 } 117 }
120 WebInspector.TempFile._ensureTempStorageCleared(didClearTempStorage.bind(thi s)); 118 WebInspector.TempFile._ensureTempStorageCleared(didClearTempStorage.bind(thi s));
121 } 119 }
122 120
123 WebInspector.TempFile.prototype = { 121 WebInspector.TempFile.prototype = {
124 /** 122 /**
125 * @param {!string} data 123 * @param {!string} data
126 * @param {!function(boolean)} callback 124 * @param {!function(boolean)} callback
127 */ 125 */
128 write: function(data, callback) 126 write: function(data, callback)
129 { 127 {
130 var blob = new Blob([data], {type: 'text/plain'}); 128 var blob = new Blob([data], {type: 'text/plain'});
131 this._writer.onerror = function(e) 129 this._writer.onerror = function(e)
132 { 130 {
133 WebInspector.console.log("Failed to write into a temp file: " + e.me ssage, 131 WebInspector.messageSink.addErrorMessage("Failed to write into a tem p file: " + e.message);
134 WebInspector.ConsoleMessage.MessageLevel.Error);
135 callback(false); 132 callback(false);
136 } 133 }
137 this._writer.onwrite = function(e) 134 this._writer.onwrite = function(e)
138 { 135 {
139 callback(true); 136 callback(true);
140 } 137 }
141 this._writer.write(blob); 138 this._writer.write(blob);
142 }, 139 },
143 140
144 finishWriting: function() 141 finishWriting: function()
(...skipping 15 matching lines...) Expand all
160 157
161 /** 158 /**
162 * @this {FileReader} 159 * @this {FileReader}
163 */ 160 */
164 reader.onloadend = function(e) 161 reader.onloadend = function(e)
165 { 162 {
166 callback(/** @type {?string} */ (this.result)); 163 callback(/** @type {?string} */ (this.result));
167 } 164 }
168 reader.onerror = function(error) 165 reader.onerror = function(error)
169 { 166 {
170 WebInspector.console.log("Failed to read from temp file: " + err or.message, 167 WebInspector.messageSink.addErrorMessage("Failed to read from te mp file: " + error.message);
171 WebInspector.ConsoleMessage.MessageLevel.Error) ;
172 } 168 }
173 reader.readAsText(file); 169 reader.readAsText(file);
174 } 170 }
175 function didFailToGetFile(error) 171 function didFailToGetFile(error)
176 { 172 {
177 WebInspector.console.log("Failed to load temp file: " + error.messag e, 173 WebInspector.messageSink.addErrorMessage("Failed to load temp file: " + error.message);
178 WebInspector.ConsoleMessage.MessageLevel.Error);
179 callback(null); 174 callback(null);
180 } 175 }
181 this._fileEntry.file(didGetFile, didFailToGetFile); 176 this._fileEntry.file(didGetFile, didFailToGetFile);
182 }, 177 },
183 178
184 /** 179 /**
185 * @param {!WebInspector.OutputStream} outputStream 180 * @param {!WebInspector.OutputStream} outputStream
186 * @param {!WebInspector.OutputStreamDelegate} delegate 181 * @param {!WebInspector.OutputStreamDelegate} delegate
187 */ 182 */
188 writeToOutputSteam: function(outputStream, delegate) 183 writeToOutputSteam: function(outputStream, delegate)
189 { 184 {
190 /** 185 /**
191 * @param {!File} file 186 * @param {!File} file
192 */ 187 */
193 function didGetFile(file) 188 function didGetFile(file)
194 { 189 {
195 var reader = new WebInspector.ChunkedFileReader(file, 10*1000*1000, delegate); 190 var reader = new WebInspector.ChunkedFileReader(file, 10*1000*1000, delegate);
196 reader.start(outputStream); 191 reader.start(outputStream);
197 } 192 }
198 193
199 function didFailToGetFile(error) 194 function didFailToGetFile(error)
200 { 195 {
201 WebInspector.console.log("Failed to load temp file: " + error.messag e, 196 WebInspector.messageSink.addErrorMessage("Failed to load temp file: " + error.message);
202 WebInspector.ConsoleMessage.MessageLevel.Error);
203 outputStream.close(); 197 outputStream.close();
204 } 198 }
205 199
206 this._fileEntry.file(didGetFile, didFailToGetFile); 200 this._fileEntry.file(didGetFile, didFailToGetFile);
207 }, 201 },
208 202
209 remove: function() 203 remove: function()
210 { 204 {
211 if (this._fileEntry) 205 if (this._fileEntry)
212 this._fileEntry.remove(function() {}); 206 this._fileEntry.remove(function() {});
(...skipping 17 matching lines...) Expand all
230 224
231 WebInspector.BufferedTempFileWriter.prototype = { 225 WebInspector.BufferedTempFileWriter.prototype = {
232 /** 226 /**
233 * @param {!string} data 227 * @param {!string} data
234 */ 228 */
235 write: function(data) 229 write: function(data)
236 { 230 {
237 if (!this._chunks) 231 if (!this._chunks)
238 return; 232 return;
239 if (this._finishCallback) 233 if (this._finishCallback)
240 throw new Error("Now writes are allowed after close."); 234 throw new Error("No writes are allowed after close.");
241 this._chunks.push(data); 235 this._chunks.push(data);
242 if (this._tempFile && !this._isWriting) 236 if (this._tempFile && !this._isWriting)
243 this._writeNextChunk(); 237 this._writeNextChunk();
244 }, 238 },
245 239
246 /** 240 /**
247 * @param {!function(?WebInspector.TempFile)} callback 241 * @param {!function(?WebInspector.TempFile)} callback
248 */ 242 */
249 close: function(callback) 243 close: function(callback)
250 { 244 {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (this._callbacks) 321 if (this._callbacks)
328 this._callbacks.push(callback); 322 this._callbacks.push(callback);
329 else 323 else
330 callback(); 324 callback();
331 }, 325 },
332 326
333 _handleMessage: function(event) 327 _handleMessage: function(event)
334 { 328 {
335 if (event.data.type === "tempStorageCleared") { 329 if (event.data.type === "tempStorageCleared") {
336 if (event.data.error) 330 if (event.data.error)
337 WebInspector.console.log(event.data.error, WebInspector.ConsoleM essage.MessageLevel.Error); 331 WebInspector.messageSink.addErrorMessage(event.data.error);
338 this._notifyCallbacks(); 332 this._notifyCallbacks();
339 } 333 }
340 }, 334 },
341 335
342 _handleError: function(event) 336 _handleError: function(event)
343 { 337 {
344 WebInspector.console.log(WebInspector.UIString("Failed to clear temp sto rage: %s", event.data), 338 WebInspector.messageSink.addErrorMessage(WebInspector.UIString("Failed t o clear temp storage: %s", event.data));
345 WebInspector.ConsoleMessage.MessageLevel.Error);
346 this._notifyCallbacks(); 339 this._notifyCallbacks();
347 }, 340 },
348 341
349 _notifyCallbacks: function() 342 _notifyCallbacks: function()
350 { 343 {
351 var callbacks = this._callbacks; 344 var callbacks = this._callbacks;
352 this._callbacks = null; 345 this._callbacks = null;
353 for (var i = 0; i < callbacks.length; i++) 346 for (var i = 0; i < callbacks.length; i++)
354 callbacks[i](); 347 callbacks[i]();
355 } 348 }
356 } 349 }
357 350
358 /** 351 /**
359 * @param {!function()} callback 352 * @param {!function()} callback
360 */ 353 */
361 WebInspector.TempFile._ensureTempStorageCleared = function(callback) 354 WebInspector.TempFile._ensureTempStorageCleared = function(callback)
362 { 355 {
363 if (!WebInspector.TempFile._storageCleaner) 356 if (!WebInspector.TempFile._storageCleaner)
364 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea ner(); 357 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea ner();
365 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback); 358 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback);
366 } 359 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/StylesSourceMapping.js ('k') | Source/devtools/front_end/sdk/TimelineManager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698