OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ |
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 using base::PlatformFile; | 28 using base::PlatformFile; |
29 using base::PlatformFileError; | 29 using base::PlatformFileError; |
30 using base::PlatformFileInfo; | 30 using base::PlatformFileInfo; |
31 | 31 |
32 // This class provides asynchronous access to common file routines for the | 32 // This class provides asynchronous access to common file routines for the |
33 // FileSystem API. | 33 // FileSystem API. |
34 class FileSystemFileUtilProxy { | 34 class FileSystemFileUtilProxy { |
35 public: | 35 public: |
36 typedef base::FileUtilProxy::Entry Entry; | 36 typedef base::FileUtilProxy::Entry Entry; |
37 | 37 |
38 typedef base::FileUtilProxy::StatusCallback StatusCallback; | |
39 typedef base::Callback<void(PlatformFileError, | 38 typedef base::Callback<void(PlatformFileError, |
40 bool /* created */ | 39 bool /* created */ |
41 )> EnsureFileExistsCallback; | 40 )> EnsureFileExistsCallback; |
42 typedef base::Callback<void(PlatformFileError, | 41 typedef base::Callback<void(PlatformFileError, |
43 const PlatformFileInfo&, | 42 const PlatformFileInfo&, |
44 const FilePath& /* platform_path */ | 43 const FilePath& /* platform_path */ |
45 )> GetFileInfoCallback; | 44 )> GetFileInfoCallback; |
46 typedef base::Callback<void(PlatformFileError, | 45 typedef base::Callback<void(PlatformFileError, |
47 const std::vector<Entry>& | 46 const std::vector<Entry>& |
48 )> ReadDirectoryCallback; | 47 )> ReadDirectoryCallback; |
49 | 48 |
50 typedef Callback2<PlatformFileError /* error code */, | |
51 const FilePath& /* local_path, where possible */ | |
52 >::Type GetLocalPathCallback; | |
53 | |
54 // Ensures that the given |file_path| exist. This creates a empty new file | 49 // Ensures that the given |file_path| exist. This creates a empty new file |
55 // at |file_path| if the |file_path| does not exist. | 50 // at |file_path| if the |file_path| does not exist. |
56 // If a new file han not existed and is created at the |file_path|, | 51 // If a new file han not existed and is created at the |file_path|, |
57 // |created| of the callback argument is set true and |error code| | 52 // |created| of the callback argument is set true and |error code| |
58 // is set PLATFORM_FILE_OK. | 53 // is set PLATFORM_FILE_OK. |
59 // If the file already exists, |created| is set false and |error code| | 54 // If the file already exists, |created| is set false and |error code| |
60 // is set PLATFORM_FILE_OK. | 55 // is set PLATFORM_FILE_OK. |
61 // If the file hasn't existed but it couldn't be created for some other | 56 // If the file hasn't existed but it couldn't be created for some other |
62 // reasons, |created| is set false and |error code| indicates the error. | 57 // reasons, |created| is set false and |error code| indicates the error. |
63 static bool EnsureFileExists( | 58 static bool EnsureFileExists( |
64 const FileSystemOperationContext& context, | 59 const FileSystemOperationContext& context, |
65 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 60 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
66 const FilePath& file_path, | 61 const FilePath& file_path, |
67 const EnsureFileExistsCallback& callback); | 62 const EnsureFileExistsCallback& callback); |
68 | 63 |
69 // Maps virtual file patch to its local physical location. | |
70 static bool GetLocalPath( | |
71 const FileSystemOperationContext& context, | |
72 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
73 const FilePath& virtual_path, | |
74 GetLocalPathCallback* callback); | |
75 | |
76 // Retrieves the information about a file. It is invalid to pass NULL for the | 64 // Retrieves the information about a file. It is invalid to pass NULL for the |
77 // callback. | 65 // callback. |
78 static bool GetFileInfo( | 66 static bool GetFileInfo( |
79 const FileSystemOperationContext& context, | 67 const FileSystemOperationContext& context, |
80 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 68 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
81 const FilePath& file_path, | 69 const FilePath& file_path, |
82 const GetFileInfoCallback& callback); | 70 const GetFileInfoCallback& callback); |
83 | 71 |
84 static bool ReadDirectory(const FileSystemOperationContext& context, | 72 static bool ReadDirectory(const FileSystemOperationContext& context, |
85 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 73 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
86 const FilePath& file_path, | 74 const FilePath& file_path, |
87 const ReadDirectoryCallback& callback); | 75 const ReadDirectoryCallback& callback); |
88 | 76 |
89 // Creates directory at given path. It's an error to create | |
90 // if |exclusive| is true and dir already exists. | |
91 static bool CreateDirectory( | |
92 const FileSystemOperationContext& context, | |
93 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
94 const FilePath& file_path, | |
95 bool exclusive, | |
96 bool recursive, | |
97 const StatusCallback& callback); | |
98 | |
99 // Copies a file or a directory from |src_file_path| to |dest_file_path| | |
100 // Error cases: | |
101 // If destination file doesn't exist or destination's parent | |
102 // doesn't exists. | |
103 // If source dir exists but destination path is an existing file. | |
104 // If source file exists but destination path is an existing directory. | |
105 // If source is a parent of destination. | |
106 // If source doesn't exists. | |
107 static bool Copy(const FileSystemOperationContext& context, | |
108 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
109 const FilePath& src_file_path, | |
110 const FilePath& dest_file_path, | |
111 const StatusCallback& callback); | |
112 | |
113 // Moves a file or a directory from src_file_path to dest_file_path. | |
114 // Error cases are similar to Copy method's error cases. | |
115 static bool Move( | |
116 const FileSystemOperationContext& context, | |
117 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
118 const FilePath& src_file_path, | |
119 const FilePath& dest_file_path, | |
120 const StatusCallback& callback); | |
121 | |
122 // Deletes a file or a directory. | |
123 // It is an error to delete a non-empty directory with recursive=false. | |
124 static bool Delete(const FileSystemOperationContext& context, | |
125 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
126 const FilePath& file_path, | |
127 bool recursive, | |
128 const StatusCallback& callback); | |
129 | |
130 // Touches a file. The callback can be NULL. | |
131 static bool Touch( | |
132 const FileSystemOperationContext& context, | |
133 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
134 const FilePath& file_path, | |
135 const base::Time& last_access_time, | |
136 const base::Time& last_modified_time, | |
137 const StatusCallback& callback); | |
138 | |
139 // Truncates a file to the given length. If |length| is greater than the | |
140 // current length of the file, the file will be extended with zeroes. | |
141 // The callback can be NULL. | |
142 static bool Truncate( | |
143 const FileSystemOperationContext& context, | |
144 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
145 const FilePath& path, | |
146 int64 length, | |
147 const StatusCallback& callback); | |
148 | |
149 private: | 77 private: |
150 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy); | 78 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy); |
151 }; | 79 }; |
152 | 80 |
153 } // namespace fileapi | 81 } // namespace fileapi |
154 | 82 |
155 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ | 83 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ |
OLD | NEW |