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

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

Issue 136793008: Clear DevTools temp storage (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Comments addressed 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
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 callback(this); 100 callback(this);
101 } 101 }
102 } 102 }
103 103
104 function errorHandler(e) 104 function errorHandler(e)
105 { 105 {
106 WebInspector.log("Failed to create temp file " + e.code + " : " + e.mess age, 106 WebInspector.log("Failed to create temp file " + e.code + " : " + e.mess age,
107 WebInspector.ConsoleMessage.MessageLevel.Error); 107 WebInspector.ConsoleMessage.MessageLevel.Error);
108 callback(null); 108 callback(null);
109 } 109 }
110
110 var boundErrorHandler = errorHandler.bind(this) 111 var boundErrorHandler = errorHandler.bind(this)
111 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), errorHa ndler.bind(this)); 112 /**
113 * @this {WebInspector.TempFile}
114 */
115 function didClearTempStorage()
116 {
117 window.requestFileSystem(window.TEMPORARY, 10, didInitFs.bind(this), bou ndErrorHandler);
118 }
119 WebInspector.TempFile._ensureTempStorageCleared(didClearTempStorage.bind(thi s));
112 } 120 }
113 121
114 WebInspector.TempFile.prototype = { 122 WebInspector.TempFile.prototype = {
115 /** 123 /**
116 * @param {!string} data 124 * @param {!string} data
117 * @param {!function(boolean)} callback 125 * @param {!function(boolean)} callback
118 */ 126 */
119 write: function(data, callback) 127 write: function(data, callback)
120 { 128 {
121 var blob = new Blob([data], {type: 'text/plain'}); 129 var blob = new Blob([data], {type: 'text/plain'});
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 */ 186 */
179 getFile: function(callback) 187 getFile: function(callback)
180 { 188 {
181 function didFailToGetFile(error) 189 function didFailToGetFile(error)
182 { 190 {
183 WebInspector.log("Failed to load temp file: " + error.message, 191 WebInspector.log("Failed to load temp file: " + error.message,
184 WebInspector.ConsoleMessage.MessageLevel.Error); 192 WebInspector.ConsoleMessage.MessageLevel.Error);
185 callback(null); 193 callback(null);
186 } 194 }
187 this._fileEntry.file(callback, didFailToGetFile.bind(this)); 195 this._fileEntry.file(callback, didFailToGetFile.bind(this));
196 },
197
198 remove: function()
199 {
200 if (this._fileEntry)
201 this._fileEntry.remove(function() {});
188 } 202 }
189 } 203 }
190 204
191 /** 205 /**
192 * @constructor 206 * @constructor
193 * @param {!string} dirPath 207 * @param {!string} dirPath
194 * @param {!string} name 208 * @param {!string} name
195 */ 209 */
196 WebInspector.BufferedTempFileWriter = function(dirPath, name) 210 WebInspector.BufferedTempFileWriter = function(dirPath, name)
197 { 211 {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 286
273 _notifyFinished: function() 287 _notifyFinished: function()
274 { 288 {
275 this._isFinished = true; 289 this._isFinished = true;
276 if (this._tempFile) 290 if (this._tempFile)
277 this._tempFile.finishWriting(); 291 this._tempFile.finishWriting();
278 if (this._finishCallback) 292 if (this._finishCallback)
279 this._finishCallback(this._tempFile); 293 this._finishCallback(this._tempFile);
280 } 294 }
281 } 295 }
296
297 /**
298 * @constructor
299 */
300 WebInspector.TempStorageCleaner = function()
301 {
302 this._worker = new SharedWorker("TempStorageSharedWorker.js", "TempStorage") ;
303 this._callbacks = [];
304 this._worker.port.onmessage = this._handleMessage.bind(this);
305 this._worker.port.onerror = this._handleError.bind(this);
306 }
307
308 WebInspector.TempStorageCleaner.prototype = {
309 /**
310 * @param {!function()} callback
311 */
312 ensureStorageCleared: function(callback)
313 {
314 if (this._callbacks)
315 this._callbacks.push(callback);
316 else
317 callback();
318 },
319
320 _handleMessage: function(event)
321 {
322 if (event.data.type === "tempStorageCleared") {
323 if (event.data.error)
324 WebInspector.log(event.data.error, WebInspector.ConsoleMessage.M essageLevel.Error);
325 this._notifyCallbacks();
326 }
327 },
328
329 _handleError: function(event)
330 {
331 WebInspector.log(WebInspector.UIString("Failed to clear temp storage: %s ", event.data),
332 WebInspector.ConsoleMessage.MessageLevel.Error);
333 this._notifyCallbacks();
334 },
335
336 _notifyCallbacks: function()
337 {
338 var callbacks = this._callbacks;
339 this._callbacks = null;
340 for (var i = 0; i < callbacks.length; i++)
341 callbacks[i]();
342 }
343 }
344
345 /**
346 * @param {!function()} callback
347 */
348 WebInspector.TempFile._ensureTempStorageCleared = function(callback)
349 {
350 if (!WebInspector.TempFile._storageCleaner)
351 WebInspector.TempFile._storageCleaner = new WebInspector.TempStorageClea ner();
352 WebInspector.TempFile._storageCleaner.ensureStorageCleared(callback);
353 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ProfilesPanel.js ('k') | Source/devtools/front_end/TempStorageSharedWorker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698