blob: ff04e5b0edc494b4a1eb2ec3d403897306bcd108 [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.org6dedd6d2010-08-25 05:26:23 +090027 typedef Callback1<int /* error code */>::Type StatusCallback;
dumi@chromium.orgc980e402010-08-21 07:42:50 +090028
29 // Creates or opens a file with the given flags. It is invalid to pass NULL
30 // for the callback.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090031 typedef Callback3<int /* error code */, base::PassPlatformFile,
32 bool /* created */>::Type CreateOrOpenCallback;
33 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090034 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.org6dedd6d2010-08-25 05:26:23 +090040 typedef Callback3<int /* error code */, base::PassPlatformFile,
41 FilePath>::Type CreateTemporaryCallback;
42 static bool CreateTemporary(
dumi@chromium.orgc980e402010-08-21 07:42:50 +090043 scoped_refptr<MessageLoopProxy> message_loop_proxy,
44 CreateTemporaryCallback* callback);
45
46 // Close the given file handle.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090047 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090048 base::PlatformFile,
49 StatusCallback* callback);
50
51 // Deletes a file or empty directory.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090052 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090053 const FilePath& file_path,
54 StatusCallback* callback);
55
56 // Deletes a directory and all of its contents.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090057 static bool RecursiveDelete(
dumi@chromium.orgc980e402010-08-21 07:42:50 +090058 scoped_refptr<MessageLoopProxy> message_loop_proxy,
59 const FilePath& file_path,
60 StatusCallback* callback);
61
jianli@chromium.org9ed1f9d2010-08-31 11:42:36 +090062 // 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.orgc980e402010-08-21 07:42:50 +090072 private:
73 DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilProxy);
74};
75
76} // namespace base
77
78#endif // BASE_FILE_SYSTEM_PROXY_H_