private_api_file_system.h revision 58537e28ecd584eab876aee8be7156509866d23a
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 FileBrowserPrivateRequestFileSystemFunction(); 36 37 protected: 38 virtual ~FileBrowserPrivateRequestFileSystemFunction(); 39 40 // AsyncExtensionFunction overrides. 41 virtual bool RunImpl() OVERRIDE; 42 43 private: 44 void RespondSuccessOnUIThread(const std::string& name, 45 const GURL& root_url); 46 void RespondFailedOnUIThread(base::PlatformFileError error_code); 47 48 // Called when FileSystemContext::OpenFileSystem() is done. 49 void DidOpenFileSystem( 50 scoped_refptr<fileapi::FileSystemContext> file_system_context, 51 base::PlatformFileError result, 52 const std::string& name, 53 const GURL& root_url); 54 55 // Called when something goes wrong. Records the error to |error_| per the 56 // error code and reports that the private API function failed. 57 void DidFail(base::PlatformFileError error_code); 58 59 // Sets up file system access permissions to the extension identified by 60 // |child_id|. 61 bool SetupFileSystemAccessPermissions( 62 scoped_refptr<fileapi::FileSystemContext> file_system_context, 63 int child_id, 64 scoped_refptr<const extensions::Extension> extension); 65}; 66 67// Base class for FileBrowserPrivateAddFileWatchFunction and 68// FileBrowserPrivateRemoveFileWatchFunction. Although it's called "FileWatch", 69// the class and its sub classes are used only for watching changes in 70// directories. 71class FileWatchFunctionBase : public LoggedAsyncExtensionFunction { 72 public: 73 FileWatchFunctionBase(); 74 75 protected: 76 virtual ~FileWatchFunctionBase(); 77 78 // Performs a file watch operation (ex. adds or removes a file watch). 79 virtual void PerformFileWatchOperation( 80 const base::FilePath& local_path, 81 const base::FilePath& virtual_path, 82 const std::string& extension_id) = 0; 83 84 // AsyncExtensionFunction overrides. 85 virtual bool RunImpl() OVERRIDE; 86 87 // Calls SendResponse() with |success| converted to base::Value. 88 void Respond(bool success); 89}; 90 91// Implements the chrome.fileBrowserPrivate.addFileWatch method. 92// Starts watching changes in directories. 93class FileBrowserPrivateAddFileWatchFunction : public FileWatchFunctionBase { 94 public: 95 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch", 96 FILEBROWSERPRIVATE_ADDFILEWATCH) 97 98 FileBrowserPrivateAddFileWatchFunction(); 99 100 protected: 101 virtual ~FileBrowserPrivateAddFileWatchFunction(); 102 103 // FileWatchFunctionBase override. 104 virtual void PerformFileWatchOperation( 105 const base::FilePath& local_path, 106 const base::FilePath& virtual_path, 107 const std::string& extension_id) OVERRIDE; 108}; 109 110 111// Implements the chrome.fileBrowserPrivate.removeFileWatch method. 112// Stops watching changes in directories. 113class FileBrowserPrivateRemoveFileWatchFunction : public FileWatchFunctionBase { 114 public: 115 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch", 116 FILEBROWSERPRIVATE_REMOVEFILEWATCH) 117 118 FileBrowserPrivateRemoveFileWatchFunction(); 119 120 protected: 121 virtual ~FileBrowserPrivateRemoveFileWatchFunction(); 122 123 // FileWatchFunctionBase override. 124 virtual void PerformFileWatchOperation( 125 const base::FilePath& local_path, 126 const base::FilePath& virtual_path, 127 const std::string& extension_id) OVERRIDE; 128}; 129 130// Implements the chrome.fileBrowserPrivate.setLastModified method. 131// Sets last modified date in seconds of local file 132class FileBrowserPrivateSetLastModifiedFunction 133 : public LoggedAsyncExtensionFunction { 134 public: 135 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setLastModified", 136 FILEBROWSERPRIVATE_SETLASTMODIFIED) 137 138 FileBrowserPrivateSetLastModifiedFunction(); 139 140 protected: 141 virtual ~FileBrowserPrivateSetLastModifiedFunction(); 142 143 // AsyncExtensionFunction overrides. 144 virtual bool RunImpl() OVERRIDE; 145}; 146 147// Implements the chrome.fileBrowserPrivate.getSizeStats method. 148class FileBrowserPrivateGetSizeStatsFunction 149 : public LoggedAsyncExtensionFunction { 150 public: 151 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats", 152 FILEBROWSERPRIVATE_GETSIZESTATS) 153 154 FileBrowserPrivateGetSizeStatsFunction(); 155 156 protected: 157 virtual ~FileBrowserPrivateGetSizeStatsFunction(); 158 159 // AsyncExtensionFunction overrides. 160 virtual bool RunImpl() OVERRIDE; 161 162 private: 163 void GetDriveAvailableSpaceCallback(drive::FileError error, 164 int64 bytes_total, 165 int64 bytes_used); 166 167 void GetSizeStatsCallback(const uint64* total_size, 168 const uint64* remaining_size); 169}; 170 171// Implements the chrome.fileBrowserPrivate.getVolumeMetadata method. 172// Retrieves devices meta-data. Expects volume's device path as an argument. 173class FileBrowserPrivateGetVolumeMetadataFunction 174 : public LoggedAsyncExtensionFunction { 175 public: 176 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getVolumeMetadata", 177 FILEBROWSERPRIVATE_GETVOLUMEMETADATA) 178 179 FileBrowserPrivateGetVolumeMetadataFunction(); 180 181 protected: 182 virtual ~FileBrowserPrivateGetVolumeMetadataFunction(); 183 184 // AsyncExtensionFunction overrides. 185 virtual bool RunImpl() OVERRIDE; 186}; 187 188// Implements the chrome.fileBrowserPrivate.validatePathNameLength method. 189class FileBrowserPrivateValidatePathNameLengthFunction 190 : public LoggedAsyncExtensionFunction { 191 public: 192 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength", 193 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH) 194 195 FileBrowserPrivateValidatePathNameLengthFunction(); 196 197 protected: 198 virtual ~FileBrowserPrivateValidatePathNameLengthFunction(); 199 200 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length); 201 202 // AsyncExtensionFunction overrides. 203 virtual bool RunImpl() OVERRIDE; 204}; 205 206// Implements the chrome.fileBrowserPrivate.formatDevice method. 207// Formats Device given its mount path. 208class FileBrowserPrivateFormatDeviceFunction 209 : public LoggedAsyncExtensionFunction { 210 public: 211 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatDevice", 212 FILEBROWSERPRIVATE_FORMATDEVICE) 213 214 FileBrowserPrivateFormatDeviceFunction(); 215 216 protected: 217 virtual ~FileBrowserPrivateFormatDeviceFunction(); 218 219 // AsyncExtensionFunction overrides. 220 virtual bool RunImpl() OVERRIDE; 221}; 222 223// Implements the chrome.fileBrowserPrivate.startCopy method. 224class FileBrowserPrivateStartCopyFunction 225 : public LoggedAsyncExtensionFunction { 226 public: 227 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.startCopy", 228 FILEBROWSERPRIVATE_STARTCOPY) 229 230 FileBrowserPrivateStartCopyFunction(); 231 232 protected: 233 virtual ~FileBrowserPrivateStartCopyFunction(); 234 235 // AsyncExtensionFunction overrides. 236 virtual bool RunImpl() OVERRIDE; 237 238 private: 239 // Part of RunImpl(). Called after Copy() is started on IO thread. 240 void RunAfterStartCopy(int operation_id); 241}; 242 243// Implements the chrome.fileBrowserPrivate.cancelCopy method. 244class FileBrowserPrivateCancelCopyFunction 245 : public LoggedAsyncExtensionFunction { 246 public: 247 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelCopy", 248 FILEBROWSERPRIVATE_CANCELCOPY) 249 250 FileBrowserPrivateCancelCopyFunction(); 251 252 protected: 253 virtual ~FileBrowserPrivateCancelCopyFunction(); 254 255 // AsyncExtensionFunction overrides. 256 virtual bool RunImpl() OVERRIDE; 257}; 258 259} // namespace extensions 260 261#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_ 262