cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / wallpaper_manager / js / wallpaper_directories.js
blobdfb9158ad1a9c13037d827e024899f946b2db9e2
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * Wallpaper file system quota.
7 */
8 /** @const */ var WallpaperQuota = 1024 * 1024 * 100;
10 var wallpaperDirectories = null;
12 /**
13 * Manages custom wallpaper related directories in wallpaper's sandboxed
14 * FileSystem.
15 * @constructor
17 function WallpaperDirectories() {
18 this.wallpaperDirs_ = {};
19 this.wallpaperDirs_[Constants.WallpaperDirNameEnum.ORIGINAL] = null;
20 this.wallpaperDirs_[Constants.WallpaperDirNameEnum.THUMBNAIL] = null;
23 /**
24 * Gets WallpaperDirectories instance. In case is hasn't been initialized, a new
25 * instance is created.
26 * @return {WallpaperDirectories} A WallpaperDirectories instance.
28 WallpaperDirectories.getInstance = function() {
29 if (wallpaperDirectories === null)
30 wallpaperDirectories = new WallpaperDirectories();
31 return wallpaperDirectories;
34 WallpaperDirectories.prototype = {
35 /**
36 * Returns all custom wallpaper related directory entries.
38 get wallpaperDirs() {
39 return this.wallpaperDirs_;
42 /**
43 * If dirName is not requested, gets the directory entry of dirName and cache
44 * the result. Calls success callback if success.
45 * @param {string} dirName The directory name of requested directory entry.
46 * @param {function(DirectoryEntry):void} success Call success with requested
47 * DirectoryEntry.
48 * @param {function(e):void} failure Call failure when failed to get the
49 * requested directory.
51 requestDir: function(dirName, success, failure) {
52 if (dirName != Constants.WallpaperDirNameEnum.ORIGINAL &&
53 dirName != Constants.WallpaperDirNameEnum.THUMBNAIL) {
54 console.error('Error: Unknow directory name.');
55 var e = new Error();
56 e.code = FileError.NOT_FOUND_ERR;
57 failure(e);
58 return;
60 var self = this;
61 window.webkitRequestFileSystem(window.PERSISTENT, WallpaperQuota,
62 function(fs) {
63 fs.root.getDirectory(dirName, {create: true}, function(dirEntry) {
64 self.wallpaperDirs_[dirName] = dirEntry;
65 success(dirEntry);
66 }, failure);
67 }, failure);
70 /**
71 * Gets DirectoryEntry associated with dirName from cache. If not in cache try
72 * to request it from FileSystem.
73 * @param {string} dirName The directory name of requested directory entry.
74 * @param {function(DirectoryEntry):void} success Call success with requested
75 * DirectoryEntry.
76 * @param {function(e):void} failure Call failure when failed to get the
77 * requested directory.
79 getDirectory: function(dirName, success, failure) {
80 if (this.wallpaperDirs[dirName])
81 success(this.wallpaperDirs[dirName]);
82 else
83 this.requestDir(dirName, success, failure);