dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_FILE_SYSTEM_PROXY_H_ |
| 6 | #define BASE_FILE_SYSTEM_PROXY_H_ |
| 7 | |
| 8 | #include "base/callback.h" |
| 9 | #include "base/platform_file.h" |
| 10 | #include "base/ref_counted.h" |
| 11 | #include "base/tracked_objects.h" |
| 12 | |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 13 | namespace file_util { |
| 14 | struct FileInfo; |
| 15 | } |
| 16 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 17 | namespace base { |
| 18 | |
| 19 | class MessageLoopProxy; |
| 20 | |
| 21 | // This class provides asynchronous access to common file routines. |
| 22 | class FileUtilProxy { |
| 23 | public: |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 24 | // This callback is used by methods that report only an error code. It is |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 25 | // valid to pass NULL as the callback parameter to any function that takes a |
| 26 | // StatusCallback, in which case the operation will complete silently. |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame^] | 27 | typedef Callback1<base::PlatformFileError /* error code */ |
| 28 | >::Type StatusCallback; |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 29 | |
| 30 | // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 31 | // for the callback. |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame^] | 32 | typedef Callback3<base::PlatformFileError /* error code */, |
| 33 | base::PassPlatformFile, |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 34 | bool /* created */>::Type CreateOrOpenCallback; |
| 35 | static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 36 | const FilePath& file_path, |
| 37 | int file_flags, |
| 38 | CreateOrOpenCallback* callback); |
| 39 | |
| 40 | // Creates a temporary file for writing. The path and an open file handle |
| 41 | // are returned. It is invalid to pass NULL for the callback. |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame^] | 42 | typedef Callback3<base::PlatformFileError /* error code */, |
| 43 | base::PassPlatformFile, |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 44 | FilePath>::Type CreateTemporaryCallback; |
| 45 | static bool CreateTemporary( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 46 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 47 | CreateTemporaryCallback* callback); |
| 48 | |
| 49 | // Close the given file handle. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 50 | static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 51 | base::PlatformFile, |
| 52 | StatusCallback* callback); |
| 53 | |
| 54 | // Deletes a file or empty directory. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 55 | static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 56 | const FilePath& file_path, |
| 57 | StatusCallback* callback); |
| 58 | |
| 59 | // Deletes a directory and all of its contents. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 60 | static bool RecursiveDelete( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 61 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 62 | const FilePath& file_path, |
| 63 | StatusCallback* callback); |
| 64 | |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 65 | // Retrieves the information about a file. It is invalid to pass NULL for the |
| 66 | // callback. |
dumi@chromium.org | 50f197d | 2010-09-01 04:30:27 +0900 | [diff] [blame^] | 67 | typedef Callback2<base::PlatformFileError /* error code */, |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame] | 68 | const file_util::FileInfo& /*file_info*/ |
| 69 | >::Type GetFileInfoCallback; |
| 70 | static bool GetFileInfo( |
| 71 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 72 | const FilePath& file_path, |
| 73 | GetFileInfoCallback* callback); |
| 74 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 75 | private: |
| 76 | DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); |
| 77 | }; |
| 78 | |
| 79 | } // namespace base |
| 80 | |
| 81 | #endif // BASE_FILE_SYSTEM_PROXY_H_ |