1 // Copyright 2014 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 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERFACE_H_ 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERFACE_H_ 7 8 #include "base/callback.h" 9 #include "base/files/file.h" 10 #include "base/files/file_path.h" 11 #include "base/memory/weak_ptr.h" 12 #include "webkit/browser/fileapi/async_file_util.h" 13 14 class EventRouter; 15 16 namespace net { 17 class IOBuffer; 18 } // namespace net 19 20 namespace chromeos { 21 namespace file_system_provider { 22 23 class ProvidedFileSystemInfo; 24 class RequestManager; 25 26 // Interface for a provided file system. Acts as a proxy between providers 27 // and clients. 28 // TODO(mtomasz): Add more methods once implemented. 29 class ProvidedFileSystemInterface { 30 public: 31 typedef base::Callback<void(int file_handle, base::File::Error result)> 32 OpenFileCallback; 33 34 typedef base::Callback< 35 void(int chunk_length, bool has_more, base::File::Error result)> 36 ReadChunkReceivedCallback; 37 38 // Mode of opening a file. Used by OpenFile(). 39 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE }; 40 ~ProvidedFileSystemInterface()41 virtual ~ProvidedFileSystemInterface() {} 42 43 // Requests unmounting of the file system. The callback is called when the 44 // request is accepted or rejected, with an error code. 45 virtual void RequestUnmount( 46 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; 47 48 // Requests metadata of the passed |entry_path|. It can be either a file 49 // or a directory. 50 virtual void GetMetadata( 51 const base::FilePath& entry_path, 52 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) = 0; 53 54 // Requests enumerating entries from the passed |directory_path|. The callback 55 // can be called multiple times until |has_more| is set to false. 56 virtual void ReadDirectory( 57 const base::FilePath& directory_path, 58 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) = 0; 59 60 // Requests opening a file at |file_path|. If |create| is set to true, it will 61 // create a file and return success in case it didn't exist. 62 virtual void OpenFile(const base::FilePath& file_path, 63 OpenFileMode mode, 64 bool create, 65 const OpenFileCallback& callback) = 0; 66 67 // Requests closing a file, previously opened with OpenFile() as a file with 68 // |file_handle|. For either succes or error |callback| must be called. 69 virtual void CloseFile( 70 int file_handle, 71 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; 72 73 // Requests reading a file previously opened with |file_handle|. The callback 74 // can be called multiple times until |has_more| is set to false. On success 75 // it should return |length| bytes starting from |offset| in total. It can 76 // return less only in case EOF is encountered. 77 virtual void ReadFile(int file_handle, 78 net::IOBuffer* buffer, 79 int64 offset, 80 int length, 81 const ReadChunkReceivedCallback& callback) = 0; 82 83 // Returns a provided file system info for this file system. 84 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; 85 86 // Returns a request manager for the file system. 87 virtual RequestManager* GetRequestManager() = 0; 88 89 // Returns a weak pointer to this object. 90 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0; 91 }; 92 93 } // namespace file_system_provider 94 } // namespace chromeos 95 96 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERFACE_H_ 97