| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/fileapi/file_system_operation_impl.h" | 5 #include "storage/browser/fileapi/file_system_operation_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "base/trace_event/trace_event.h" |
| 11 #include "net/base/escape.h" | 12 #include "net/base/escape.h" |
| 12 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
| 13 #include "storage/browser/blob/shareable_file_reference.h" | 14 #include "storage/browser/blob/shareable_file_reference.h" |
| 14 #include "storage/browser/fileapi/async_file_util.h" | 15 #include "storage/browser/fileapi/async_file_util.h" |
| 15 #include "storage/browser/fileapi/copy_or_move_operation_delegate.h" | 16 #include "storage/browser/fileapi/copy_or_move_operation_delegate.h" |
| 16 #include "storage/browser/fileapi/file_observers.h" | 17 #include "storage/browser/fileapi/file_observers.h" |
| 17 #include "storage/browser/fileapi/file_system_backend.h" | 18 #include "storage/browser/fileapi/file_system_backend.h" |
| 18 #include "storage/browser/fileapi/file_system_context.h" | 19 #include "storage/browser/fileapi/file_system_context.h" |
| 19 #include "storage/browser/fileapi/file_system_file_util.h" | 20 #include "storage/browser/fileapi/file_system_file_util.h" |
| 20 #include "storage/browser/fileapi/remove_operation_delegate.h" | 21 #include "storage/browser/fileapi/remove_operation_delegate.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return new FileSystemOperationImpl(url, file_system_context, | 57 return new FileSystemOperationImpl(url, file_system_context, |
| 57 operation_context.Pass()); | 58 operation_context.Pass()); |
| 58 } | 59 } |
| 59 | 60 |
| 60 FileSystemOperationImpl::~FileSystemOperationImpl() { | 61 FileSystemOperationImpl::~FileSystemOperationImpl() { |
| 61 } | 62 } |
| 62 | 63 |
| 63 void FileSystemOperationImpl::CreateFile(const FileSystemURL& url, | 64 void FileSystemOperationImpl::CreateFile(const FileSystemURL& url, |
| 64 bool exclusive, | 65 bool exclusive, |
| 65 const StatusCallback& callback) { | 66 const StatusCallback& callback) { |
| 67 // crbug.com/349708 |
| 68 TRACE_EVENT0("io", "FileSystemOperationImpl::CreateFile"); |
| 69 |
| 66 DCHECK(SetPendingOperationType(kOperationCreateFile)); | 70 DCHECK(SetPendingOperationType(kOperationCreateFile)); |
| 71 |
| 67 GetUsageAndQuotaThenRunTask( | 72 GetUsageAndQuotaThenRunTask( |
| 68 url, | 73 url, |
| 69 base::Bind(&FileSystemOperationImpl::DoCreateFile, | 74 base::Bind(&FileSystemOperationImpl::DoCreateFile, |
| 70 weak_factory_.GetWeakPtr(), url, callback, exclusive), | 75 weak_factory_.GetWeakPtr(), url, callback, exclusive), |
| 71 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 76 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
| 72 } | 77 } |
| 73 | 78 |
| 74 void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url, | 79 void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url, |
| 75 bool exclusive, | 80 bool exclusive, |
| 76 bool recursive, | 81 bool recursive, |
| 77 const StatusCallback& callback) { | 82 const StatusCallback& callback) { |
| 78 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); | 83 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); |
| 84 |
| 85 // crbug.com/349708 |
| 86 TRACE_EVENT0("io", "FileSystemOperationImpl::CreateDirectory"); |
| 87 |
| 79 GetUsageAndQuotaThenRunTask( | 88 GetUsageAndQuotaThenRunTask( |
| 80 url, | 89 url, |
| 81 base::Bind(&FileSystemOperationImpl::DoCreateDirectory, | 90 base::Bind(&FileSystemOperationImpl::DoCreateDirectory, |
| 82 weak_factory_.GetWeakPtr(), url, callback, | 91 weak_factory_.GetWeakPtr(), url, callback, |
| 83 exclusive, recursive), | 92 exclusive, recursive), |
| 84 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 93 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
| 85 } | 94 } |
| 86 | 95 |
| 87 void FileSystemOperationImpl::Copy( | 96 void FileSystemOperationImpl::Copy( |
| 88 const FileSystemURL& src_url, | 97 const FileSystemURL& src_url, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 file_writer_delegate_ = writer_delegate.Pass(); | 192 file_writer_delegate_ = writer_delegate.Pass(); |
| 184 file_writer_delegate_->Start( | 193 file_writer_delegate_->Start( |
| 185 blob_request.Pass(), | 194 blob_request.Pass(), |
| 186 base::Bind(&FileSystemOperationImpl::DidWrite, | 195 base::Bind(&FileSystemOperationImpl::DidWrite, |
| 187 weak_factory_.GetWeakPtr(), url, callback)); | 196 weak_factory_.GetWeakPtr(), url, callback)); |
| 188 } | 197 } |
| 189 | 198 |
| 190 void FileSystemOperationImpl::Truncate(const FileSystemURL& url, int64 length, | 199 void FileSystemOperationImpl::Truncate(const FileSystemURL& url, int64 length, |
| 191 const StatusCallback& callback) { | 200 const StatusCallback& callback) { |
| 192 DCHECK(SetPendingOperationType(kOperationTruncate)); | 201 DCHECK(SetPendingOperationType(kOperationTruncate)); |
| 202 |
| 203 // crbug.com/349708 |
| 204 TRACE_EVENT0("io", "FileSystemOperationImpl::Truncate"); |
| 205 |
| 193 GetUsageAndQuotaThenRunTask( | 206 GetUsageAndQuotaThenRunTask( |
| 194 url, | 207 url, |
| 195 base::Bind(&FileSystemOperationImpl::DoTruncate, | 208 base::Bind(&FileSystemOperationImpl::DoTruncate, |
| 196 weak_factory_.GetWeakPtr(), url, callback, length), | 209 weak_factory_.GetWeakPtr(), url, callback, length), |
| 197 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 210 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
| 198 } | 211 } |
| 199 | 212 |
| 200 void FileSystemOperationImpl::TouchFile(const FileSystemURL& url, | 213 void FileSystemOperationImpl::TouchFile(const FileSystemURL& url, |
| 201 const base::Time& last_access_time, | 214 const base::Time& last_access_time, |
| 202 const base::Time& last_modified_time, | 215 const base::Time& last_modified_time, |
| 203 const StatusCallback& callback) { | 216 const StatusCallback& callback) { |
| 204 DCHECK(SetPendingOperationType(kOperationTouchFile)); | 217 DCHECK(SetPendingOperationType(kOperationTouchFile)); |
| 218 |
| 219 // crbug.com/349708 |
| 220 TRACE_EVENT0("io", "FileSystemOperationImpl::TouchFile"); |
| 221 |
| 205 async_file_util_->Touch( | 222 async_file_util_->Touch( |
| 206 operation_context_.Pass(), url, | 223 operation_context_.Pass(), url, |
| 207 last_access_time, last_modified_time, | 224 last_access_time, last_modified_time, |
| 208 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 225 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
| 209 weak_factory_.GetWeakPtr(), callback)); | 226 weak_factory_.GetWeakPtr(), callback)); |
| 210 } | 227 } |
| 211 | 228 |
| 212 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, | 229 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, |
| 213 int file_flags, | 230 int file_flags, |
| 214 const OpenFileCallback& callback) { | 231 const OpenFileCallback& callback) { |
| 215 DCHECK(SetPendingOperationType(kOperationOpenFile)); | 232 DCHECK(SetPendingOperationType(kOperationOpenFile)); |
| 216 | 233 |
| 217 if (file_flags & | 234 if (file_flags & |
| 218 (base::File::FLAG_TEMPORARY | base::File::FLAG_HIDDEN)) { | 235 (base::File::FLAG_TEMPORARY | base::File::FLAG_HIDDEN)) { |
| 219 callback.Run(base::File(base::File::FILE_ERROR_FAILED), | 236 callback.Run(base::File(base::File::FILE_ERROR_FAILED), |
| 220 base::Closure()); | 237 base::Closure()); |
| 221 return; | 238 return; |
| 222 } | 239 } |
| 240 |
| 241 // crbug.com/349708 |
| 242 TRACE_EVENT0("io", "FileSystemOperationImpl::OpenFile"); |
| 243 |
| 223 GetUsageAndQuotaThenRunTask( | 244 GetUsageAndQuotaThenRunTask( |
| 224 url, | 245 url, |
| 225 base::Bind(&FileSystemOperationImpl::DoOpenFile, | 246 base::Bind(&FileSystemOperationImpl::DoOpenFile, |
| 226 weak_factory_.GetWeakPtr(), | 247 weak_factory_.GetWeakPtr(), |
| 227 url, callback, file_flags), | 248 url, callback, file_flags), |
| 228 base::Bind(callback, Passed(base::File(base::File::FILE_ERROR_FAILED)), | 249 base::Bind(callback, Passed(base::File(base::File::FILE_ERROR_FAILED)), |
| 229 base::Closure())); | 250 base::Closure())); |
| 230 } | 251 } |
| 231 | 252 |
| 232 // We can only get here on a write or truncate that's not yet completed. | 253 // We can only get here on a write or truncate that's not yet completed. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 255 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); | 276 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); |
| 256 async_file_util_->CreateSnapshotFile( | 277 async_file_util_->CreateSnapshotFile( |
| 257 operation_context_.Pass(), url, callback); | 278 operation_context_.Pass(), url, callback); |
| 258 } | 279 } |
| 259 | 280 |
| 260 void FileSystemOperationImpl::CopyInForeignFile( | 281 void FileSystemOperationImpl::CopyInForeignFile( |
| 261 const base::FilePath& src_local_disk_file_path, | 282 const base::FilePath& src_local_disk_file_path, |
| 262 const FileSystemURL& dest_url, | 283 const FileSystemURL& dest_url, |
| 263 const StatusCallback& callback) { | 284 const StatusCallback& callback) { |
| 264 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); | 285 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); |
| 286 |
| 287 // crbug.com/349708 |
| 288 TRACE_EVENT0("io", "FileSystemOperationImpl::CopyInForeinFile"); |
| 289 |
| 265 GetUsageAndQuotaThenRunTask( | 290 GetUsageAndQuotaThenRunTask( |
| 266 dest_url, | 291 dest_url, |
| 267 base::Bind(&FileSystemOperationImpl::DoCopyInForeignFile, | 292 base::Bind(&FileSystemOperationImpl::DoCopyInForeignFile, |
| 268 weak_factory_.GetWeakPtr(), src_local_disk_file_path, dest_url, | 293 weak_factory_.GetWeakPtr(), src_local_disk_file_path, dest_url, |
| 269 callback), | 294 callback), |
| 270 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 295 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
| 271 } | 296 } |
| 272 | 297 |
| 273 void FileSystemOperationImpl::RemoveFile( | 298 void FileSystemOperationImpl::RemoveFile( |
| 274 const FileSystemURL& url, | 299 const FileSystemURL& url, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 292 | 317 |
| 293 void FileSystemOperationImpl::CopyFileLocal( | 318 void FileSystemOperationImpl::CopyFileLocal( |
| 294 const FileSystemURL& src_url, | 319 const FileSystemURL& src_url, |
| 295 const FileSystemURL& dest_url, | 320 const FileSystemURL& dest_url, |
| 296 CopyOrMoveOption option, | 321 CopyOrMoveOption option, |
| 297 const CopyFileProgressCallback& progress_callback, | 322 const CopyFileProgressCallback& progress_callback, |
| 298 const StatusCallback& callback) { | 323 const StatusCallback& callback) { |
| 299 DCHECK(SetPendingOperationType(kOperationCopy)); | 324 DCHECK(SetPendingOperationType(kOperationCopy)); |
| 300 DCHECK(src_url.IsInSameFileSystem(dest_url)); | 325 DCHECK(src_url.IsInSameFileSystem(dest_url)); |
| 301 | 326 |
| 327 // crbug.com/349708 |
| 328 TRACE_EVENT0("io", "FileSystemOperationImpl::CopyFileLocal"); |
| 329 |
| 302 GetUsageAndQuotaThenRunTask( | 330 GetUsageAndQuotaThenRunTask( |
| 303 dest_url, | 331 dest_url, |
| 304 base::Bind(&FileSystemOperationImpl::DoCopyFileLocal, | 332 base::Bind(&FileSystemOperationImpl::DoCopyFileLocal, |
| 305 weak_factory_.GetWeakPtr(), src_url, dest_url, option, | 333 weak_factory_.GetWeakPtr(), src_url, dest_url, option, |
| 306 progress_callback, callback), | 334 progress_callback, callback), |
| 307 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 335 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
| 308 } | 336 } |
| 309 | 337 |
| 310 void FileSystemOperationImpl::MoveFileLocal( | 338 void FileSystemOperationImpl::MoveFileLocal( |
| 311 const FileSystemURL& src_url, | 339 const FileSystemURL& src_url, |
| 312 const FileSystemURL& dest_url, | 340 const FileSystemURL& dest_url, |
| 313 CopyOrMoveOption option, | 341 CopyOrMoveOption option, |
| 314 const StatusCallback& callback) { | 342 const StatusCallback& callback) { |
| 315 DCHECK(SetPendingOperationType(kOperationMove)); | 343 DCHECK(SetPendingOperationType(kOperationMove)); |
| 316 DCHECK(src_url.IsInSameFileSystem(dest_url)); | 344 DCHECK(src_url.IsInSameFileSystem(dest_url)); |
| 345 |
| 346 // crbug.com/349708 |
| 347 TRACE_EVENT0("io", "FileSystemOperationImpl::MoveFileLocal"); |
| 348 |
| 317 GetUsageAndQuotaThenRunTask( | 349 GetUsageAndQuotaThenRunTask( |
| 318 dest_url, | 350 dest_url, |
| 319 base::Bind(&FileSystemOperationImpl::DoMoveFileLocal, | 351 base::Bind(&FileSystemOperationImpl::DoMoveFileLocal, |
| 320 weak_factory_.GetWeakPtr(), | 352 weak_factory_.GetWeakPtr(), |
| 321 src_url, dest_url, option, callback), | 353 src_url, dest_url, option, callback), |
| 322 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 354 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
| 323 } | 355 } |
| 324 | 356 |
| 325 base::File::Error FileSystemOperationImpl::SyncGetPlatformPath( | 357 base::File::Error FileSystemOperationImpl::SyncGetPlatformPath( |
| 326 const FileSystemURL& url, | 358 const FileSystemURL& url, |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 } | 587 } |
| 556 | 588 |
| 557 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { | 589 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { |
| 558 if (pending_operation_ != kOperationNone) | 590 if (pending_operation_ != kOperationNone) |
| 559 return false; | 591 return false; |
| 560 pending_operation_ = type; | 592 pending_operation_ = type; |
| 561 return true; | 593 return true; |
| 562 } | 594 } |
| 563 | 595 |
| 564 } // namespace storage | 596 } // namespace storage |
| OLD | NEW |