OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 function cacheEntrySize(entry, successCallback, opt_errorCallback, opt_sync) { | 298 function cacheEntrySize(entry, successCallback, opt_errorCallback, opt_sync) { |
299 if (entry.isDirectory) { | 299 if (entry.isDirectory) { |
300 // No size for a directory, -1 ensures it's sorted before 0 length files. | 300 // No size for a directory, -1 ensures it's sorted before 0 length files. |
301 entry.cachedSize_ = -1; | 301 entry.cachedSize_ = -1; |
302 } | 302 } |
303 | 303 |
304 if ('cachedSize_' in entry) { | 304 if ('cachedSize_' in entry) { |
305 invokeCallback(successCallback, !!opt_sync, entry); | 305 invokeCallback(successCallback, !!opt_sync, entry); |
306 return; | 306 return; |
307 } | 307 } |
308 | |
309 batchAsyncCall(entry, 'file', function(file) { | |
310 entry.cachedSize_ = file.size; | |
311 if (successCallback) | |
312 successCallback(entry); | |
313 }, opt_errorCallback); | |
314 } | 308 } |
315 | 309 |
316 /** | 310 /** |
317 * Get the mtime of a file, caching the result. | 311 * Get the mtime of a file, caching the result. |
318 * | 312 * |
319 * When this method completes, the fileEntry object will get a | 313 * When this method completes, the fileEntry object will get a |
320 * 'cachedMtime_' property (if it doesn't already have one) containing the | 314 * 'cachedMtime_' property (if it doesn't already have one) containing the |
321 * last modified time of the file as a Date object. | 315 * last modified time of the file as a Date object. |
322 * | 316 * |
323 * @param {Entry} entry An HTML5 Entry object. | 317 * @param {Entry} entry An HTML5 Entry object. |
324 * @param {function(Entry)} successCallback The function to invoke once the | 318 * @param {function(Entry)} successCallback The function to invoke once the |
325 * mtime is known. | 319 * mtime is known. |
326 * @param {function=} opt_errorCallback Error callback. | 320 * @param {function=} opt_errorCallback Error callback. |
327 * @param {boolean=} opt_sync True, if callback should be called sync instead | 321 * @param {boolean=} opt_sync True, if callback should be called sync instead |
328 * of async. | 322 * of async. |
329 */ | 323 */ |
330 function cacheEntryDate(entry, successCallback, opt_errorCallback, opt_sync) { | 324 function cacheEntryDate(entry, successCallback, opt_errorCallback, opt_sync) { |
331 if ('cachedMtime_' in entry) { | 325 if ('cachedMtime_' in entry) { |
332 invokeCallback(successCallback, !!opt_sync, entry); | 326 invokeCallback(successCallback, !!opt_sync, entry); |
333 return; | 327 return; |
334 } | 328 } |
335 | 329 |
336 if (entry.isFile) { | 330 if (entry.isFile) { |
337 batchAsyncCall(entry, 'file', function(file) { | 331 batchAsyncCall(entry, 'getMetadata', function(metadata) { |
338 entry.cachedMtime_ = file.lastModifiedDate; | 332 entry.cachedMtime_ = metadata.modificationTime; |
| 333 entry.cachedSize_ = metadata.size; |
339 if (successCallback) | 334 if (successCallback) |
340 successCallback(entry); | 335 successCallback(entry); |
341 }); | 336 }); |
342 } else { | 337 } else { |
343 batchAsyncCall(entry, 'getMetadata', function(metadata) { | 338 batchAsyncCall(entry, 'getMetadata', function(metadata) { |
344 entry.cachedMtime_ = metadata.modificationTime; | 339 entry.cachedMtime_ = metadata.modificationTime; |
345 if (successCallback) | 340 if (successCallback) |
346 successCallback(entry); | 341 successCallback(entry); |
347 }, opt_errorCallback); | 342 }, opt_errorCallback); |
348 } | 343 } |
(...skipping 3588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3937 }); | 3932 }); |
3938 }, onError); | 3933 }, onError); |
3939 | 3934 |
3940 function onError(err) { | 3935 function onError(err) { |
3941 console.log('Error while checking free space: ' + err); | 3936 console.log('Error while checking free space: ' + err); |
3942 setTimeout(doCheck, 1000 * 60); | 3937 setTimeout(doCheck, 1000 * 60); |
3943 } | 3938 } |
3944 } | 3939 } |
3945 } | 3940 } |
3946 })(); | 3941 })(); |
OLD | NEW |