| OLD | NEW |
| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 class FileUtilProxy { | 33 class FileUtilProxy { |
| 34 public: | 34 public: |
| 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 |
| 37 // StatusCallback, in which case the operation will complete silently. | 37 // StatusCallback, in which case the operation will complete silently. |
| 38 typedef Callback1<base::PlatformFileError /* error code */ | 38 typedef Callback1<base::PlatformFileError /* error code */ |
| 39 >::Type StatusCallback; | 39 >::Type StatusCallback; |
| 40 | 40 |
| 41 // Creates or opens a file with the given flags. It is invalid to pass NULL | 41 // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 42 // for the callback. | 42 // for the callback. |
| 43 // 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 |
| 45 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
| 43 typedef Callback3<base::PlatformFileError /* error code */, | 46 typedef Callback3<base::PlatformFileError /* error code */, |
| 44 base::PassPlatformFile, | 47 base::PassPlatformFile, |
| 45 bool /* created */>::Type CreateOrOpenCallback; | 48 bool /* created */>::Type CreateOrOpenCallback; |
| 46 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 49 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 47 const FilePath& file_path, | 50 const FilePath& file_path, |
| 48 int file_flags, | 51 int file_flags, |
| 49 CreateOrOpenCallback* callback); | 52 CreateOrOpenCallback* callback); |
| 50 | 53 |
| 51 // Creates a file with the given flags. This one is a variation of | |
| 52 // CreateOrOpen but it doesn't return a file handle. | |
| 53 static bool Create(scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
| 54 const FilePath& file_path, | |
| 55 int file_flags, | |
| 56 CreateOrOpenCallback* callback); | |
| 57 | |
| 58 // Creates a temporary file for writing. The path and an open file handle | 54 // Creates a temporary file for writing. The path and an open file handle |
| 59 // are returned. It is invalid to pass NULL for the callback. | 55 // are returned. It is invalid to pass NULL for the callback. |
| 60 typedef Callback3<base::PlatformFileError /* error code */, | 56 typedef Callback3<base::PlatformFileError /* error code */, |
| 61 base::PassPlatformFile, | 57 base::PassPlatformFile, |
| 62 FilePath>::Type CreateTemporaryCallback; | 58 FilePath>::Type CreateTemporaryCallback; |
| 63 static bool CreateTemporary( | 59 static bool CreateTemporary( |
| 64 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 60 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 65 CreateTemporaryCallback* callback); | 61 CreateTemporaryCallback* callback); |
| 66 | 62 |
| 67 // Close the given file handle. | 63 // Close the given file handle. |
| 68 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 64 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 69 base::PlatformFile, | 65 base::PlatformFile, |
| 70 StatusCallback* callback); | 66 StatusCallback* callback); |
| 71 | 67 |
| 68 // Ensures that the given |file_path| exist. This creates a empty new file |
| 69 // 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|, |
| 71 // |created| of the callback argument is set true and |error code| |
| 72 // is set PLATFORM_FILE_OK. |
| 73 // If the file already exists, |created| is set false and |error code| |
| 74 // is set PLATFORM_FILE_OK. |
| 75 // 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. |
| 77 typedef Callback2<base::PlatformFileError /* error code */, |
| 78 bool /* created */>::Type EnsureFileExistsCallback; |
| 79 static bool EnsureFileExists( |
| 80 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 81 const FilePath& file_path, |
| 82 EnsureFileExistsCallback* callback); |
| 83 |
| 72 // Retrieves the information about a file. It is invalid to pass NULL for the | 84 // Retrieves the information about a file. It is invalid to pass NULL for the |
| 73 // callback. | 85 // callback. |
| 74 typedef Callback2<base::PlatformFileError /* error code */, | 86 typedef Callback2<base::PlatformFileError /* error code */, |
| 75 const base::PlatformFileInfo& /* file_info */ | 87 const base::PlatformFileInfo& /* file_info */ |
| 76 >::Type GetFileInfoCallback; | 88 >::Type GetFileInfoCallback; |
| 77 static bool GetFileInfo( | 89 static bool GetFileInfo( |
| 78 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 90 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 79 const FilePath& file_path, | 91 const FilePath& file_path, |
| 80 GetFileInfoCallback* callback); | 92 GetFileInfoCallback* callback); |
| 81 | 93 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 base::PlatformFile file, | 209 base::PlatformFile file, |
| 198 StatusCallback* callback); | 210 StatusCallback* callback); |
| 199 | 211 |
| 200 private: | 212 private: |
| 201 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); | 213 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); |
| 202 }; | 214 }; |
| 203 | 215 |
| 204 } // namespace base | 216 } // namespace base |
| 205 | 217 |
| 206 #endif // BASE_FILE_UTIL_PROXY_H_ | 218 #endif // BASE_FILE_UTIL_PROXY_H_ |
| OLD | NEW |