private_api_file_system.h revision f2477e01787aa58f445919b809d89e252beef54f
1// Copyright 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. 4// 5// This file provides file system related API functions. 6 7#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_ 8#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_ 9 10#include <string> 11 12#include "base/platform_file.h" 13#include "chrome/browser/chromeos/drive/file_errors.h" 14#include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" 15 16class GURL; 17 18namespace base { 19class FilePath; 20} 21 22namespace fileapi { 23class FileSystemContext; 24} 25 26namespace extensions { 27 28// Implements the chrome.fileBrowserPrivate.requestFileSystem method. 29class FileBrowserPrivateRequestFileSystemFunction 30 : public LoggedAsyncExtensionFunction { 31 public: 32 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem", 33 FILEBROWSERPRIVATE_REQUESTFILESYSTEM) 34 35 protected: 36 virtual ~FileBrowserPrivateRequestFileSystemFunction() {} 37 38 // AsyncExtensionFunction overrides. 39 virtual bool RunImpl() OVERRIDE; 40 41 private: 42 void RespondSuccessOnUIThread(const std::string& name, 43 const GURL& root_url); 44 void RespondFailedOnUIThread(base::PlatformFileError error_code); 45 46 // Called when something goes wrong. Records the error to |error_| per the 47 // error code and reports that the private API function failed. 48 void DidFail(base::PlatformFileError error_code); 49 50 // Sets up file system access permissions to the extension identified by 51 // |child_id|. 52 bool SetupFileSystemAccessPermissions( 53 scoped_refptr<fileapi::FileSystemContext> file_system_context, 54 int child_id, 55 scoped_refptr<const extensions::Extension> extension); 56}; 57 58// Base class for FileBrowserPrivateAddFileWatchFunction and 59// FileBrowserPrivateRemoveFileWatchFunction. Although it's called "FileWatch", 60// the class and its sub classes are used only for watching changes in 61// directories. 62class FileWatchFunctionBase : public LoggedAsyncExtensionFunction { 63 protected: 64 virtual ~FileWatchFunctionBase() {} 65 66 // Performs a file watch operation (ex. adds or removes a file watch). 67 virtual void PerformFileWatchOperation( 68 const base::FilePath& local_path, 69 const base::FilePath& virtual_path, 70 const std::string& extension_id) = 0; 71 72 // AsyncExtensionFunction overrides. 73 virtual bool RunImpl() OVERRIDE; 74 75 // Calls SendResponse() with |success| converted to base::Value. 76 void Respond(bool success); 77}; 78 79// Implements the chrome.fileBrowserPrivate.addFileWatch method. 80// Starts watching changes in directories. 81class FileBrowserPrivateAddFileWatchFunction : public FileWatchFunctionBase { 82 public: 83 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch", 84 FILEBROWSERPRIVATE_ADDFILEWATCH) 85 86 protected: 87 virtual ~FileBrowserPrivateAddFileWatchFunction() {} 88 89 // FileWatchFunctionBase override. 90 virtual void PerformFileWatchOperation( 91 const base::FilePath& local_path, 92 const base::FilePath& virtual_path, 93 const std::string& extension_id) OVERRIDE; 94}; 95 96 97// Implements the chrome.fileBrowserPrivate.removeFileWatch method. 98// Stops watching changes in directories. 99class FileBrowserPrivateRemoveFileWatchFunction : public FileWatchFunctionBase { 100 public: 101 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch", 102 FILEBROWSERPRIVATE_REMOVEFILEWATCH) 103 104 protected: 105 virtual ~FileBrowserPrivateRemoveFileWatchFunction() {} 106 107 // FileWatchFunctionBase override. 108 virtual void PerformFileWatchOperation( 109 const base::FilePath& local_path, 110 const base::FilePath& virtual_path, 111 const std::string& extension_id) OVERRIDE; 112}; 113 114// Implements the chrome.fileBrowserPrivate.getSizeStats method. 115class FileBrowserPrivateGetSizeStatsFunction 116 : public LoggedAsyncExtensionFunction { 117 public: 118 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats", 119 FILEBROWSERPRIVATE_GETSIZESTATS) 120 121 protected: 122 virtual ~FileBrowserPrivateGetSizeStatsFunction() {} 123 124 // AsyncExtensionFunction overrides. 125 virtual bool RunImpl() OVERRIDE; 126 127 private: 128 void GetDriveAvailableSpaceCallback(drive::FileError error, 129 int64 bytes_total, 130 int64 bytes_used); 131 132 void GetSizeStatsCallback(const uint64* total_size, 133 const uint64* remaining_size); 134}; 135 136// Implements the chrome.fileBrowserPrivate.validatePathNameLength method. 137class FileBrowserPrivateValidatePathNameLengthFunction 138 : public LoggedAsyncExtensionFunction { 139 public: 140 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength", 141 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH) 142 143 protected: 144 virtual ~FileBrowserPrivateValidatePathNameLengthFunction() {} 145 146 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length); 147 148 // AsyncExtensionFunction overrides. 149 virtual bool RunImpl() OVERRIDE; 150}; 151 152// Implements the chrome.fileBrowserPrivate.formatVolume method. 153// Formats Volume given its mount path. 154class FileBrowserPrivateFormatVolumeFunction 155 : public LoggedAsyncExtensionFunction { 156 public: 157 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatVolume", 158 FILEBROWSERPRIVATE_FORMATVOLUME) 159 160 protected: 161 virtual ~FileBrowserPrivateFormatVolumeFunction() {} 162 163 // AsyncExtensionFunction overrides. 164 virtual bool RunImpl() OVERRIDE; 165}; 166 167// Implements the chrome.fileBrowserPrivate.startCopy method. 168class FileBrowserPrivateStartCopyFunction 169 : public LoggedAsyncExtensionFunction { 170 public: 171 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.startCopy", 172 FILEBROWSERPRIVATE_STARTCOPY) 173 174 protected: 175 virtual ~FileBrowserPrivateStartCopyFunction() {} 176 177 // AsyncExtensionFunction overrides. 178 virtual bool RunImpl() OVERRIDE; 179 180 private: 181 // Part of RunImpl(). Called after Copy() is started on IO thread. 182 void RunAfterStartCopy(int operation_id); 183}; 184 185// Implements the chrome.fileBrowserPrivate.cancelCopy method. 186class FileBrowserPrivateCancelCopyFunction 187 : public LoggedAsyncExtensionFunction { 188 public: 189 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelCopy", 190 FILEBROWSERPRIVATE_CANCELCOPY) 191 192 protected: 193 virtual ~FileBrowserPrivateCancelCopyFunction() {} 194 195 // AsyncExtensionFunction overrides. 196 virtual bool RunImpl() OVERRIDE; 197}; 198 199} // namespace extensions 200 201#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_ 202