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 | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 27 | typedef Callback1<int /* error code */>::Type StatusCallback; |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 28 | |
| 29 | // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 30 | // for the callback. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 31 | typedef Callback3<int /* error code */, base::PassPlatformFile, |
| 32 | bool /* created */>::Type CreateOrOpenCallback; |
| 33 | static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 34 | const FilePath& file_path, |
| 35 | int file_flags, |
| 36 | CreateOrOpenCallback* callback); |
| 37 | |
| 38 | // Creates a temporary file for writing. The path and an open file handle |
| 39 | // are returned. It is invalid to pass NULL for the callback. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 40 | typedef Callback3<int /* error code */, base::PassPlatformFile, |
| 41 | FilePath>::Type CreateTemporaryCallback; |
| 42 | static bool CreateTemporary( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 43 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 44 | CreateTemporaryCallback* callback); |
| 45 | |
| 46 | // Close the given file handle. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 47 | static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 48 | base::PlatformFile, |
| 49 | StatusCallback* callback); |
| 50 | |
| 51 | // Deletes a file or empty directory. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 52 | static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 53 | const FilePath& file_path, |
| 54 | StatusCallback* callback); |
| 55 | |
| 56 | // Deletes a directory and all of its contents. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 57 | static bool RecursiveDelete( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 58 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 59 | const FilePath& file_path, |
| 60 | StatusCallback* callback); |
| 61 | |
jianli@chromium.org | 9ed1f9d | 2010-08-31 11:42:36 +0900 | [diff] [blame^] | 62 | // Retrieves the information about a file. It is invalid to pass NULL for the |
| 63 | // callback. |
| 64 | typedef Callback2<bool /*exists*/, |
| 65 | const file_util::FileInfo& /*file_info*/ |
| 66 | >::Type GetFileInfoCallback; |
| 67 | static bool GetFileInfo( |
| 68 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 69 | const FilePath& file_path, |
| 70 | GetFileInfoCallback* callback); |
| 71 | |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 72 | private: |
| 73 | DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); |
| 74 | }; |
| 75 | |
| 76 | } // namespace base |
| 77 | |
| 78 | #endif // BASE_FILE_SYSTEM_PROXY_H_ |