1 // Copyright 2014 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.
5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.h"
7 #include "base/callback.h"
8 #include "base/files/file.h"
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/platform_file.h"
12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "webkit/browser/fileapi/file_system_operation_context.h"
16 #include "webkit/browser/fileapi/file_system_url.h"
17 #include "webkit/common/blob/shareable_file_reference.h"
19 using content::BrowserThread;
22 namespace file_system_provider {
26 // Executes GetFileInfo on the UI thread.
27 void GetFileInfoOnUIThread(
28 scoped_ptr<fileapi::FileSystemOperationContext> context,
29 const fileapi::FileSystemURL& url,
30 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) {
31 util::FileSystemURLParser parser(url);
32 if (!parser.Parse()) {
33 callback.Run(base::File::FILE_ERROR_NOT_FOUND, base::File::Info());
37 parser.file_system()->GetMetadata(parser.file_path(), callback);
40 // Routes the response of GetFileInfo back to the IO thread.
41 void OnGetFileInfo(const fileapi::AsyncFileUtil::GetFileInfoCallback& callback,
42 base::File::Error result,
43 const base::File::Info& file_info) {
44 BrowserThread::PostTask(
45 BrowserThread::IO, FROM_HERE, base::Bind(callback, result, file_info));
48 // Executes ReadDirectory on the UI thread.
49 void ReadDirectoryOnUIThread(
50 scoped_ptr<fileapi::FileSystemOperationContext> context,
51 const fileapi::FileSystemURL& url,
52 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) {
53 util::FileSystemURLParser parser(url);
54 if (!parser.Parse()) {
55 callback.Run(base::File::FILE_ERROR_NOT_FOUND,
56 fileapi::AsyncFileUtil::EntryList(),
57 false /* has_more */);
61 parser.file_system()->ReadDirectory(parser.file_path(), callback);
64 // Routes the response of ReadDirectory back to the IO thread.
66 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback,
67 base::File::Error result,
68 const fileapi::AsyncFileUtil::EntryList& entry_list,
70 BrowserThread::PostTask(BrowserThread::IO,
72 base::Bind(callback, result, entry_list, has_more));
77 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {}
79 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {}
81 void ProviderAsyncFileUtil::CreateOrOpen(
82 scoped_ptr<fileapi::FileSystemOperationContext> context,
83 const fileapi::FileSystemURL& url,
85 const CreateOrOpenCallback& callback) {
86 DCHECK_CURRENTLY_ON(BrowserThread::IO);
87 base::PlatformFile platform_file = base::kInvalidPlatformFileValue;
88 if ((file_flags & base::PLATFORM_FILE_CREATE) ||
89 (file_flags & base::PLATFORM_FILE_OPEN_ALWAYS) ||
90 (file_flags & base::PLATFORM_FILE_CREATE_ALWAYS) ||
91 (file_flags & base::PLATFORM_FILE_OPEN_TRUNCATED)) {
92 callback.Run(base::File::FILE_ERROR_SECURITY,
93 base::PassPlatformFile(&platform_file),
99 callback.Run(base::File::FILE_ERROR_NOT_FOUND,
100 base::PassPlatformFile(&platform_file),
104 void ProviderAsyncFileUtil::EnsureFileExists(
105 scoped_ptr<fileapi::FileSystemOperationContext> context,
106 const fileapi::FileSystemURL& url,
107 const EnsureFileExistsCallback& callback) {
108 DCHECK_CURRENTLY_ON(BrowserThread::IO);
109 callback.Run(base::File::FILE_ERROR_SECURITY, false /* created */);
112 void ProviderAsyncFileUtil::CreateDirectory(
113 scoped_ptr<fileapi::FileSystemOperationContext> context,
114 const fileapi::FileSystemURL& url,
117 const StatusCallback& callback) {
118 DCHECK_CURRENTLY_ON(BrowserThread::IO);
119 callback.Run(base::File::FILE_ERROR_SECURITY);
122 void ProviderAsyncFileUtil::GetFileInfo(
123 scoped_ptr<fileapi::FileSystemOperationContext> context,
124 const fileapi::FileSystemURL& url,
125 const GetFileInfoCallback& callback) {
126 DCHECK_CURRENTLY_ON(BrowserThread::IO);
127 BrowserThread::PostTask(BrowserThread::UI,
129 base::Bind(&GetFileInfoOnUIThread,
130 base::Passed(&context),
132 base::Bind(&OnGetFileInfo, callback)));
135 void ProviderAsyncFileUtil::ReadDirectory(
136 scoped_ptr<fileapi::FileSystemOperationContext> context,
137 const fileapi::FileSystemURL& url,
138 const ReadDirectoryCallback& callback) {
139 DCHECK_CURRENTLY_ON(BrowserThread::IO);
140 BrowserThread::PostTask(BrowserThread::UI,
142 base::Bind(&ReadDirectoryOnUIThread,
143 base::Passed(&context),
145 base::Bind(&OnReadDirectory, callback)));
148 void ProviderAsyncFileUtil::Touch(
149 scoped_ptr<fileapi::FileSystemOperationContext> context,
150 const fileapi::FileSystemURL& url,
151 const base::Time& last_access_time,
152 const base::Time& last_modified_time,
153 const StatusCallback& callback) {
154 DCHECK_CURRENTLY_ON(BrowserThread::IO);
155 callback.Run(base::File::FILE_ERROR_SECURITY);
158 void ProviderAsyncFileUtil::Truncate(
159 scoped_ptr<fileapi::FileSystemOperationContext> context,
160 const fileapi::FileSystemURL& url,
162 const StatusCallback& callback) {
163 DCHECK_CURRENTLY_ON(BrowserThread::IO);
164 callback.Run(base::File::FILE_ERROR_SECURITY);
167 void ProviderAsyncFileUtil::CopyFileLocal(
168 scoped_ptr<fileapi::FileSystemOperationContext> context,
169 const fileapi::FileSystemURL& src_url,
170 const fileapi::FileSystemURL& dest_url,
171 CopyOrMoveOption option,
172 const CopyFileProgressCallback& progress_callback,
173 const StatusCallback& callback) {
174 DCHECK_CURRENTLY_ON(BrowserThread::IO);
175 callback.Run(base::File::FILE_ERROR_SECURITY);
178 void ProviderAsyncFileUtil::MoveFileLocal(
179 scoped_ptr<fileapi::FileSystemOperationContext> context,
180 const fileapi::FileSystemURL& src_url,
181 const fileapi::FileSystemURL& dest_url,
182 CopyOrMoveOption option,
183 const StatusCallback& callback) {
184 DCHECK_CURRENTLY_ON(BrowserThread::IO);
185 callback.Run(base::File::FILE_ERROR_SECURITY);
188 void ProviderAsyncFileUtil::CopyInForeignFile(
189 scoped_ptr<fileapi::FileSystemOperationContext> context,
190 const base::FilePath& src_file_path,
191 const fileapi::FileSystemURL& dest_url,
192 const StatusCallback& callback) {
193 DCHECK_CURRENTLY_ON(BrowserThread::IO);
194 callback.Run(base::File::FILE_ERROR_SECURITY);
197 void ProviderAsyncFileUtil::DeleteFile(
198 scoped_ptr<fileapi::FileSystemOperationContext> context,
199 const fileapi::FileSystemURL& url,
200 const StatusCallback& callback) {
201 DCHECK_CURRENTLY_ON(BrowserThread::IO);
202 callback.Run(base::File::FILE_ERROR_SECURITY);
205 void ProviderAsyncFileUtil::DeleteDirectory(
206 scoped_ptr<fileapi::FileSystemOperationContext> context,
207 const fileapi::FileSystemURL& url,
208 const StatusCallback& callback) {
209 DCHECK_CURRENTLY_ON(BrowserThread::IO);
210 callback.Run(base::File::FILE_ERROR_SECURITY);
213 void ProviderAsyncFileUtil::DeleteRecursively(
214 scoped_ptr<fileapi::FileSystemOperationContext> context,
215 const fileapi::FileSystemURL& url,
216 const StatusCallback& callback) {
217 DCHECK_CURRENTLY_ON(BrowserThread::IO);
218 callback.Run(base::File::FILE_ERROR_SECURITY);
221 void ProviderAsyncFileUtil::CreateSnapshotFile(
222 scoped_ptr<fileapi::FileSystemOperationContext> context,
223 const fileapi::FileSystemURL& url,
224 const CreateSnapshotFileCallback& callback) {
225 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 callback.Run(base::File::FILE_ERROR_NOT_FOUND,
230 scoped_refptr<webkit_blob::ShareableFileReference>());
233 } // namespace internal
234 } // namespace file_system_provider
235 } // namespace chromeos