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 <map> |
8 #include <string> | 9 #include <string> |
| 10 #include <vector> |
9 | 11 |
10 #include "base/callback.h" | 12 #include "base/callback.h" |
11 #include "base/files/file.h" | 13 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" |
| 18 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_obse
rver.h" |
15 #include "storage/browser/fileapi/async_file_util.h" | 19 #include "storage/browser/fileapi/async_file_util.h" |
16 | 20 |
17 class EventRouter; | 21 class EventRouter; |
18 | 22 |
19 namespace base { | 23 namespace base { |
20 class Time; | 24 class Time; |
21 } // namespace base | 25 } // namespace base |
22 | 26 |
23 namespace net { | 27 namespace net { |
24 class IOBuffer; | 28 class IOBuffer; |
25 } // namespace net | 29 } // namespace net |
26 | 30 |
27 namespace chromeos { | 31 namespace chromeos { |
28 namespace file_system_provider { | 32 namespace file_system_provider { |
29 | 33 |
30 class ProvidedFileSystemInfo; | 34 class ProvidedFileSystemInfo; |
31 class RequestManager; | 35 class RequestManager; |
32 | 36 |
33 // Represents metadata for either a file or a directory. Returned by GetMetadata | 37 // Represents metadata for either a file or a directory. |
34 // method in ProvidedFileSystemInterface. | |
35 struct EntryMetadata { | 38 struct EntryMetadata { |
36 EntryMetadata(); | 39 EntryMetadata(); |
37 ~EntryMetadata(); | 40 ~EntryMetadata(); |
38 | 41 |
39 bool is_directory; | 42 bool is_directory; |
40 std::string name; | 43 std::string name; |
41 int64 size; | 44 int64 size; |
42 base::Time modification_time; | 45 base::Time modification_time; |
43 std::string mime_type; | 46 std::string mime_type; |
44 std::string thumbnail; | 47 std::string thumbnail; |
45 | 48 |
46 private: | 49 private: |
47 DISALLOW_COPY_AND_ASSIGN(EntryMetadata); | 50 DISALLOW_COPY_AND_ASSIGN(EntryMetadata); |
48 }; | 51 }; |
49 | 52 |
50 // Interface for a provided file system. Acts as a proxy between providers | 53 // Interface for a provided file system. Acts as a proxy between providers |
51 // and clients. All of the request methods return an abort callback in order to | 54 // and clients. All of the request methods return an abort callback in order to |
52 // terminate it while running. They must be called on the same thread as the | 55 // terminate it while running. They must be called on the same thread as the |
53 // request methods. The cancellation callback may be null if the operation | 56 // request methods. The cancellation callback may be null if the operation |
54 // fails synchronously. | 57 // fails synchronously. |
55 class ProvidedFileSystemInterface { | 58 class ProvidedFileSystemInterface { |
56 public: | 59 public: |
| 60 struct ObservedEntry; |
| 61 struct ChildChange; |
| 62 |
57 // Mode of opening a file. Used by OpenFile(). | 63 // Mode of opening a file. Used by OpenFile(). |
58 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE }; | 64 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE }; |
59 | 65 |
60 // Extra fields to be fetched with metadata. | 66 // Extra fields to be fetched with metadata. |
61 enum MetadataField { | 67 enum MetadataField { |
62 METADATA_FIELD_DEFAULT = 0, | 68 METADATA_FIELD_DEFAULT = 0, |
63 METADATA_FIELD_THUMBNAIL = 1 << 0 | 69 METADATA_FIELD_THUMBNAIL = 1 << 0 |
64 }; | 70 }; |
65 | 71 |
66 typedef base::Callback<void(int file_handle, base::File::Error result)> | 72 typedef base::Callback<void(int file_handle, base::File::Error result)> |
67 OpenFileCallback; | 73 OpenFileCallback; |
68 | 74 |
69 typedef base::Callback< | 75 typedef base::Callback< |
70 void(int chunk_length, bool has_more, base::File::Error result)> | 76 void(int chunk_length, bool has_more, base::File::Error result)> |
71 ReadChunkReceivedCallback; | 77 ReadChunkReceivedCallback; |
72 | 78 |
73 typedef base::Callback<void(scoped_ptr<EntryMetadata> entry_metadata, | 79 typedef base::Callback<void(scoped_ptr<EntryMetadata> entry_metadata, |
74 base::File::Error result)> GetMetadataCallback; | 80 base::File::Error result)> GetMetadataCallback; |
75 | 81 |
76 typedef base::Callback<void( | 82 typedef base::Callback<void( |
77 const storage::AsyncFileUtil::StatusCallback& callback)> AbortCallback; | 83 const storage::AsyncFileUtil::StatusCallback& callback)> AbortCallback; |
78 | 84 |
79 // Mask of fields requested from the GetMetadata() call. | 85 // Mask of fields requested from the GetMetadata() call. |
80 typedef int MetadataFieldMask; | 86 typedef int MetadataFieldMask; |
81 | 87 |
| 88 // List of observed entries. |
| 89 typedef std::map<base::FilePath, ObservedEntry> ObservedEntries; |
| 90 |
| 91 // Represents an observed entry on the file system. |
| 92 struct ObservedEntry { |
| 93 ObservedEntry(); |
| 94 ~ObservedEntry(); |
| 95 |
| 96 base::FilePath entry_path; |
| 97 bool recursive; |
| 98 std::string last_tag; |
| 99 }; |
| 100 |
82 virtual ~ProvidedFileSystemInterface() {} | 101 virtual ~ProvidedFileSystemInterface() {} |
83 | 102 |
84 // Requests unmounting of the file system. The callback is called when the | 103 // Requests unmounting of the file system. The callback is called when the |
85 // request is accepted or rejected, with an error code. | 104 // request is accepted or rejected, with an error code. |
86 virtual AbortCallback RequestUnmount( | 105 virtual AbortCallback RequestUnmount( |
87 const storage::AsyncFileUtil::StatusCallback& callback) = 0; | 106 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
88 | 107 |
89 // Requests metadata of the passed |entry_path|. It can be either a file | 108 // Requests metadata of the passed |entry_path|. It can be either a file |
90 // or a directory. All |fields| will be returned if supported. Note, that | 109 // or a directory. All |fields| will be returned if supported. Note, that |
91 // default fields are always returned. | 110 // default fields are always returned. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 const storage::AsyncFileUtil::StatusCallback& callback) = 0; | 182 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
164 | 183 |
165 // Requests writing to a file previously opened with |file_handle|. | 184 // Requests writing to a file previously opened with |file_handle|. |
166 virtual AbortCallback WriteFile( | 185 virtual AbortCallback WriteFile( |
167 int file_handle, | 186 int file_handle, |
168 net::IOBuffer* buffer, | 187 net::IOBuffer* buffer, |
169 int64 offset, | 188 int64 offset, |
170 int length, | 189 int length, |
171 const storage::AsyncFileUtil::StatusCallback& callback) = 0; | 190 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
172 | 191 |
| 192 // Requests observing a directory. |
| 193 virtual AbortCallback ObserveDirectory( |
| 194 const base::FilePath& directory_path, |
| 195 bool recursive, |
| 196 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
| 197 |
| 198 // Requests unobserving an entry, which is immediately removed from the |
| 199 // internal list, hence the operation is not abortable. |
| 200 virtual void UnobserveEntry( |
| 201 const base::FilePath& entry_path, |
| 202 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
| 203 |
| 204 // Notifies about changes to the observed entries within the file system. |
| 205 // Invoked by the file system implementation. Returns false if the |
| 206 // notification arguments are malformed or the entry is not observed anymore. |
| 207 virtual bool Notify( |
| 208 const base::FilePath& observed_path, |
| 209 ProvidedFileSystemObserver::ChangeType change_type, |
| 210 const ProvidedFileSystemObserver::ChildChanges& child_changes, |
| 211 const std::string& tag) = 0; |
| 212 |
173 // Returns a provided file system info for this file system. | 213 // Returns a provided file system info for this file system. |
174 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; | 214 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; |
175 | 215 |
| 216 // Returns a mutable list of observed entries. |
| 217 virtual ObservedEntries* GetObservedEntries() = 0; |
| 218 |
176 // Returns a request manager for the file system. | 219 // Returns a request manager for the file system. |
177 virtual RequestManager* GetRequestManager() = 0; | 220 virtual RequestManager* GetRequestManager() = 0; |
178 | 221 |
| 222 // Adds an observer on the file system. |
| 223 virtual void AddObserver(ProvidedFileSystemObserver* observer) = 0; |
| 224 |
| 225 // Removes an observer. |
| 226 virtual void RemoveObserver(ProvidedFileSystemObserver* observer) = 0; |
| 227 |
179 // Returns a weak pointer to this object. | 228 // Returns a weak pointer to this object. |
180 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0; | 229 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0; |
181 }; | 230 }; |
182 | 231 |
183 } // namespace file_system_provider | 232 } // namespace file_system_provider |
184 } // namespace chromeos | 233 } // namespace chromeos |
185 | 234 |
186 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INT
ERFACE_H_ | 235 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INT
ERFACE_H_ |
OLD | NEW |