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.
6 * Wallpaper file system quota.
8 /** @const */ var WallpaperQuota = 1024 * 1024 * 100;
10 var wallpaperDirectories = null;
13 * Manages custom wallpaper related directories in wallpaper's sandboxed
17 function WallpaperDirectories() {
18 this.wallpaperDirs_ = {};
19 this.wallpaperDirs_[Constants.WallpaperDirNameEnum.ORIGINAL] = null;
20 this.wallpaperDirs_[Constants.WallpaperDirNameEnum.THUMBNAIL] = null;
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 = {
36 * Returns all custom wallpaper related directory entries.
39 return this.wallpaperDirs_;
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
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.');
56 e.code = FileError.NOT_FOUND_ERR;
61 window.webkitRequestFileSystem(window.PERSISTENT, WallpaperQuota,
63 fs.root.getDirectory(dirName, {create: true}, function(dirEntry) {
64 self.wallpaperDirs_[dirName] = dirEntry;
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
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]);
83 this.requestDir(dirName, success, failure);