blob: cd6b158cabc6a85d0713915dade1279fc1121db2 [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:
20 // This callback is used by methods that report success with a bool. It is
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.
23 typedef Callback1<bool /* succeeded */>::Type StatusCallback;
24
25 // Creates or opens a file with the given flags. It is invalid to pass NULL
26 // for the callback.
27 typedef Callback2<base::PassPlatformFile, bool /* created */>::Type
28 CreateOrOpenCallback;
29 static void CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
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.
36 typedef Callback2<base::PassPlatformFile, FilePath>::Type
37 CreateTemporaryCallback;
38 static void CreateTemporary(
39 scoped_refptr<MessageLoopProxy> message_loop_proxy,
40 CreateTemporaryCallback* callback);
41
42 // Close the given file handle.
43 static void Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
44 base::PlatformFile,
45 StatusCallback* callback);
46
47 // Deletes a file or empty directory.
48 static void Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy,
49 const FilePath& file_path,
50 StatusCallback* callback);
51
52 // Deletes a directory and all of its contents.
53 static void RecursiveDelete(
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_