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 | |
| 13 | namespace base { |
| 14 | |
| 15 | class MessageLoopProxy; |
| 16 | |
| 17 | // This class provides asynchronous access to common file routines. |
| 18 | class FileUtilProxy { |
| 19 | public: |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 20 | // 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] | 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. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 23 | typedef Callback1<int /* error code */>::Type StatusCallback; |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 24 | |
| 25 | // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 26 | // for the callback. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 27 | typedef Callback3<int /* error code */, base::PassPlatformFile, |
| 28 | bool /* created */>::Type CreateOrOpenCallback; |
| 29 | static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 30 | const FilePath& file_path, |
| 31 | int file_flags, |
| 32 | CreateOrOpenCallback* callback); |
| 33 | |
| 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. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 36 | typedef Callback3<int /* error code */, base::PassPlatformFile, |
| 37 | FilePath>::Type CreateTemporaryCallback; |
| 38 | static bool CreateTemporary( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 39 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 40 | CreateTemporaryCallback* callback); |
| 41 | |
| 42 | // Close the given file handle. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 43 | static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 44 | base::PlatformFile, |
| 45 | StatusCallback* callback); |
| 46 | |
| 47 | // Deletes a file or empty directory. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 48 | static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 49 | const FilePath& file_path, |
| 50 | StatusCallback* callback); |
| 51 | |
| 52 | // Deletes a directory and all of its contents. |
dumi@chromium.org | 6dedd6d | 2010-08-25 05:26:23 +0900 | [diff] [blame] | 53 | static bool RecursiveDelete( |
dumi@chromium.org | c980e40 | 2010-08-21 07:42:50 +0900 | [diff] [blame] | 54 | scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 55 | const FilePath& file_path, |
| 56 | StatusCallback* callback); |
| 57 | |
| 58 | private: |
| 59 | DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy); |
| 60 | }; |
| 61 | |
| 62 | } // namespace base |
| 63 | |
| 64 | #endif // BASE_FILE_SYSTEM_PROXY_H_ |