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" |
15 #include "storage/browser/fileapi/async_file_util.h" | 18 #include "storage/browser/fileapi/async_file_util.h" |
16 | 19 |
17 class EventRouter; | 20 class EventRouter; |
18 | 21 |
19 namespace base { | 22 namespace base { |
20 class Time; | 23 class Time; |
21 } // namespace base | 24 } // namespace base |
22 | 25 |
23 namespace net { | 26 namespace net { |
24 class IOBuffer; | 27 class IOBuffer; |
25 } // namespace net | 28 } // namespace net |
26 | 29 |
27 namespace chromeos { | 30 namespace chromeos { |
28 namespace file_system_provider { | 31 namespace file_system_provider { |
29 | 32 |
30 class ProvidedFileSystemInfo; | 33 class ProvidedFileSystemInfo; |
31 class RequestManager; | 34 class RequestManager; |
32 | 35 |
33 // Represents metadata for either a file or a directory. Returned by GetMetadata | 36 // Represents metadata for either a file or a directory. |
34 // method in ProvidedFileSystemInterface. | |
35 struct EntryMetadata { | 37 struct EntryMetadata { |
36 EntryMetadata(); | 38 EntryMetadata(); |
37 ~EntryMetadata(); | 39 ~EntryMetadata(); |
38 | 40 |
39 bool is_directory; | 41 bool is_directory; |
40 std::string name; | 42 std::string name; |
41 int64 size; | 43 int64 size; |
42 base::Time modification_time; | 44 base::Time modification_time; |
43 std::string mime_type; | 45 std::string mime_type; |
44 std::string thumbnail; | 46 std::string thumbnail; |
45 | 47 |
46 private: | 48 private: |
47 DISALLOW_COPY_AND_ASSIGN(EntryMetadata); | 49 DISALLOW_COPY_AND_ASSIGN(EntryMetadata); |
48 }; | 50 }; |
49 | 51 |
50 // Interface for a provided file system. Acts as a proxy between providers | 52 // 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 | 53 // 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 | 54 // 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 | 55 // request methods. The cancellation callback may be null if the operation |
54 // fails synchronously. | 56 // fails synchronously. |
55 class ProvidedFileSystemInterface { | 57 class ProvidedFileSystemInterface { |
56 public: | 58 public: |
| 59 struct ObservedEntry; |
| 60 struct ChildChange; |
| 61 |
57 // Mode of opening a file. Used by OpenFile(). | 62 // Mode of opening a file. Used by OpenFile(). |
58 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE }; | 63 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE }; |
59 | 64 |
60 // Extra fields to be fetched with metadata. | 65 // Extra fields to be fetched with metadata. |
61 enum MetadataField { | 66 enum MetadataField { |
62 METADATA_FIELD_DEFAULT = 0, | 67 METADATA_FIELD_DEFAULT = 0, |
63 METADATA_FIELD_THUMBNAIL = 1 << 0 | 68 METADATA_FIELD_THUMBNAIL = 1 << 0 |
64 }; | 69 }; |
65 | 70 |
| 71 // Type of a change to an observed entry. |
| 72 enum ChangeType { CHANGED, DELETED }; |
| 73 |
66 typedef base::Callback<void(int file_handle, base::File::Error result)> | 74 typedef base::Callback<void(int file_handle, base::File::Error result)> |
67 OpenFileCallback; | 75 OpenFileCallback; |
68 | 76 |
69 typedef base::Callback< | 77 typedef base::Callback< |
70 void(int chunk_length, bool has_more, base::File::Error result)> | 78 void(int chunk_length, bool has_more, base::File::Error result)> |
71 ReadChunkReceivedCallback; | 79 ReadChunkReceivedCallback; |
72 | 80 |
73 typedef base::Callback<void(scoped_ptr<EntryMetadata> entry_metadata, | 81 typedef base::Callback<void(scoped_ptr<EntryMetadata> entry_metadata, |
74 base::File::Error result)> GetMetadataCallback; | 82 base::File::Error result)> GetMetadataCallback; |
75 | 83 |
76 typedef base::Callback<void( | 84 typedef base::Callback<void( |
77 const storage::AsyncFileUtil::StatusCallback& callback)> AbortCallback; | 85 const storage::AsyncFileUtil::StatusCallback& callback)> AbortCallback; |
78 | 86 |
79 // Mask of fields requested from the GetMetadata() call. | 87 // Mask of fields requested from the GetMetadata() call. |
80 typedef int MetadataFieldMask; | 88 typedef int MetadataFieldMask; |
81 | 89 |
| 90 // List of observed entries. |
| 91 typedef std::map<base::FilePath, ObservedEntry> ObservedEntries; |
| 92 |
| 93 // Lust of child changes. |
| 94 typedef std::vector<ChildChange> ChildChanges; |
| 95 |
| 96 // Represents an observed entry on the file system. |
| 97 struct ObservedEntry { |
| 98 ObservedEntry(); |
| 99 ~ObservedEntry(); |
| 100 |
| 101 base::FilePath entry_path; |
| 102 bool recursive; |
| 103 std::string last_tag; |
| 104 }; |
| 105 |
| 106 // Describes a change in an entry contained in an observed directory. |
| 107 struct ChildChange { |
| 108 ChildChange(); |
| 109 ~ChildChange(); |
| 110 |
| 111 base::FilePath entry_path; |
| 112 ChangeType change_type; |
| 113 }; |
| 114 |
| 115 // Observer class to be notified about changes happened to the file system. |
| 116 class Observer { |
| 117 public: |
| 118 // Called when an observed entry is changed, including removals. |
| 119 virtual void OnEntryChanged( |
| 120 const base::FilePath& observed_path, |
| 121 ChangeType change_type, |
| 122 const std::vector<ChildChange>& child_changes) = 0; |
| 123 |
| 124 // Called when list of observed entries is changed. |
| 125 virtual void OnObservedEntriesListChanged() = 0; |
| 126 }; |
| 127 |
82 virtual ~ProvidedFileSystemInterface() {} | 128 virtual ~ProvidedFileSystemInterface() {} |
83 | 129 |
84 // Requests unmounting of the file system. The callback is called when the | 130 // Requests unmounting of the file system. The callback is called when the |
85 // request is accepted or rejected, with an error code. | 131 // request is accepted or rejected, with an error code. |
86 virtual AbortCallback RequestUnmount( | 132 virtual AbortCallback RequestUnmount( |
87 const storage::AsyncFileUtil::StatusCallback& callback) = 0; | 133 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
88 | 134 |
89 // Requests metadata of the passed |entry_path|. It can be either a file | 135 // 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 | 136 // or a directory. All |fields| will be returned if supported. Note, that |
91 // default fields are always returned. | 137 // 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; | 209 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
164 | 210 |
165 // Requests writing to a file previously opened with |file_handle|. | 211 // Requests writing to a file previously opened with |file_handle|. |
166 virtual AbortCallback WriteFile( | 212 virtual AbortCallback WriteFile( |
167 int file_handle, | 213 int file_handle, |
168 net::IOBuffer* buffer, | 214 net::IOBuffer* buffer, |
169 int64 offset, | 215 int64 offset, |
170 int length, | 216 int length, |
171 const storage::AsyncFileUtil::StatusCallback& callback) = 0; | 217 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
172 | 218 |
| 219 // Requests observing a directory. |
| 220 virtual AbortCallback ObserveDirectory( |
| 221 const base::FilePath& directory_path, |
| 222 bool recursive, |
| 223 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
| 224 |
| 225 // Requests unobserving an entry. |
| 226 virtual AbortCallback UnobserveEntry( |
| 227 const base::FilePath& entry_path, |
| 228 const storage::AsyncFileUtil::StatusCallback& callback) = 0; |
| 229 |
173 // Returns a provided file system info for this file system. | 230 // Returns a provided file system info for this file system. |
174 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; | 231 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; |
175 | 232 |
| 233 // Returns a mutable list of observed entries. |
| 234 virtual ObservedEntries* GetObservedEntries() = 0; |
| 235 |
176 // Returns a request manager for the file system. | 236 // Returns a request manager for the file system. |
177 virtual RequestManager* GetRequestManager() = 0; | 237 virtual RequestManager* GetRequestManager() = 0; |
178 | 238 |
| 239 // Adds an observer on the file system. |
| 240 virtual void AddObserver(Observer* observer) = 0; |
| 241 |
| 242 // Removes an observer. |
| 243 virtual void RemoveObserver(Observer* observer) = 0; |
| 244 |
| 245 // Gets a list of observers. |
| 246 virtual ObserverList<Observer>* GetObservers() = 0; |
| 247 |
179 // Returns a weak pointer to this object. | 248 // Returns a weak pointer to this object. |
180 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0; | 249 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0; |
181 }; | 250 }; |
182 | 251 |
183 } // namespace file_system_provider | 252 } // namespace file_system_provider |
184 } // namespace chromeos | 253 } // namespace chromeos |
185 | 254 |
186 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INT
ERFACE_H_ | 255 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INT
ERFACE_H_ |
OLD | NEW |