| 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_SYSTEM_PROXY_H_ | 5 #ifndef BASE_FILE_SYSTEM_PROXY_H_ |
| 6 #define BASE_FILE_SYSTEM_PROXY_H_ | 6 #define BASE_FILE_SYSTEM_PROXY_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 | 14 |
| 15 class MessageLoopProxy; | 15 class MessageLoopProxy; |
| 16 | 16 |
| 17 // This class provides asynchronous access to common file routines. | 17 // This class provides asynchronous access to common file routines. |
| 18 class FileUtilProxy { | 18 class FileUtilProxy { |
| 19 public: | 19 public: |
| 20 // This callback is used by methods that report success with a bool. It is | 20 // This callback is used by methods that report only an error code. It is |
| 21 // valid to pass NULL as the callback parameter to any function that takes a | 21 // valid to pass NULL as the callback parameter to any function that takes a |
| 22 // StatusCallback, in which case the operation will complete silently. | 22 // StatusCallback, in which case the operation will complete silently. |
| 23 typedef Callback1<bool /* succeeded */>::Type StatusCallback; | 23 typedef Callback1<int /* error code */>::Type StatusCallback; |
| 24 | 24 |
| 25 // Creates or opens a file with the given flags. It is invalid to pass NULL | 25 // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 26 // for the callback. | 26 // for the callback. |
| 27 typedef Callback2<base::PassPlatformFile, bool /* created */>::Type | 27 typedef Callback3<int /* error code */, base::PassPlatformFile, |
| 28 CreateOrOpenCallback; | 28 bool /* created */>::Type CreateOrOpenCallback; |
| 29 static void CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 29 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 30 const FilePath& file_path, | 30 const FilePath& file_path, |
| 31 int file_flags, | 31 int file_flags, |
| 32 CreateOrOpenCallback* callback); | 32 CreateOrOpenCallback* callback); |
| 33 | 33 |
| 34 // Creates a temporary file for writing. The path and an open file handle | 34 // Creates a temporary file for writing. The path and an open file handle |
| 35 // are returned. It is invalid to pass NULL for the callback. | 35 // are returned. It is invalid to pass NULL for the callback. |
| 36 typedef Callback2<base::PassPlatformFile, FilePath>::Type | 36 typedef Callback3<int /* error code */, base::PassPlatformFile, |
| 37 CreateTemporaryCallback; | 37 FilePath>::Type CreateTemporaryCallback; |
| 38 static void CreateTemporary( | 38 static bool CreateTemporary( |
| 39 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 39 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 40 CreateTemporaryCallback* callback); | 40 CreateTemporaryCallback* callback); |
| 41 | 41 |
| 42 // Close the given file handle. | 42 // Close the given file handle. |
| 43 static void Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 43 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 44 base::PlatformFile, | 44 base::PlatformFile, |
| 45 StatusCallback* callback); | 45 StatusCallback* callback); |
| 46 | 46 |
| 47 // Deletes a file or empty directory. | 47 // Deletes a file or empty directory. |
| 48 static void Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 48 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 49 const FilePath& file_path, | 49 const FilePath& file_path, |
| 50 StatusCallback* callback); | 50 StatusCallback* callback); |
| 51 | 51 |
| 52 // Deletes a directory and all of its contents. | 52 // Deletes a directory and all of its contents. |
| 53 static void RecursiveDelete( | 53 static bool RecursiveDelete( |
| 54 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 54 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 55 const FilePath& file_path, | 55 const FilePath& file_path, |
| 56 StatusCallback* callback); | 56 StatusCallback* callback); |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); | 59 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 } // namespace base | 62 } // namespace base |
| 63 | 63 |
| 64 #endif // BASE_FILE_SYSTEM_PROXY_H_ | 64 #endif // BASE_FILE_SYSTEM_PROXY_H_ |
| OLD | NEW |