Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / file_system_provider / fileapi / provider_async_file_util.cc
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.
4
5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.h"
6
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"
18
19 using content::BrowserThread;
20
21 namespace chromeos {
22 namespace file_system_provider {
23 namespace internal {
24 namespace {
25
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());
34     return;
35   }
36
37   parser.file_system()->GetMetadata(parser.file_path(), callback);
38 }
39
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));
46 }
47
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 */);
58     return;
59   }
60
61   parser.file_system()->ReadDirectory(parser.file_path(), callback);
62 }
63
64 // Routes the response of ReadDirectory back to the IO thread.
65 void OnReadDirectory(
66     const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback,
67     base::File::Error result,
68     const fileapi::AsyncFileUtil::EntryList& entry_list,
69     bool has_more) {
70   BrowserThread::PostTask(BrowserThread::IO,
71                           FROM_HERE,
72                           base::Bind(callback, result, entry_list, has_more));
73 }
74
75 }  // namespace
76
77 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {}
78
79 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {}
80
81 void ProviderAsyncFileUtil::CreateOrOpen(
82     scoped_ptr<fileapi::FileSystemOperationContext> context,
83     const fileapi::FileSystemURL& url,
84     int file_flags,
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),
94                  base::Closure());
95     return;
96   }
97
98   NOTIMPLEMENTED();
99   callback.Run(base::File::FILE_ERROR_NOT_FOUND,
100                base::PassPlatformFile(&platform_file),
101                base::Closure());
102 }
103
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 */);
110 }
111
112 void ProviderAsyncFileUtil::CreateDirectory(
113     scoped_ptr<fileapi::FileSystemOperationContext> context,
114     const fileapi::FileSystemURL& url,
115     bool exclusive,
116     bool recursive,
117     const StatusCallback& callback) {
118   DCHECK_CURRENTLY_ON(BrowserThread::IO);
119   callback.Run(base::File::FILE_ERROR_SECURITY);
120 }
121
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,
128                           FROM_HERE,
129                           base::Bind(&GetFileInfoOnUIThread,
130                                      base::Passed(&context),
131                                      url,
132                                      base::Bind(&OnGetFileInfo, callback)));
133 }
134
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,
141                           FROM_HERE,
142                           base::Bind(&ReadDirectoryOnUIThread,
143                                      base::Passed(&context),
144                                      url,
145                                      base::Bind(&OnReadDirectory, callback)));
146 }
147
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);
156 }
157
158 void ProviderAsyncFileUtil::Truncate(
159     scoped_ptr<fileapi::FileSystemOperationContext> context,
160     const fileapi::FileSystemURL& url,
161     int64 length,
162     const StatusCallback& callback) {
163   DCHECK_CURRENTLY_ON(BrowserThread::IO);
164   callback.Run(base::File::FILE_ERROR_SECURITY);
165 }
166
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);
176 }
177
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);
186 }
187
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);
195 }
196
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);
203 }
204
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);
211 }
212
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);
219 }
220
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);
226   NOTIMPLEMENTED();
227   callback.Run(base::File::FILE_ERROR_NOT_FOUND,
228                base::File::Info(),
229                base::FilePath(),
230                scoped_refptr<webkit_blob::ShareableFileReference>());
231 }
232
233 }  // namespace internal
234 }  // namespace file_system_provider
235 }  // namespace chromeos