| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 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/callback.h" | 10 #include "base/callback.h" | 
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 26   struct Entry { | 26   struct Entry { | 
| 27     FilePath::StringType name; | 27     FilePath::StringType name; | 
| 28     bool is_directory; | 28     bool is_directory; | 
| 29   }; | 29   }; | 
| 30 | 30 | 
| 31   // 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 | 
| 32   // 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 | 
| 33   // StatusCallback, in which case the operation will complete silently. | 33   // StatusCallback, in which case the operation will complete silently. | 
| 34   typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback; | 34   typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback; | 
| 35 | 35 | 
|  | 36   typedef Callback3<PlatformFileError /* error code */, | 
|  | 37                     PassPlatformFile, | 
|  | 38                     bool /* created */>::Type CreateOrOpenCallback; | 
|  | 39   typedef Callback3<PlatformFileError /* error code */, | 
|  | 40                     PassPlatformFile, | 
|  | 41                     FilePath>::Type CreateTemporaryCallback; | 
|  | 42   typedef Callback2<PlatformFileError /* error code */, | 
|  | 43                     bool /* created */>::Type EnsureFileExistsCallback; | 
|  | 44   typedef Callback2<PlatformFileError /* error code */, | 
|  | 45                     const PlatformFileInfo& /* file_info */ | 
|  | 46                     >::Type GetFileInfoCallback; | 
|  | 47   typedef Callback2<PlatformFileError /* error code */, | 
|  | 48                     const std::vector<Entry>&>::Type ReadDirectoryCallback; | 
|  | 49   typedef Callback2<PlatformFileError /* error code */, | 
|  | 50                     int /* bytes read/written */>::Type ReadWriteCallback; | 
|  | 51 | 
| 36   // Creates or opens a file with the given flags.  It is invalid to pass NULL | 52   // Creates or opens a file with the given flags.  It is invalid to pass NULL | 
| 37   // for the callback. | 53   // for the callback. | 
| 38   // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 54   // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 
| 39   // a new file at the given |file_path| and calls back with | 55   // a new file at the given |file_path| and calls back with | 
| 40   // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. | 56   // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. | 
| 41   typedef Callback3<PlatformFileError /* error code */, |  | 
| 42                     PassPlatformFile, |  | 
| 43                     bool /* created */>::Type CreateOrOpenCallback; |  | 
| 44   static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 57   static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 45                            const FilePath& file_path, | 58                            const FilePath& file_path, | 
| 46                            int file_flags, | 59                            int file_flags, | 
| 47                            CreateOrOpenCallback* callback); | 60                            CreateOrOpenCallback* callback); | 
| 48 | 61 | 
| 49   // Creates a temporary file for writing.  The path and an open file handle | 62   // Creates a temporary file for writing.  The path and an open file handle | 
| 50   // are returned.  It is invalid to pass NULL for the callback. | 63   // are returned.  It is invalid to pass NULL for the callback. | 
| 51   typedef Callback3<PlatformFileError /* error code */, |  | 
| 52                     PassPlatformFile, |  | 
| 53                     FilePath>::Type CreateTemporaryCallback; |  | 
| 54   static bool CreateTemporary( | 64   static bool CreateTemporary( | 
| 55       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 65       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 56       CreateTemporaryCallback* callback); | 66       CreateTemporaryCallback* callback); | 
| 57 | 67 | 
| 58   // Close the given file handle. | 68   // Close the given file handle. | 
| 59   static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 69   static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 60                     PlatformFile, | 70                     PlatformFile, | 
| 61                     StatusCallback* callback); | 71                     StatusCallback* callback); | 
| 62 | 72 | 
| 63   // Ensures that the given |file_path| exist.  This creates a empty new file | 73   // Ensures that the given |file_path| exist.  This creates a empty new file | 
| 64   // at |file_path| if the |file_path| does not exist. | 74   // at |file_path| if the |file_path| does not exist. | 
| 65   // If a new file han not existed and is created at the |file_path|, | 75   // If a new file han not existed and is created at the |file_path|, | 
| 66   // |created| of the callback argument is set true and |error code| | 76   // |created| of the callback argument is set true and |error code| | 
| 67   // is set PLATFORM_FILE_OK. | 77   // is set PLATFORM_FILE_OK. | 
| 68   // If the file already exists, |created| is set false and |error code| | 78   // If the file already exists, |created| is set false and |error code| | 
| 69   // is set PLATFORM_FILE_OK. | 79   // is set PLATFORM_FILE_OK. | 
| 70   // If the file hasn't existed but it couldn't be created for some other | 80   // If the file hasn't existed but it couldn't be created for some other | 
| 71   // reasons, |created| is set false and |error code| indicates the error. | 81   // reasons, |created| is set false and |error code| indicates the error. | 
| 72   typedef Callback2<PlatformFileError /* error code */, |  | 
| 73                     bool /* created */>::Type EnsureFileExistsCallback; |  | 
| 74   static bool EnsureFileExists( | 82   static bool EnsureFileExists( | 
| 75       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 83       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 76       const FilePath& file_path, | 84       const FilePath& file_path, | 
| 77       EnsureFileExistsCallback* callback); | 85       EnsureFileExistsCallback* callback); | 
| 78 | 86 | 
| 79   // Retrieves the information about a file. It is invalid to pass NULL for the | 87   // Retrieves the information about a file. It is invalid to pass NULL for the | 
| 80   // callback. | 88   // callback. | 
| 81   typedef Callback2<PlatformFileError /* error code */, |  | 
| 82                     const PlatformFileInfo& /* file_info */ |  | 
| 83                     >::Type GetFileInfoCallback; |  | 
| 84   static bool GetFileInfo( | 89   static bool GetFileInfo( | 
| 85       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 90       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 86       const FilePath& file_path, | 91       const FilePath& file_path, | 
| 87       GetFileInfoCallback* callback); | 92       GetFileInfoCallback* callback); | 
| 88 | 93 | 
| 89   static bool GetFileInfoFromPlatformFile( | 94   static bool GetFileInfoFromPlatformFile( | 
| 90       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 95       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 91       PlatformFile file, | 96       PlatformFile file, | 
| 92       GetFileInfoCallback* callback); | 97       GetFileInfoCallback* callback); | 
| 93 | 98 | 
| 94   typedef Callback2<PlatformFileError /* error code */, |  | 
| 95       const std::vector<Entry>&>::Type ReadDirectoryCallback; |  | 
| 96   static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 99   static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 97                             const FilePath& file_path, | 100                             const FilePath& file_path, | 
| 98                             ReadDirectoryCallback* callback); | 101                             ReadDirectoryCallback* callback); | 
| 99 | 102 | 
| 100   // Copies a file or a directory from |src_file_path| to |dest_file_path| | 103   // Copies a file or a directory from |src_file_path| to |dest_file_path| | 
| 101   // Error cases: | 104   // Error cases: | 
| 102   // If destination file doesn't exist or destination's parent | 105   // If destination file doesn't exist or destination's parent | 
| 103   // doesn't exists. | 106   // doesn't exists. | 
| 104   // If source dir exists but destination path is an existing file. | 107   // If source dir exists but destination path is an existing file. | 
| 105   // If source file exists but destination path is an existing directory. | 108   // If source file exists but destination path is an existing directory. | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 135       StatusCallback* callback); | 138       StatusCallback* callback); | 
| 136 | 139 | 
| 137   // Deletes a directory and all of its contents. | 140   // Deletes a directory and all of its contents. | 
| 138   static bool RecursiveDelete( | 141   static bool RecursiveDelete( | 
| 139       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 142       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 140       const FilePath& file_path, | 143       const FilePath& file_path, | 
| 141       StatusCallback* callback); | 144       StatusCallback* callback); | 
| 142 | 145 | 
| 143   // Reads from a file. On success, the file pointer is moved to position | 146   // Reads from a file. On success, the file pointer is moved to position | 
| 144   // |offset + bytes_to_read| in the file. The callback can be NULL. | 147   // |offset + bytes_to_read| in the file. The callback can be NULL. | 
| 145   typedef Callback2<PlatformFileError /* error code */, |  | 
| 146                     int /* bytes read/written */>::Type ReadWriteCallback; |  | 
| 147   static bool Read( | 148   static bool Read( | 
| 148       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 149       scoped_refptr<MessageLoopProxy> message_loop_proxy, | 
| 149       PlatformFile file, | 150       PlatformFile file, | 
| 150       int64 offset, | 151       int64 offset, | 
| 151       char* buffer, | 152       char* buffer, | 
| 152       int bytes_to_read, | 153       int bytes_to_read, | 
| 153       ReadWriteCallback* callback); | 154       ReadWriteCallback* callback); | 
| 154 | 155 | 
| 155   // Writes to a file. If |offset| is greater than the length of the file, | 156   // Writes to a file. If |offset| is greater than the length of the file, | 
| 156   // |false| is returned. On success, the file pointer is moved to position | 157   // |false| is returned. On success, the file pointer is moved to position | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 203       PlatformFile file, | 204       PlatformFile file, | 
| 204       StatusCallback* callback); | 205       StatusCallback* callback); | 
| 205 | 206 | 
| 206  private: | 207  private: | 
| 207   DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); | 208   DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); | 
| 208 }; | 209 }; | 
| 209 | 210 | 
| 210 }  // namespace base | 211 }  // namespace base | 
| 211 | 212 | 
| 212 #endif  // BASE_FILE_UTIL_PROXY_H_ | 213 #endif  // BASE_FILE_UTIL_PROXY_H_ | 
| OLD | NEW | 
|---|