Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: base/file_util_proxy.h

Issue 4261001: Moving Entry from base::file_util_proxy namespace to within class base::FileU... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/file_util_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 BASE_FILE_UTIL_PROXY_H_ 5 #ifndef BASE_FILE_UTIL_PROXY_H_
6 #define BASE_FILE_UTIL_PROXY_H_ 6 #define BASE_FILE_UTIL_PROXY_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "base/tracked_objects.h" 15 #include "base/tracked_objects.h"
16 16
17 namespace base { 17 namespace base {
18 18
19 namespace file_util_proxy {
20
21 // Holds metadata for file or directory entry.
22 struct Entry {
23 FilePath::StringType name;
24 bool is_directory;
25 };
26
27 } // namespace file_util_proxy
28
29 class MessageLoopProxy; 19 class MessageLoopProxy;
30 class Time; 20 class Time;
31 21
32 // This class provides asynchronous access to common file routines. 22 // This class provides asynchronous access to common file routines.
33 class FileUtilProxy { 23 class FileUtilProxy {
34 public: 24 public:
25 // Holds metadata for file or directory entry.
kinuko 2010/11/02 03:31:53 Would be nice to mention that it's used by ReadDir
26 struct Entry {
27 FilePath::StringType name;
28 bool is_directory;
29 };
30
35 // This callback is used by methods that report only an error code. It is 31 // This callback is used by methods that report only an error code. It is
36 // valid to pass NULL as the callback parameter to any function that takes a 32 // valid to pass NULL as the callback parameter to any function that takes a
37 // StatusCallback, in which case the operation will complete silently. 33 // StatusCallback, in which case the operation will complete silently.
38 typedef Callback1<base::PlatformFileError /* error code */ 34 typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback;
39 >::Type StatusCallback;
40 35
41 // Creates or opens a file with the given flags. It is invalid to pass NULL 36 // Creates or opens a file with the given flags. It is invalid to pass NULL
42 // for the callback. 37 // for the callback.
43 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create 38 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create
44 // a new file at the given |file_path| and calls back with 39 // a new file at the given |file_path| and calls back with
45 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. 40 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists.
46 typedef Callback3<base::PlatformFileError /* error code */, 41 typedef Callback3<PlatformFileError /* error code */,
47 base::PassPlatformFile, 42 PassPlatformFile,
48 bool /* created */>::Type CreateOrOpenCallback; 43 bool /* created */>::Type CreateOrOpenCallback;
49 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, 44 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
50 const FilePath& file_path, 45 const FilePath& file_path,
51 int file_flags, 46 int file_flags,
52 CreateOrOpenCallback* callback); 47 CreateOrOpenCallback* callback);
53 48
54 // Creates a temporary file for writing. The path and an open file handle 49 // Creates a temporary file for writing. The path and an open file handle
55 // are returned. It is invalid to pass NULL for the callback. 50 // are returned. It is invalid to pass NULL for the callback.
56 typedef Callback3<base::PlatformFileError /* error code */, 51 typedef Callback3<PlatformFileError /* error code */,
57 base::PassPlatformFile, 52 PassPlatformFile,
58 FilePath>::Type CreateTemporaryCallback; 53 FilePath>::Type CreateTemporaryCallback;
59 static bool CreateTemporary( 54 static bool CreateTemporary(
60 scoped_refptr<MessageLoopProxy> message_loop_proxy, 55 scoped_refptr<MessageLoopProxy> message_loop_proxy,
61 CreateTemporaryCallback* callback); 56 CreateTemporaryCallback* callback);
62 57
63 // Close the given file handle. 58 // Close the given file handle.
64 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, 59 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
65 base::PlatformFile, 60 PlatformFile,
66 StatusCallback* callback); 61 StatusCallback* callback);
67 62
68 // Ensures that the given |file_path| exist. This creates a empty new file 63 // Ensures that the given |file_path| exist. This creates a empty new file
69 // at |file_path| if the |file_path| does not exist. 64 // at |file_path| if the |file_path| does not exist.
70 // If a new file han not existed and is created at the |file_path|, 65 // If a new file han not existed and is created at the |file_path|,
71 // |created| of the callback argument is set true and |error code| 66 // |created| of the callback argument is set true and |error code|
72 // is set PLATFORM_FILE_OK. 67 // is set PLATFORM_FILE_OK.
73 // If the file already exists, |created| is set false and |error code| 68 // If the file already exists, |created| is set false and |error code|
74 // is set PLATFORM_FILE_OK. 69 // is set PLATFORM_FILE_OK.
75 // If the file hasn't existed but it couldn't be created for some other 70 // If the file hasn't existed but it couldn't be created for some other
76 // reasons, |created| is set false and |error code| indicates the error. 71 // reasons, |created| is set false and |error code| indicates the error.
77 typedef Callback2<base::PlatformFileError /* error code */, 72 typedef Callback2<PlatformFileError /* error code */,
78 bool /* created */>::Type EnsureFileExistsCallback; 73 bool /* created */>::Type EnsureFileExistsCallback;
79 static bool EnsureFileExists( 74 static bool EnsureFileExists(
80 scoped_refptr<MessageLoopProxy> message_loop_proxy, 75 scoped_refptr<MessageLoopProxy> message_loop_proxy,
81 const FilePath& file_path, 76 const FilePath& file_path,
82 EnsureFileExistsCallback* callback); 77 EnsureFileExistsCallback* callback);
83 78
84 // Retrieves the information about a file. It is invalid to pass NULL for the 79 // Retrieves the information about a file. It is invalid to pass NULL for the
85 // callback. 80 // callback.
86 typedef Callback2<base::PlatformFileError /* error code */, 81 typedef Callback2<PlatformFileError /* error code */,
87 const base::PlatformFileInfo& /* file_info */ 82 const PlatformFileInfo& /* file_info */
88 >::Type GetFileInfoCallback; 83 >::Type GetFileInfoCallback;
89 static bool GetFileInfo( 84 static bool GetFileInfo(
90 scoped_refptr<MessageLoopProxy> message_loop_proxy, 85 scoped_refptr<MessageLoopProxy> message_loop_proxy,
91 const FilePath& file_path, 86 const FilePath& file_path,
92 GetFileInfoCallback* callback); 87 GetFileInfoCallback* callback);
93 88
94 static bool GetFileInfoFromPlatformFile( 89 static bool GetFileInfoFromPlatformFile(
95 scoped_refptr<MessageLoopProxy> message_loop_proxy, 90 scoped_refptr<MessageLoopProxy> message_loop_proxy,
96 base::PlatformFile file, 91 PlatformFile file,
97 GetFileInfoCallback* callback); 92 GetFileInfoCallback* callback);
98 93
99 typedef Callback2<base::PlatformFileError /* error code */, 94 typedef Callback2<PlatformFileError /* error code */,
100 const std::vector<base::file_util_proxy::Entry>& 95 const std::vector<Entry>&>::Type ReadDirectoryCallback;
kinuko 2010/11/02 03:31:53 nit: indent
101 >::Type ReadDirectoryCallback;
102 static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy, 96 static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy,
103 const FilePath& file_path, 97 const FilePath& file_path,
104 ReadDirectoryCallback* callback); 98 ReadDirectoryCallback* callback);
105 99
106 // Copies a file or a directory from |src_file_path| to |dest_file_path| 100 // Copies a file or a directory from |src_file_path| to |dest_file_path|
107 // Error cases: 101 // Error cases:
108 // If destination file doesn't exist or destination's parent 102 // If destination file doesn't exist or destination's parent
109 // doesn't exists. 103 // doesn't exists.
110 // If source dir exists but destination path is an existing file. 104 // If source dir exists but destination path is an existing file.
111 // If source file exists but destination path is an existing directory. 105 // If source file exists but destination path is an existing directory.
(...skipping 29 matching lines...) Expand all
141 StatusCallback* callback); 135 StatusCallback* callback);
142 136
143 // Deletes a directory and all of its contents. 137 // Deletes a directory and all of its contents.
144 static bool RecursiveDelete( 138 static bool RecursiveDelete(
145 scoped_refptr<MessageLoopProxy> message_loop_proxy, 139 scoped_refptr<MessageLoopProxy> message_loop_proxy,
146 const FilePath& file_path, 140 const FilePath& file_path,
147 StatusCallback* callback); 141 StatusCallback* callback);
148 142
149 // Reads from a file. On success, the file pointer is moved to position 143 // Reads from a file. On success, the file pointer is moved to position
150 // |offset + bytes_to_read| in the file. The callback can be NULL. 144 // |offset + bytes_to_read| in the file. The callback can be NULL.
151 typedef Callback2<base::PlatformFileError /* error code */, 145 typedef Callback2<PlatformFileError /* error code */,
152 int /* bytes read/written */>::Type ReadWriteCallback; 146 int /* bytes read/written */>::Type ReadWriteCallback;
153 static bool Read( 147 static bool Read(
154 scoped_refptr<MessageLoopProxy> message_loop_proxy, 148 scoped_refptr<MessageLoopProxy> message_loop_proxy,
155 base::PlatformFile file, 149 PlatformFile file,
156 int64 offset, 150 int64 offset,
157 char* buffer, 151 char* buffer,
158 int bytes_to_read, 152 int bytes_to_read,
159 ReadWriteCallback* callback); 153 ReadWriteCallback* callback);
160 154
161 // Writes to a file. If |offset| is greater than the length of the file, 155 // Writes to a file. If |offset| is greater than the length of the file,
162 // |false| is returned. On success, the file pointer is moved to position 156 // |false| is returned. On success, the file pointer is moved to position
163 // |offset + bytes_to_write| in the file. The callback can be NULL. 157 // |offset + bytes_to_write| in the file. The callback can be NULL.
164 static bool Write( 158 static bool Write(
165 scoped_refptr<MessageLoopProxy> message_loop_proxy, 159 scoped_refptr<MessageLoopProxy> message_loop_proxy,
166 base::PlatformFile file, 160 PlatformFile file,
167 int64 offset, 161 int64 offset,
168 const char* buffer, 162 const char* buffer,
169 int bytes_to_write, 163 int bytes_to_write,
170 ReadWriteCallback* callback); 164 ReadWriteCallback* callback);
171 165
172 // Touches a file. The callback can be NULL. 166 // Touches a file. The callback can be NULL.
173 static bool Touch( 167 static bool Touch(
174 scoped_refptr<MessageLoopProxy> message_loop_proxy, 168 scoped_refptr<MessageLoopProxy> message_loop_proxy,
175 base::PlatformFile file, 169 PlatformFile file,
176 const base::Time& last_access_time, 170 const Time& last_access_time,
177 const base::Time& last_modified_time, 171 const Time& last_modified_time,
178 StatusCallback* callback); 172 StatusCallback* callback);
179 173
180 // Touches a file. The callback can be NULL. 174 // Touches a file. The callback can be NULL.
181 static bool Touch( 175 static bool Touch(
182 scoped_refptr<MessageLoopProxy> message_loop_proxy, 176 scoped_refptr<MessageLoopProxy> message_loop_proxy,
183 const FilePath& file_path, 177 const FilePath& file_path,
184 const base::Time& last_access_time, 178 const Time& last_access_time,
185 const base::Time& last_modified_time, 179 const Time& last_modified_time,
186 StatusCallback* callback); 180 StatusCallback* callback);
187 181
188 // Truncates a file to the given length. If |length| is greater than the 182 // Truncates a file to the given length. If |length| is greater than the
189 // current length of the file, the file will be extended with zeroes. 183 // current length of the file, the file will be extended with zeroes.
190 // The callback can be NULL. 184 // The callback can be NULL.
191 static bool Truncate( 185 static bool Truncate(
192 scoped_refptr<MessageLoopProxy> message_loop_proxy, 186 scoped_refptr<MessageLoopProxy> message_loop_proxy,
193 base::PlatformFile file, 187 PlatformFile file,
194 int64 length, 188 int64 length,
195 StatusCallback* callback); 189 StatusCallback* callback);
196 190
197 // Truncates a file to the given length. If |length| is greater than the 191 // Truncates a file to the given length. If |length| is greater than the
198 // current length of the file, the file will be extended with zeroes. 192 // current length of the file, the file will be extended with zeroes.
199 // The callback can be NULL. 193 // The callback can be NULL.
200 static bool Truncate( 194 static bool Truncate(
201 scoped_refptr<MessageLoopProxy> message_loop_proxy, 195 scoped_refptr<MessageLoopProxy> message_loop_proxy,
202 const FilePath& path, 196 const FilePath& path,
203 int64 length, 197 int64 length,
204 StatusCallback* callback); 198 StatusCallback* callback);
205 199
206 // Flushes a file. The callback can be NULL. 200 // Flushes a file. The callback can be NULL.
207 static bool Flush( 201 static bool Flush(
208 scoped_refptr<MessageLoopProxy> message_loop_proxy, 202 scoped_refptr<MessageLoopProxy> message_loop_proxy,
209 base::PlatformFile file, 203 PlatformFile file,
210 StatusCallback* callback); 204 StatusCallback* callback);
211 205
212 private: 206 private:
213 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); 207 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy);
214 }; 208 };
215 209
216 } // namespace base 210 } // namespace base
217 211
218 #endif // BASE_FILE_UTIL_PROXY_H_ 212 #endif // BASE_FILE_UTIL_PROXY_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698