summaryrefslogtreecommitdiffstats
path: root/webkit/chromeos/fileapi/file_util_async.h
blob: 3cec09dbd6ac35083199fc0602186de15dc3e3c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_
#define WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_

#include "base/callback.h"
#include "base/files/file_util_proxy.h"
#include "base/platform_file.h"
#include "webkit/chromeos/fileapi/async_file_stream.h"

namespace fileapi {

using base::PlatformFileError;

// The interface class of asynchronous file utils. All functions are pure
// virtual.
class FileUtilAsync {
 public:
  virtual ~FileUtilAsync() {}

  typedef base::FileUtilProxy::Entry DirectoryEntry;

  // Used for GetFileInfo(). |result| is the return code of the operation,
  // and |file_info| is the obtained file info.
  typedef base::Callback<void(
      PlatformFileError result,
      const base::PlatformFileInfo& file_info)> GetFileInfoCallback;

  // Used for Create(), etc. |result| is the return code of the operation.
  typedef base::Callback<void(PlatformFileError)> StatusCallback;

  // Used for Open(). |result| is the return code of the operation, and
  // |stream| is the stream of the opened file.
  typedef base::Callback<void(
      PlatformFileError result,
      AsyncFileStream* stream)> OpenCallback;

  typedef std::vector<DirectoryEntry> FileList;

  // Used for ReadDirectoryCallback(). |result| is the return code of the
  // operation, |file_list| is the list of files read, and |completed| is
  // true if all files are read.
  typedef base::Callback<void(
      PlatformFileError result,
      const FileList& file_list,
      bool completed)> ReadDirectoryCallback;

  // Opens a file of the given |file_path| with |flags|. On success,
  // PLATFORM_FILE_OK is passed to |callback| with a pointer to newly
  // created AsyncFileStream object. The caller should delete the
  // stream. On failure, an error code is passed instead.
  virtual void Open(const FilePath& file_path,
                    int file_flags,  // PlatformFileFlags
                    const OpenCallback& callback) = 0;

  // Gets file info of the given |file_path|. On success,
  // PLATFORM_FILE_OK is passed to |callback| with the the obtained file
  // info. On failure, an error code is passed instead.
  virtual void GetFileInfo(const FilePath& file_path,
                           const GetFileInfoCallback& callback) = 0;

  // Creates a file of the given |file_path|. On success,
  // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code
  // is passed instead.
  virtual void Create(const FilePath& file_path,
                      const StatusCallback& callback) = 0;

  // Truncates a file of the given |file_path| to |length|. On success,
  // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code
  // is passed instead.
  virtual void Truncate(const FilePath& file_path,
                        int64 length,
                        const StatusCallback& callback) = 0;

  // Modifies the timestamps of a file of the given |file_path|. On
  // success, PLATFORM_FILE_OK is passed to |callback|. On failure, an
  // error code is passed instead.
  virtual void Touch(const FilePath& file_path,
                     const base::Time& last_access_time,
                     const base::Time& last_modified_time,
                     const StatusCallback& callback) = 0;

  // Removes a file or directory of the given |file_path|. If |recursive|
  // is true, removes the contents of the given directory recursively. On
  // success, PLATFORM_FILE_OK is passed to |callback|. On failure, an
  // error code is passed instead.
  virtual void Remove(const FilePath& file_path,
                      bool recursive,
                      const StatusCallback& callback) = 0;

  // Creates a directory of the given |dir_path|. On success,
  // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code
  // is passed instead.
  virtual void CreateDirectory(const FilePath& dir_path,
                               const StatusCallback& callback) = 0;

  // Reads a directory of the given |dir_path|. On success,
  // PLATFORM_FILE_OK is passed to |callback| with the list of files, and
  // a boolean value indicating if all files are read. On failure, an
  // error code is passed instead.
  //
  // The ReadDirectoryCallback may be called several times, returning the
  // portions of the whole directory listing. The reference to vector with
  // DirectoryEntry objects, passed to callback is guaranteed to contain the
  // results of the operation only while callback is running.
  //
  // The implementations of FileUtilAsync should be careful to populate the
  // vector on the same thread, on which the callback is called. Otherwise,
  // if callback is called through PostTask, the data might get overwritten
  // before callback is actually called.
  //
  // TODO(olege): Maybe make it possible to read only a part of the directory.
  virtual void ReadDirectory(const FilePath& dir_path,
                             const ReadDirectoryCallback& callback) = 0;

  // TODO(olege): Add LocalCopy and LocalMove.
};

}  // namespace fileapi

#endif  // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_