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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
// 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_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_
#define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_
#include <vector>
#include "base/callback.h"
#include "base/file_path.h"
#include "base/file_util_proxy.h"
#include "base/memory/ref_counted.h"
#include "base/platform_file.h"
#include "base/tracked_objects.h"
namespace fileapi {
using base::PlatformFile;
using base::PlatformFileError;
using base::PlatformFileInfo;
class FileSystemFileUtil;
class FileSystemOperationContext;
class FileSystemPath;
// This class provides asynchronous access to FileSystemFileUtil methods for
// FileSystem API operations. This also implements cross-FileUtil copy/move
// operations on top of FileSystemFileUtil methods.
class FileSystemFileUtilProxy {
public:
// Some of the proxy routines are just wrapping around the FileUtilProxy's
// relay methods, so we use the same types as FileUtilProxy for them.
typedef base::FileUtilProxy::Entry Entry;
typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback;
typedef base::Callback<void(PlatformFileError status)> StatusCallback;
typedef base::Callback<void(PlatformFileError status,
bool created)> EnsureFileExistsCallback;
typedef base::Callback<void(PlatformFileError status,
const PlatformFileInfo& info,
const FilePath& platform_path)>
GetFileInfoCallback;
typedef base::Callback<void(PlatformFileError,
const std::vector<Entry>&,
bool has_more)> ReadDirectoryCallback;
// Deletes a file or a directory on the given context's file_task_runner.
// It is an error to delete a non-empty directory with recursive=false.
static bool Delete(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
bool recursive,
const StatusCallback& callback);
// Creates or opens a file with the given flags by calling |file_util|'s
// CreateOrOpen method on the given context's file_task_runner.
static bool CreateOrOpen(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
int file_flags,
const CreateOrOpenCallback& callback);
// Copies a file or a directory from |src_path| to |dest_path| by calling
// FileSystemFileUtil's following methods on the given context's
// file_task_runner.
// - CopyOrMoveFile() for same-filesystem operations
// - CopyInForeignFile() for (limited) cross-filesystem operations
//
// Error cases:
// If destination's parent doesn't exist.
// If source dir exists but destination path is an existing file.
// If source file exists but destination path is an existing directory.
// If source is a parent of destination.
// If source doesn't exist.
// If source and dest are the same path in the same filesystem.
static bool Copy(
FileSystemOperationContext* context,
FileSystemFileUtil* src_util,
FileSystemFileUtil* dest_util,
const FileSystemPath& src_path,
const FileSystemPath& dest_path,
const StatusCallback& callback);
// Moves a file or a directory from |src_path| to |dest_path| by calling
// FileSystemFileUtil's following methods on the given context's
// file_task_runner.
// - CopyOrMoveFile() for same-filesystem operations
// - CopyInForeignFile() for (limited) cross-filesystem operations
//
// This method returns an error on the same error cases with Copy.
static bool Move(
FileSystemOperationContext* context,
FileSystemFileUtil* src_util,
FileSystemFileUtil* dest_util,
const FileSystemPath& src_path,
const FileSystemPath& dest_path,
const StatusCallback& callback);
// Ensures that the given |path| exist by calling |file_util|'s
// EnsureFileExists method on the given context's file_task_runner.
static bool EnsureFileExists(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
const EnsureFileExistsCallback& callback);
// Creates directory at a given path by calling |file_util|'s
// CreateDirectory method on the given context's file_task_runner.
static bool CreateDirectory(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
bool exclusive,
bool recursive,
const StatusCallback& callback);
// Retrieves the information about a file by calling |file_util|'s
// GetFileInfo method on the given context's file_task_runner.
static bool GetFileInfo(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
const GetFileInfoCallback& callback);
// Reads the filenames in |path| by calling |file_util|'s
// ReadDirectory method on the given context's file_task_runner.
// TODO: this should support returning entries in multiple chunks.
static bool ReadDirectory(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
const ReadDirectoryCallback& callback);
// Touches a file by calling |file_util|'s Touch method
// on the given context's file_task_runner.
static bool Touch(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
const StatusCallback& callback);
// Truncates a file to the given length by calling |file_util|'s
// Truncate method on the given context's file_task_runner.
static bool Truncate(
FileSystemOperationContext* context,
FileSystemFileUtil* file_util,
const FileSystemPath& path,
int64 length,
const StatusCallback& callback);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy);
};
} // namespace fileapi
#endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_
|