OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERF
ACE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERF
ACE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERF
ACE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERF
ACE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 ~EntryMetadata(); | 36 ~EntryMetadata(); |
37 | 37 |
38 bool is_directory; | 38 bool is_directory; |
39 std::string name; | 39 std::string name; |
40 int64 size; | 40 int64 size; |
41 base::Time modification_time; | 41 base::Time modification_time; |
42 std::string mime_type; | 42 std::string mime_type; |
43 }; | 43 }; |
44 | 44 |
45 // Interface for a provided file system. Acts as a proxy between providers | 45 // Interface for a provided file system. Acts as a proxy between providers |
46 // and clients. | 46 // and clients. All of the request methods return an abort callback in order to |
47 // TODO(mtomasz): Add more methods once implemented. | 47 // terminate it while running. They must be called on the same thread as the |
| 48 // request methods. The cancellation callback may be null if the operation |
| 49 // fails synchronously. |
48 class ProvidedFileSystemInterface { | 50 class ProvidedFileSystemInterface { |
49 public: | 51 public: |
50 typedef base::Callback<void(int file_handle, base::File::Error result)> | 52 typedef base::Callback<void(int file_handle, base::File::Error result)> |
51 OpenFileCallback; | 53 OpenFileCallback; |
52 | 54 |
53 typedef base::Callback< | 55 typedef base::Callback< |
54 void(int chunk_length, bool has_more, base::File::Error result)> | 56 void(int chunk_length, bool has_more, base::File::Error result)> |
55 ReadChunkReceivedCallback; | 57 ReadChunkReceivedCallback; |
56 | 58 |
57 typedef base::Callback<void(const EntryMetadata& entry_metadata, | 59 typedef base::Callback<void(const EntryMetadata& entry_metadata, |
58 base::File::Error result)> GetMetadataCallback; | 60 base::File::Error result)> GetMetadataCallback; |
59 | 61 |
| 62 typedef base::Callback<void( |
| 63 const fileapi::AsyncFileUtil::StatusCallback& callback)> AbortCallback; |
| 64 |
60 // Mode of opening a file. Used by OpenFile(). | 65 // Mode of opening a file. Used by OpenFile(). |
61 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE }; | 66 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE }; |
62 | 67 |
63 virtual ~ProvidedFileSystemInterface() {} | 68 virtual ~ProvidedFileSystemInterface() {} |
64 | 69 |
65 // Requests unmounting of the file system. The callback is called when the | 70 // Requests unmounting of the file system. The callback is called when the |
66 // request is accepted or rejected, with an error code. | 71 // request is accepted or rejected, with an error code. |
67 virtual void RequestUnmount( | 72 virtual AbortCallback RequestUnmount( |
68 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 73 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
69 | 74 |
70 // Requests metadata of the passed |entry_path|. It can be either a file | 75 // Requests metadata of the passed |entry_path|. It can be either a file |
71 // or a directory. | 76 // or a directory. |
72 virtual void GetMetadata(const base::FilePath& entry_path, | 77 virtual AbortCallback GetMetadata(const base::FilePath& entry_path, |
73 const GetMetadataCallback& callback) = 0; | 78 const GetMetadataCallback& callback) = 0; |
74 | 79 |
75 // Requests enumerating entries from the passed |directory_path|. The callback | 80 // Requests enumerating entries from the passed |directory_path|. The callback |
76 // can be called multiple times until |has_more| is set to false. | 81 // can be called multiple times until |has_more| is set to false. |
77 virtual void ReadDirectory( | 82 virtual AbortCallback ReadDirectory( |
78 const base::FilePath& directory_path, | 83 const base::FilePath& directory_path, |
79 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) = 0; | 84 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) = 0; |
80 | 85 |
81 // Requests opening a file at |file_path|. If the file doesn't exist, then the | 86 // Requests opening a file at |file_path|. If the file doesn't exist, then the |
82 // operation will fail. | 87 // operation will fail. |
83 virtual void OpenFile(const base::FilePath& file_path, | 88 virtual AbortCallback OpenFile(const base::FilePath& file_path, |
84 OpenFileMode mode, | 89 OpenFileMode mode, |
85 const OpenFileCallback& callback) = 0; | 90 const OpenFileCallback& callback) = 0; |
86 | 91 |
87 // Requests closing a file, previously opened with OpenFile() as a file with | 92 // Requests closing a file, previously opened with OpenFile() as a file with |
88 // |file_handle|. For either succes or error |callback| must be called. | 93 // |file_handle|. For either succes or error |callback| must be called. |
89 virtual void CloseFile( | 94 virtual AbortCallback CloseFile( |
90 int file_handle, | 95 int file_handle, |
91 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 96 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
92 | 97 |
93 // Requests reading a file previously opened with |file_handle|. The callback | 98 // Requests reading a file previously opened with |file_handle|. The callback |
94 // can be called multiple times until |has_more| is set to false. On success | 99 // can be called multiple times until |has_more| is set to false. On success |
95 // it should return |length| bytes starting from |offset| in total. It can | 100 // it should return |length| bytes starting from |offset| in total. It can |
96 // return less only in case EOF is encountered. | 101 // return less only in case EOF is encountered. |
97 virtual void ReadFile(int file_handle, | 102 virtual AbortCallback ReadFile(int file_handle, |
98 net::IOBuffer* buffer, | 103 net::IOBuffer* buffer, |
99 int64 offset, | 104 int64 offset, |
100 int length, | 105 int length, |
101 const ReadChunkReceivedCallback& callback) = 0; | 106 const ReadChunkReceivedCallback& callback) = 0; |
102 | 107 |
103 // Requests creating a directory. If |recursive| is passed, then all non | 108 // Requests creating a directory. If |recursive| is passed, then all non |
104 // existing directories on the path will be created. If |exclusive| is true, | 109 // existing directories on the path will be created. If |exclusive| is true, |
105 // then creating the directory will fail, if it already exists. | 110 // then creating the directory will fail, if it already exists. |
106 virtual void CreateDirectory( | 111 virtual AbortCallback CreateDirectory( |
107 const base::FilePath& directory_path, | 112 const base::FilePath& directory_path, |
108 bool exclusive, | 113 bool exclusive, |
109 bool recursive, | 114 bool recursive, |
110 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 115 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
111 | 116 |
112 // Requests creating a file. If the entry already exists, then the | 117 // Requests creating a file. If the entry already exists, then the |
113 // FILE_ERROR_EXISTS error must be returned. | 118 // FILE_ERROR_EXISTS error must be returned. |
114 virtual void CreateFile( | 119 virtual AbortCallback CreateFile( |
115 const base::FilePath& file_path, | 120 const base::FilePath& file_path, |
116 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 121 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
117 | 122 |
118 // Requests deleting a directory. If |recursive| is passed and the entry is | 123 // Requests deleting a directory. If |recursive| is passed and the entry is |
119 // a directory, then all contents of it (recursively) will be deleted too. | 124 // a directory, then all contents of it (recursively) will be deleted too. |
120 virtual void DeleteEntry( | 125 virtual AbortCallback DeleteEntry( |
121 const base::FilePath& entry_path, | 126 const base::FilePath& entry_path, |
122 bool recursive, | 127 bool recursive, |
123 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 128 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
124 | 129 |
125 // Requests copying an entry (recursively in case of a directory) within the | 130 // Requests copying an entry (recursively in case of a directory) within the |
126 // same file system. | 131 // same file system. |
127 virtual void CopyEntry( | 132 virtual AbortCallback CopyEntry( |
128 const base::FilePath& source_path, | 133 const base::FilePath& source_path, |
129 const base::FilePath& target_path, | 134 const base::FilePath& target_path, |
130 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 135 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
131 | 136 |
132 // Requests moving an entry (recursively in case of a directory) within the | 137 // Requests moving an entry (recursively in case of a directory) within the |
133 // same file system. | 138 // same file system. |
134 virtual void MoveEntry( | 139 virtual AbortCallback MoveEntry( |
135 const base::FilePath& source_path, | 140 const base::FilePath& source_path, |
136 const base::FilePath& target_path, | 141 const base::FilePath& target_path, |
137 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 142 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
138 | 143 |
139 // Requests truncating a file to the desired length. | 144 // Requests truncating a file to the desired length. |
140 virtual void Truncate( | 145 virtual AbortCallback Truncate( |
141 const base::FilePath& file_path, | 146 const base::FilePath& file_path, |
142 int64 length, | 147 int64 length, |
143 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 148 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
144 | 149 |
145 // Requests writing to a file previously opened with |file_handle|. | 150 // Requests writing to a file previously opened with |file_handle|. |
146 virtual void WriteFile( | 151 virtual AbortCallback WriteFile( |
147 int file_handle, | 152 int file_handle, |
148 net::IOBuffer* buffer, | 153 net::IOBuffer* buffer, |
149 int64 offset, | 154 int64 offset, |
150 int length, | 155 int length, |
151 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; | 156 const fileapi::AsyncFileUtil::StatusCallback& callback) = 0; |
152 | 157 |
153 // Returns a provided file system info for this file system. | 158 // Returns a provided file system info for this file system. |
154 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; | 159 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; |
155 | 160 |
156 // Returns a request manager for the file system. | 161 // Returns a request manager for the file system. |
157 virtual RequestManager* GetRequestManager() = 0; | 162 virtual RequestManager* GetRequestManager() = 0; |
158 | 163 |
159 // Returns a weak pointer to this object. | 164 // Returns a weak pointer to this object. |
160 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0; | 165 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0; |
161 }; | 166 }; |
162 | 167 |
163 } // namespace file_system_provider | 168 } // namespace file_system_provider |
164 } // namespace chromeos | 169 } // namespace chromeos |
165 | 170 |
166 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INT
ERFACE_H_ | 171 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INT
ERFACE_H_ |
OLD | NEW |