OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 parser.file_path(), exclusive, recursive, callback); | 100 parser.file_path(), exclusive, recursive, callback); |
101 } | 101 } |
102 | 102 |
103 // Routes the response of CreateDirectory back to the IO thread. | 103 // Routes the response of CreateDirectory back to the IO thread. |
104 void OnCreateDirectory(const fileapi::AsyncFileUtil::StatusCallback& callback, | 104 void OnCreateDirectory(const fileapi::AsyncFileUtil::StatusCallback& callback, |
105 base::File::Error result) { | 105 base::File::Error result) { |
106 BrowserThread::PostTask( | 106 BrowserThread::PostTask( |
107 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 107 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
108 } | 108 } |
109 | 109 |
| 110 // Executes DeleteEntry on the UI thread. |
| 111 void DeleteEntryOnUIThread( |
| 112 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 113 const fileapi::FileSystemURL& url, |
| 114 bool recursive, |
| 115 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 116 util::FileSystemURLParser parser(url); |
| 117 if (!parser.Parse()) { |
| 118 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 119 return; |
| 120 } |
| 121 |
| 122 parser.file_system()->DeleteEntry(parser.file_path(), recursive, callback); |
| 123 } |
| 124 |
| 125 // Routes the response of DeleteEntry back to the IO thread. |
| 126 void OnDeleteEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, |
| 127 base::File::Error result) { |
| 128 BrowserThread::PostTask( |
| 129 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 130 } |
| 131 |
110 } // namespace | 132 } // namespace |
111 | 133 |
112 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} | 134 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} |
113 | 135 |
114 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} | 136 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} |
115 | 137 |
116 void ProviderAsyncFileUtil::CreateOrOpen( | 138 void ProviderAsyncFileUtil::CreateOrOpen( |
117 scoped_ptr<fileapi::FileSystemOperationContext> context, | 139 scoped_ptr<fileapi::FileSystemOperationContext> context, |
118 const fileapi::FileSystemURL& url, | 140 const fileapi::FileSystemURL& url, |
119 int file_flags, | 141 int file_flags, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 const StatusCallback& callback) { | 253 const StatusCallback& callback) { |
232 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 254 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
233 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 255 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); |
234 } | 256 } |
235 | 257 |
236 void ProviderAsyncFileUtil::DeleteFile( | 258 void ProviderAsyncFileUtil::DeleteFile( |
237 scoped_ptr<fileapi::FileSystemOperationContext> context, | 259 scoped_ptr<fileapi::FileSystemOperationContext> context, |
238 const fileapi::FileSystemURL& url, | 260 const fileapi::FileSystemURL& url, |
239 const StatusCallback& callback) { | 261 const StatusCallback& callback) { |
240 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 262 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
241 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 263 BrowserThread::PostTask(BrowserThread::UI, |
| 264 FROM_HERE, |
| 265 base::Bind(&DeleteEntryOnUIThread, |
| 266 base::Passed(&context), |
| 267 url, |
| 268 false, // recursive |
| 269 base::Bind(&OnDeleteEntry, callback))); |
242 } | 270 } |
243 | 271 |
244 void ProviderAsyncFileUtil::DeleteDirectory( | 272 void ProviderAsyncFileUtil::DeleteDirectory( |
245 scoped_ptr<fileapi::FileSystemOperationContext> context, | 273 scoped_ptr<fileapi::FileSystemOperationContext> context, |
246 const fileapi::FileSystemURL& url, | 274 const fileapi::FileSystemURL& url, |
247 const StatusCallback& callback) { | 275 const StatusCallback& callback) { |
248 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 276 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
249 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 277 BrowserThread::PostTask(BrowserThread::UI, |
| 278 FROM_HERE, |
| 279 base::Bind(&DeleteEntryOnUIThread, |
| 280 base::Passed(&context), |
| 281 url, |
| 282 false, // recursive |
| 283 base::Bind(&OnDeleteEntry, callback))); |
250 } | 284 } |
251 | 285 |
252 void ProviderAsyncFileUtil::DeleteRecursively( | 286 void ProviderAsyncFileUtil::DeleteRecursively( |
253 scoped_ptr<fileapi::FileSystemOperationContext> context, | 287 scoped_ptr<fileapi::FileSystemOperationContext> context, |
254 const fileapi::FileSystemURL& url, | 288 const fileapi::FileSystemURL& url, |
255 const StatusCallback& callback) { | 289 const StatusCallback& callback) { |
256 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 290 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
257 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 291 BrowserThread::PostTask(BrowserThread::UI, |
| 292 FROM_HERE, |
| 293 base::Bind(&DeleteEntryOnUIThread, |
| 294 base::Passed(&context), |
| 295 url, |
| 296 true, // recursive |
| 297 base::Bind(&OnDeleteEntry, callback))); |
258 } | 298 } |
259 | 299 |
260 void ProviderAsyncFileUtil::CreateSnapshotFile( | 300 void ProviderAsyncFileUtil::CreateSnapshotFile( |
261 scoped_ptr<fileapi::FileSystemOperationContext> context, | 301 scoped_ptr<fileapi::FileSystemOperationContext> context, |
262 const fileapi::FileSystemURL& url, | 302 const fileapi::FileSystemURL& url, |
263 const CreateSnapshotFileCallback& callback) { | 303 const CreateSnapshotFileCallback& callback) { |
264 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 304 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
265 NOTIMPLEMENTED(); | 305 NOTIMPLEMENTED(); |
266 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 306 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
267 base::File::Info(), | 307 base::File::Info(), |
268 base::FilePath(), | 308 base::FilePath(), |
269 scoped_refptr<webkit_blob::ShareableFileReference>()); | 309 scoped_refptr<webkit_blob::ShareableFileReference>()); |
270 } | 310 } |
271 | 311 |
272 } // namespace internal | 312 } // namespace internal |
273 } // namespace file_system_provider | 313 } // namespace file_system_provider |
274 } // namespace chromeos | 314 } // namespace chromeos |
OLD | NEW |