blob: 9899c773315ab9b3d1f2477aac6475bff592ee69 [file] [log] [blame]
dumi@chromium.orgc980e402010-08-21 07:42:50 +09001// 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.org9ed1f9d2010-08-31 11:42:36 +090013namespace file_util {
14struct FileInfo;
15}
16
dumi@chromium.orgc980e402010-08-21 07:42:50 +090017namespace base {
18
19class MessageLoopProxy;
20
21// This class provides asynchronous access to common file routines.
22class FileUtilProxy {
23 public:
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090024 // This callback is used by methods that report only an error code. It is
dumi@chromium.orgc980e402010-08-21 07:42:50 +090025 // 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.org50f197d2010-09-01 04:30:27 +090027 typedef Callback1<base::PlatformFileError /* error code */
28 >::Type StatusCallback;
dumi@chromium.orgc980e402010-08-21 07:42:50 +090029
30 // Creates or opens a file with the given flags. It is invalid to pass NULL
31 // for the callback.
dumi@chromium.org50f197d2010-09-01 04:30:27 +090032 typedef Callback3<base::PlatformFileError /* error code */,
33 base::PassPlatformFile,
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090034 bool /* created */>::Type CreateOrOpenCallback;
35 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090036 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.org50f197d2010-09-01 04:30:27 +090042 typedef Callback3<base::PlatformFileError /* error code */,
43 base::PassPlatformFile,
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090044 FilePath>::Type CreateTemporaryCallback;
45 static bool CreateTemporary(
dumi@chromium.orgc980e402010-08-21 07:42:50 +090046 scoped_refptr<MessageLoopProxy> message_loop_proxy,
47 CreateTemporaryCallback* callback);
48
49 // Close the given file handle.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090050 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090051 base::PlatformFile,
52 StatusCallback* callback);
53
54 // Deletes a file or empty directory.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090055 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090056 const FilePath& file_path,
57 StatusCallback* callback);
58
59 // Deletes a directory and all of its contents.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090060 static bool RecursiveDelete(
dumi@chromium.orgc980e402010-08-21 07:42:50 +090061 scoped_refptr<MessageLoopProxy> message_loop_proxy,
62 const FilePath& file_path,
63 StatusCallback* callback);
64
jianli@chromium.org9ed1f9d2010-08-31 11:42:36 +090065 // Retrieves the information about a file. It is invalid to pass NULL for the
66 // callback.
dumi@chromium.org50f197d2010-09-01 04:30:27 +090067 typedef Callback2<base::PlatformFileError /* error code */,
jianli@chromium.org9ed1f9d2010-08-31 11:42:36 +090068 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.orgc980e402010-08-21 07:42:50 +090075 private:
76 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy);
77};
78
79} // namespace base
80
81#endif // BASE_FILE_SYSTEM_PROXY_H_