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;
11 * Wallpaper directories enum.
13 /** @const */ var WallpaperDirNameEnum = {
15 THUMBNAIL: 'thumbnail'
18 var wallpaperDirectories = null;
21 * Manages custom wallpaper related directories in wallpaper's sandboxed
25 function WallpaperDirectories() {
26 this.wallpaperDirs_ = {};
27 this.wallpaperDirs_[WallpaperDirNameEnum.ORIGINAL] = null;
28 this.wallpaperDirs_[WallpaperDirNameEnum.THUMBNAIL] = null;
32 * Gets WallpaperDirectories instance. In case is hasn't been initialized, a new
33 * instance is created.
34 * @return {WallpaperDirectories} A WallpaperDirectories instance.
36 WallpaperDirectories.getInstance = function() {
37 if (wallpaperDirectories === null)
38 wallpaperDirectories = new WallpaperDirectories();
39 return wallpaperDirectories;
42 WallpaperDirectories.prototype = {
44 * Returns all custom wallpaper related directory entries.
47 return this.wallpaperDirs_;
51 * If dirName is not requested, gets the directory entry of dirName and cache
52 * the result. Calls success callback if success.
53 * @param {string} dirName The directory name of requested directory entry.
54 * @param {function(DirectoryEntry):void} success Call success with requested
56 * @param {function(e):void} failure Call failure when failed to get the
57 * requested directory.
59 requestDir: function(dirName, success, failure) {
60 if (dirName != WallpaperDirNameEnum.ORIGINAL &&
61 dirName != WallpaperDirNameEnum.THUMBNAIL) {
62 console.error('Error: Unknow directory name.');
64 e.code = FileError.NOT_FOUND_ERR;
69 window.webkitRequestFileSystem(window.PERSISTENT, WallpaperQuota,
71 fs.root.getDirectory(dirName, {create: true}, function(dirEntry) {
72 self.wallpaperDirs_[dirName] = dirEntry;
79 * Gets DirectoryEntry associated with dirName from cache. If not in cache try
80 * to request it from FileSystem.
81 * @param {string} dirName The directory name of requested directory entry.
82 * @param {function(DirectoryEntry):void} success Call success with requested
84 * @param {function(e):void} failure Call failure when failed to get the
85 * requested directory.
87 getDirectory: function(dirName, success, failure) {
88 if (this.wallpaperDirs[dirName])
89 success(this.wallpaperDirs[dirName]);
91 this.requestDir(dirName, success, failure);