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

Side by Side Diff: chrome/browser/resources/file_manager/js/util.js

Issue 7764011: File Manager: Assorted fixes and polish (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 /** 5 /**
6 * Namespace for utility functions. 6 * Namespace for utility functions.
7 */ 7 */
8 var util = { 8 var util = {
9 /** 9 /**
10 * Returns a function that console.log's its arguments, prefixed by |msg|. 10 * Returns a function that console.log's its arguments, prefixed by |msg|.
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } else { 247 } else {
248 errorCallback(err); 248 errorCallback(err);
249 } 249 }
250 }); 250 });
251 }, 251 },
252 252
253 /** 253 /**
254 * Locate the file referred to by path, creating directories or the file 254 * Locate the file referred to by path, creating directories or the file
255 * itself if necessary. 255 * itself if necessary.
256 */ 256 */
257 getOrCreateFile: function(path, successCallback, errorCallback) { 257 getOrCreateFile: function(root, path, successCallback, errorCallback) {
258 var dirname = null; 258 var dirname = null;
259 var basename = null; 259 var basename = null;
260 260
261 function onDirFound(dirEntry) { 261 function onDirFound(dirEntry) {
262 dirEntry.getFile(basename, { create: true }, 262 dirEntry.getFile(basename, { create: true },
263 successCallback, errorCallback); 263 successCallback, errorCallback);
264 } 264 }
265 265
266 var i = path.lastIndexOf('/'); 266 var i = path.lastIndexOf('/');
267 if (i > -1) { 267 if (i > -1) {
268 dirname = path.substr(0, i); 268 dirname = path.substr(0, i);
269 basename = path.substr(i + 1); 269 basename = path.substr(i + 1);
270 } else { 270 } else {
271 basename = path; 271 basename = path;
272 } 272 }
273 273
274 if (!dirname) 274 if (!dirname)
275 return onDirFound(this.filesystem.root); 275 return onDirFound(root);
276 276
277 this.getOrCreateDirectory(dirname, onDirFound, errorCallback); 277 util.getOrCreateDirectory(root, dirname, onDirFound, errorCallback);
278 }, 278 },
279 279
280 /** 280 /**
281 * Locate the directory referred to by path, creating directories along the 281 * Locate the directory referred to by path, creating directories along the
282 * way. 282 * way.
283 */ 283 */
284 getOrCreateDirectory: function(path, successCallback, errorCallback) { 284 getOrCreateDirectory: function(root, path, successCallback, errorCallback) {
285 var names = path.split('/'); 285 var names = path.split('/');
286 286
287 function getOrCreateNextName(dir) { 287 function getOrCreateNextName(dir) {
288 if (!names.length) 288 if (!names.length)
289 return successCallback(dir); 289 return successCallback(dir);
290 290
291 var name; 291 var name;
292 do { 292 do {
293 name = names.shift(); 293 name = names.shift();
294 } while (!name || name == '.'); 294 } while (!name || name == '.');
295 295
296 dir.getDirectory(name, { create: true }, getOrCreateNextName, 296 dir.getDirectory(name, { create: true }, getOrCreateNextName,
297 errorCallback); 297 errorCallback);
298 } 298 }
299 299
300 getOrCreateNextName(this.filesystem.root); 300 getOrCreateNextName(root);
301 }, 301 },
302 302
303 /** 303 /**
304 * Lookup tables used by bytesToSi. 304 * Lookup tables used by bytesToSi.
305 */ 305 */
306 units_: ['B', 'k', 'M', 'G', 'T', 'P'], 306 units_: ['B', 'k', 'M', 'G', 'T', 'P'],
307 scale_: [1, 1e3, 1e6, 1e9, 1e12, 1e15], 307 scale_: [1, 1e3, 1e6, 1e9, 1e12, 1e15],
308 308
309 /** 309 /**
310 * Convert a number of bytes into an appropriate International System of 310 * Convert a number of bytes into an appropriate International System of
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (typeof(arg) == 'string') { 384 if (typeof(arg) == 'string') {
385 element.appendChild(document.createTextNode(arg)); 385 element.appendChild(document.createTextNode(arg));
386 } else { 386 } else {
387 element.appendChild(arg); 387 element.appendChild(arg);
388 } 388 }
389 } 389 }
390 390
391 return element; 391 return element;
392 } 392 }
393 }; 393 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698