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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 // If the file already existed, then return success anyway, since it is not | 153 // If the file already existed, then return success anyway, since it is not |
154 // an error. | 154 // an error. |
155 const base::File::Error error = | 155 const base::File::Error error = |
156 result == base::File::FILE_ERROR_EXISTS ? base::File::FILE_OK : result; | 156 result == base::File::FILE_ERROR_EXISTS ? base::File::FILE_OK : result; |
157 | 157 |
158 BrowserThread::PostTask( | 158 BrowserThread::PostTask( |
159 BrowserThread::IO, FROM_HERE, base::Bind(callback, error, created)); | 159 BrowserThread::IO, FROM_HERE, base::Bind(callback, error, created)); |
160 } | 160 } |
161 | 161 |
| 162 // Executes CopyEntry on the UI thread. |
| 163 void CopyEntryOnUIThread( |
| 164 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 165 const fileapi::FileSystemURL& source_url, |
| 166 const fileapi::FileSystemURL& target_url, |
| 167 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 168 util::FileSystemURLParser source_parser(source_url); |
| 169 util::FileSystemURLParser target_parser(target_url); |
| 170 |
| 171 if (!source_parser.Parse() || !target_parser.Parse() || |
| 172 source_parser.file_system() != target_parser.file_system()) { |
| 173 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 174 return; |
| 175 } |
| 176 |
| 177 target_parser.file_system()->CopyEntry( |
| 178 source_parser.file_path(), target_parser.file_path(), callback); |
| 179 } |
| 180 |
| 181 // Routes the response of CopyEntry to a callback of CopyLocalFile() on the |
| 182 // IO thread. |
| 183 void OnCopyEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, |
| 184 base::File::Error result) { |
| 185 BrowserThread::PostTask( |
| 186 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 187 } |
| 188 |
162 } // namespace | 189 } // namespace |
163 | 190 |
164 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} | 191 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} |
165 | 192 |
166 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} | 193 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} |
167 | 194 |
168 void ProviderAsyncFileUtil::CreateOrOpen( | 195 void ProviderAsyncFileUtil::CreateOrOpen( |
169 scoped_ptr<fileapi::FileSystemOperationContext> context, | 196 scoped_ptr<fileapi::FileSystemOperationContext> context, |
170 const fileapi::FileSystemURL& url, | 197 const fileapi::FileSystemURL& url, |
171 int file_flags, | 198 int file_flags, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 } | 289 } |
263 | 290 |
264 void ProviderAsyncFileUtil::CopyFileLocal( | 291 void ProviderAsyncFileUtil::CopyFileLocal( |
265 scoped_ptr<fileapi::FileSystemOperationContext> context, | 292 scoped_ptr<fileapi::FileSystemOperationContext> context, |
266 const fileapi::FileSystemURL& src_url, | 293 const fileapi::FileSystemURL& src_url, |
267 const fileapi::FileSystemURL& dest_url, | 294 const fileapi::FileSystemURL& dest_url, |
268 CopyOrMoveOption option, | 295 CopyOrMoveOption option, |
269 const CopyFileProgressCallback& progress_callback, | 296 const CopyFileProgressCallback& progress_callback, |
270 const StatusCallback& callback) { | 297 const StatusCallback& callback) { |
271 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 298 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
272 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 299 // TODO(mtomasz): Consier adding support for options (preserving last modified |
| 300 // time) as well as the progress callback. |
| 301 BrowserThread::PostTask(BrowserThread::UI, |
| 302 FROM_HERE, |
| 303 base::Bind(&CopyEntryOnUIThread, |
| 304 base::Passed(&context), |
| 305 src_url, |
| 306 dest_url, |
| 307 base::Bind(&OnCopyEntry, callback))); |
273 } | 308 } |
274 | 309 |
275 void ProviderAsyncFileUtil::MoveFileLocal( | 310 void ProviderAsyncFileUtil::MoveFileLocal( |
276 scoped_ptr<fileapi::FileSystemOperationContext> context, | 311 scoped_ptr<fileapi::FileSystemOperationContext> context, |
277 const fileapi::FileSystemURL& src_url, | 312 const fileapi::FileSystemURL& src_url, |
278 const fileapi::FileSystemURL& dest_url, | 313 const fileapi::FileSystemURL& dest_url, |
279 CopyOrMoveOption option, | 314 CopyOrMoveOption option, |
280 const StatusCallback& callback) { | 315 const StatusCallback& callback) { |
281 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 316 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
282 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 317 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 NOTIMPLEMENTED(); | 376 NOTIMPLEMENTED(); |
342 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 377 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
343 base::File::Info(), | 378 base::File::Info(), |
344 base::FilePath(), | 379 base::FilePath(), |
345 scoped_refptr<webkit_blob::ShareableFileReference>()); | 380 scoped_refptr<webkit_blob::ShareableFileReference>()); |
346 } | 381 } |
347 | 382 |
348 } // namespace internal | 383 } // namespace internal |
349 } // namespace file_system_provider | 384 } // namespace file_system_provider |
350 } // namespace chromeos | 385 } // namespace chromeos |
OLD | NEW |