blob: 87cd08192d0fee4f4de174d95783428f1df84829 [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
13namespace base {
14
15class MessageLoopProxy;
16
17// This class provides asynchronous access to common file routines.
18class FileUtilProxy {
19 public:
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090020 // This callback is used by methods that report only an error code. It is
dumi@chromium.orgc980e402010-08-21 07:42:50 +090021 // 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.org6dedd6d2010-08-25 05:26:23 +090023 typedef Callback1<int /* error code */>::Type StatusCallback;
dumi@chromium.orgc980e402010-08-21 07:42:50 +090024
25 // Creates or opens a file with the given flags. It is invalid to pass NULL
26 // for the callback.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090027 typedef Callback3<int /* error code */, base::PassPlatformFile,
28 bool /* created */>::Type CreateOrOpenCallback;
29 static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090030 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.org6dedd6d2010-08-25 05:26:23 +090036 typedef Callback3<int /* error code */, base::PassPlatformFile,
37 FilePath>::Type CreateTemporaryCallback;
38 static bool CreateTemporary(
dumi@chromium.orgc980e402010-08-21 07:42:50 +090039 scoped_refptr<MessageLoopProxy> message_loop_proxy,
40 CreateTemporaryCallback* callback);
41
42 // Close the given file handle.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090043 static bool Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090044 base::PlatformFile,
45 StatusCallback* callback);
46
47 // Deletes a file or empty directory.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090048 static bool Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy,
dumi@chromium.orgc980e402010-08-21 07:42:50 +090049 const FilePath& file_path,
50 StatusCallback* callback);
51
52 // Deletes a directory and all of its contents.
dumi@chromium.org6dedd6d2010-08-25 05:26:23 +090053 static bool RecursiveDelete(
dumi@chromium.orgc980e402010-08-21 07:42:50 +090054 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_