Chromium Code Reviews| 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 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/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 public: | 26 public: |
| 27 // Holds metadata for file or directory entry. Used by ReadDirectoryCallback. | 27 // Holds metadata for file or directory entry. Used by ReadDirectoryCallback. |
| 28 struct Entry { | 28 struct Entry { |
| 29 FilePath::StringType name; | 29 FilePath::StringType name; |
| 30 bool is_directory; | 30 bool is_directory; |
| 31 int64 size; | 31 int64 size; |
| 32 base::Time last_modified_time; | 32 base::Time last_modified_time; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // This callback is used by methods that report only an error code. It is | 35 // 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 | 36 // valid to pass NULL as the callback parameter to any function that takes a |
|
csilv
2011/10/17 20:22:28
"valid to pass a null callback"
James Hawkins
2011/10/17 20:44:38
This is fixed in the StatusCallback CL.
| |
| 37 // StatusCallback, in which case the operation will complete silently. | 37 // StatusCallback, in which case the operation will complete silently. |
| 38 // The ownership of |callback| is taken by the function and will always be | 38 // The ownership of |callback| is taken by the function and will always be |
| 39 // deleted by the function even on failure. | 39 // deleted by the function even on failure. |
| 40 typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback; | 40 typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback; |
| 41 | 41 |
| 42 typedef base::Callback<void(PlatformFileError /* error code */, | 42 typedef base::Callback<void(PlatformFileError /* error code */, |
| 43 PassPlatformFile, | 43 PassPlatformFile, |
| 44 bool /* created */)> CreateOrOpenCallback; | 44 bool /* created */)> CreateOrOpenCallback; |
| 45 typedef base::Callback<void(PlatformFileError /* error code */, | 45 typedef base::Callback<void(PlatformFileError /* error code */, |
| 46 PassPlatformFile, | 46 PassPlatformFile, |
| 47 FilePath)> CreateTemporaryCallback; | 47 FilePath)> CreateTemporaryCallback; |
| 48 typedef base::Callback<void(PlatformFileError /* error code */, | 48 typedef base::Callback<void(PlatformFileError /* error code */, |
| 49 bool /* created */)> EnsureFileExistsCallback; | 49 bool /* created */)> EnsureFileExistsCallback; |
| 50 typedef base::Callback<void(PlatformFileError /* error code */, | 50 typedef base::Callback<void(PlatformFileError /* error code */, |
| 51 const PlatformFileInfo& /* file_info */)> | 51 const PlatformFileInfo& /* file_info */)> |
| 52 GetFileInfoCallback; | 52 GetFileInfoCallback; |
| 53 typedef base::Callback<void(PlatformFileError /* error code */, | 53 typedef base::Callback<void(PlatformFileError /* error code */, |
| 54 const std::vector<Entry>&)> ReadDirectoryCallback; | 54 const std::vector<Entry>&)> ReadDirectoryCallback; |
| 55 typedef Callback3<PlatformFileError /* error code */, | 55 typedef base::Callback<void(PlatformFileError /* error code */, |
| 56 const char* /* data */, | 56 const char* /* data */, |
| 57 int /* bytes read/written */>::Type ReadCallback; | 57 int /* bytes read/written */)> ReadCallback; |
| 58 typedef Callback2<PlatformFileError /* error code */, | 58 typedef Callback2<PlatformFileError /* error code */, |
| 59 int /* bytes written */>::Type WriteCallback; | 59 int /* bytes written */>::Type WriteCallback; |
| 60 | 60 |
| 61 // Creates or opens a file with the given flags. It is invalid to pass NULL | 61 // Creates or opens a file with the given flags. It is invalid to pass NULL |
|
csilv
2011/10/17 20:22:28
NULL -> null
James Hawkins
2011/10/17 20:44:38
Done.
| |
| 62 // for the callback. | 62 // for the callback. |
| 63 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 63 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
| 64 // a new file at the given |file_path| and calls back with | 64 // a new file at the given |file_path| and calls back with |
| 65 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. | 65 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
| 66 // Takes ownership of |callback| and will delete it even on failure. | 66 // Takes ownership of |callback| and will delete it even on failure. |
| 67 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 67 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 68 const FilePath& file_path, | 68 const FilePath& file_path, |
| 69 int file_flags, | 69 int file_flags, |
| 70 const CreateOrOpenCallback& callback); | 70 const CreateOrOpenCallback& callback); |
| 71 | 71 |
| 72 // Creates a temporary file for writing. The path and an open file handle | 72 // Creates a temporary file for writing. The path and an open file handle |
| 73 // are returned. It is invalid to pass NULL for the callback. The additional | 73 // are returned. It is invalid to pass NULL for the callback. The additional |
|
csilv
2011/10/17 20:22:28
NULL -> null
James Hawkins
2011/10/17 20:44:38
Done.
| |
| 74 // file flags will be added on top of the default file flags which are: | 74 // file flags will be added on top of the default file flags which are: |
| 75 // base::PLATFORM_FILE_CREATE_ALWAYS | 75 // base::PLATFORM_FILE_CREATE_ALWAYS |
| 76 // base::PLATFORM_FILE_WRITE | 76 // base::PLATFORM_FILE_WRITE |
| 77 // base::PLATFORM_FILE_TEMPORARY. | 77 // base::PLATFORM_FILE_TEMPORARY. |
| 78 // Set |additional_file_flags| to 0 for synchronous writes and set to | 78 // Set |additional_file_flags| to 0 for synchronous writes and set to |
| 79 // base::PLATFORM_FILE_ASYNC to support asynchronous file operations. | 79 // base::PLATFORM_FILE_ASYNC to support asynchronous file operations. |
| 80 static bool CreateTemporary( | 80 static bool CreateTemporary( |
| 81 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 81 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 82 int additional_file_flags, | 82 int additional_file_flags, |
| 83 const CreateTemporaryCallback& callback); | 83 const CreateTemporaryCallback& callback); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 94 // is set PLATFORM_FILE_OK. | 94 // is set PLATFORM_FILE_OK. |
| 95 // If the file already exists, |created| is set false and |error code| | 95 // If the file already exists, |created| is set false and |error code| |
| 96 // is set PLATFORM_FILE_OK. | 96 // is set PLATFORM_FILE_OK. |
| 97 // If the file hasn't existed but it couldn't be created for some other | 97 // If the file hasn't existed but it couldn't be created for some other |
| 98 // reasons, |created| is set false and |error code| indicates the error. | 98 // reasons, |created| is set false and |error code| indicates the error. |
| 99 static bool EnsureFileExists( | 99 static bool EnsureFileExists( |
| 100 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 100 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 101 const FilePath& file_path, | 101 const FilePath& file_path, |
| 102 const EnsureFileExistsCallback& callback); | 102 const EnsureFileExistsCallback& callback); |
| 103 | 103 |
| 104 // Retrieves the information about a file. It is invalid to pass NULL for the | 104 // Retrieves the information about a file. It is invalid to pass NULL for the |
|
csilv
2011/10/17 20:22:28
NULL -> null
James Hawkins
2011/10/17 20:44:38
Done.
| |
| 105 // callback. | 105 // callback. |
| 106 static bool GetFileInfo( | 106 static bool GetFileInfo( |
| 107 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 107 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 108 const FilePath& file_path, | 108 const FilePath& file_path, |
| 109 const GetFileInfoCallback& callback); | 109 const GetFileInfoCallback& callback); |
| 110 | 110 |
| 111 static bool GetFileInfoFromPlatformFile( | 111 static bool GetFileInfoFromPlatformFile( |
| 112 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 112 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 113 PlatformFile file, | 113 PlatformFile file, |
| 114 const GetFileInfoCallback& callback); | 114 const GetFileInfoCallback& callback); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 bool recursive, | 154 bool recursive, |
| 155 StatusCallback* callback); | 155 StatusCallback* callback); |
| 156 | 156 |
| 157 // Deletes a directory and all of its contents. | 157 // Deletes a directory and all of its contents. |
| 158 static bool RecursiveDelete( | 158 static bool RecursiveDelete( |
| 159 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 159 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 160 const FilePath& file_path, | 160 const FilePath& file_path, |
| 161 StatusCallback* callback); | 161 StatusCallback* callback); |
| 162 | 162 |
| 163 // Reads from a file. On success, the file pointer is moved to position | 163 // Reads from a file. On success, the file pointer is moved to position |
| 164 // |offset + bytes_to_read| in the file. The callback can be NULL. | 164 // |offset + bytes_to_read| in the file. The callback can be null. |
| 165 static bool Read( | 165 static bool Read( |
| 166 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 166 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 167 PlatformFile file, | 167 PlatformFile file, |
| 168 int64 offset, | 168 int64 offset, |
| 169 int bytes_to_read, | 169 int bytes_to_read, |
| 170 ReadCallback* callback); | 170 const ReadCallback& callback); |
| 171 | 171 |
| 172 // Writes to a file. If |offset| is greater than the length of the file, | 172 // Writes to a file. If |offset| is greater than the length of the file, |
| 173 // |false| is returned. On success, the file pointer is moved to position | 173 // |false| is returned. On success, the file pointer is moved to position |
| 174 // |offset + bytes_to_write| in the file. The callback can be NULL. | 174 // |offset + bytes_to_write| in the file. The callback can be NULL. |
| 175 // |bytes_to_write| must be greater than zero. | 175 // |bytes_to_write| must be greater than zero. |
| 176 static bool Write( | 176 static bool Write( |
| 177 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 177 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 178 PlatformFile file, | 178 PlatformFile file, |
| 179 int64 offset, | 179 int64 offset, |
| 180 const char* buffer, | 180 const char* buffer, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 PlatformFile file, | 221 PlatformFile file, |
| 222 StatusCallback* callback); | 222 StatusCallback* callback); |
| 223 | 223 |
| 224 private: | 224 private: |
| 225 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); | 225 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 } // namespace base | 228 } // namespace base |
| 229 | 229 |
| 230 #endif // BASE_FILE_UTIL_PROXY_H_ | 230 #endif // BASE_FILE_UTIL_PROXY_H_ |
| OLD | NEW |