| 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 "webkit/browser/fileapi/file_system_operation_runner.h" | 5 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "net/url_request/url_request_context.h" | 8 #include "net/url_request/url_request_context.h" |
| 9 #include "webkit/browser/fileapi/file_observers.h" | 9 #include "webkit/browser/fileapi/file_observers.h" |
| 10 #include "webkit/browser/fileapi/file_stream_writer.h" | 10 #include "webkit/browser/fileapi/file_stream_writer.h" |
| 11 #include "webkit/browser/fileapi/file_system_context.h" | 11 #include "webkit/browser/fileapi/file_system_context.h" |
| 12 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
| 12 #include "webkit/browser/fileapi/file_writer_delegate.h" | 13 #include "webkit/browser/fileapi/file_writer_delegate.h" |
| 13 #include "webkit/browser/fileapi/local_file_system_operation.h" | |
| 14 #include "webkit/common/blob/shareable_file_reference.h" | 14 #include "webkit/common/blob/shareable_file_reference.h" |
| 15 | 15 |
| 16 namespace fileapi { | 16 namespace fileapi { |
| 17 | 17 |
| 18 typedef FileSystemOperationRunner::OperationID OperationID; | 18 typedef FileSystemOperationRunner::OperationID OperationID; |
| 19 | 19 |
| 20 const OperationID FileSystemOperationRunner::kErrorOperationID = -1; | 20 const OperationID FileSystemOperationRunner::kErrorOperationID = -1; |
| 21 | 21 |
| 22 FileSystemOperationRunner::~FileSystemOperationRunner() { | 22 FileSystemOperationRunner::~FileSystemOperationRunner() { |
| 23 } | 23 } |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(), | 341 base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(), |
| 342 id, callback)); | 342 id, callback)); |
| 343 return id; | 343 return id; |
| 344 } | 344 } |
| 345 | 345 |
| 346 OperationID FileSystemOperationRunner::CopyInForeignFile( | 346 OperationID FileSystemOperationRunner::CopyInForeignFile( |
| 347 const base::FilePath& src_local_disk_path, | 347 const base::FilePath& src_local_disk_path, |
| 348 const FileSystemURL& dest_url, | 348 const FileSystemURL& dest_url, |
| 349 const StatusCallback& callback) { | 349 const StatusCallback& callback) { |
| 350 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 350 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 351 FileSystemOperation* operation = CreateLocalFileSystemOperation( | 351 FileSystemOperation* operation = CreateFileSystemOperationImpl( |
| 352 dest_url, &error); | 352 dest_url, &error); |
| 353 if (!operation) { | 353 if (!operation) { |
| 354 callback.Run(error); | 354 callback.Run(error); |
| 355 return kErrorOperationID; | 355 return kErrorOperationID; |
| 356 } | 356 } |
| 357 OperationID id = operations_.Add(operation); | 357 OperationID id = operations_.Add(operation); |
| 358 operation->AsLocalFileSystemOperation()->CopyInForeignFile( | 358 operation->AsFileSystemOperationImpl()->CopyInForeignFile( |
| 359 src_local_disk_path, dest_url, | 359 src_local_disk_path, dest_url, |
| 360 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 360 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 361 id, callback)); | 361 id, callback)); |
| 362 return id; | 362 return id; |
| 363 } | 363 } |
| 364 | 364 |
| 365 OperationID FileSystemOperationRunner::RemoveFile( | 365 OperationID FileSystemOperationRunner::RemoveFile( |
| 366 const FileSystemURL& url, | 366 const FileSystemURL& url, |
| 367 const StatusCallback& callback) { | 367 const StatusCallback& callback) { |
| 368 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 368 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 369 FileSystemOperation* operation = CreateLocalFileSystemOperation(url, &error); | 369 FileSystemOperation* operation = CreateFileSystemOperationImpl(url, &error); |
| 370 if (!operation) { | 370 if (!operation) { |
| 371 callback.Run(error); | 371 callback.Run(error); |
| 372 return kErrorOperationID; | 372 return kErrorOperationID; |
| 373 } | 373 } |
| 374 OperationID id = operations_.Add(operation); | 374 OperationID id = operations_.Add(operation); |
| 375 operation->AsLocalFileSystemOperation()->RemoveFile( | 375 operation->AsFileSystemOperationImpl()->RemoveFile( |
| 376 url, | 376 url, |
| 377 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 377 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 378 id, callback)); | 378 id, callback)); |
| 379 return id; | 379 return id; |
| 380 } | 380 } |
| 381 | 381 |
| 382 OperationID FileSystemOperationRunner::RemoveDirectory( | 382 OperationID FileSystemOperationRunner::RemoveDirectory( |
| 383 const FileSystemURL& url, | 383 const FileSystemURL& url, |
| 384 const StatusCallback& callback) { | 384 const StatusCallback& callback) { |
| 385 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 385 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 386 FileSystemOperation* operation = CreateLocalFileSystemOperation(url, &error); | 386 FileSystemOperation* operation = CreateFileSystemOperationImpl(url, &error); |
| 387 if (!operation) { | 387 if (!operation) { |
| 388 callback.Run(error); | 388 callback.Run(error); |
| 389 return kErrorOperationID; | 389 return kErrorOperationID; |
| 390 } | 390 } |
| 391 OperationID id = operations_.Add(operation); | 391 OperationID id = operations_.Add(operation); |
| 392 operation->AsLocalFileSystemOperation()->RemoveDirectory( | 392 operation->AsFileSystemOperationImpl()->RemoveDirectory( |
| 393 url, | 393 url, |
| 394 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 394 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 395 id, callback)); | 395 id, callback)); |
| 396 return id; | 396 return id; |
| 397 } | 397 } |
| 398 | 398 |
| 399 OperationID FileSystemOperationRunner::CopyFileLocal( | 399 OperationID FileSystemOperationRunner::CopyFileLocal( |
| 400 const FileSystemURL& src_url, | 400 const FileSystemURL& src_url, |
| 401 const FileSystemURL& dest_url, | 401 const FileSystemURL& dest_url, |
| 402 const StatusCallback& callback) { | 402 const StatusCallback& callback) { |
| 403 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 403 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 404 FileSystemOperation* operation = CreateLocalFileSystemOperation( | 404 FileSystemOperation* operation = CreateFileSystemOperationImpl( |
| 405 src_url, &error); | 405 src_url, &error); |
| 406 if (!operation) { | 406 if (!operation) { |
| 407 callback.Run(error); | 407 callback.Run(error); |
| 408 return kErrorOperationID; | 408 return kErrorOperationID; |
| 409 } | 409 } |
| 410 OperationID id = operations_.Add(operation); | 410 OperationID id = operations_.Add(operation); |
| 411 operation->AsLocalFileSystemOperation()->CopyFileLocal( | 411 operation->AsFileSystemOperationImpl()->CopyFileLocal( |
| 412 src_url, dest_url, | 412 src_url, dest_url, |
| 413 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 413 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 414 id, callback)); | 414 id, callback)); |
| 415 return id; | 415 return id; |
| 416 } | 416 } |
| 417 | 417 |
| 418 OperationID FileSystemOperationRunner::MoveFileLocal( | 418 OperationID FileSystemOperationRunner::MoveFileLocal( |
| 419 const FileSystemURL& src_url, | 419 const FileSystemURL& src_url, |
| 420 const FileSystemURL& dest_url, | 420 const FileSystemURL& dest_url, |
| 421 const StatusCallback& callback) { | 421 const StatusCallback& callback) { |
| 422 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 422 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 423 FileSystemOperation* operation = CreateLocalFileSystemOperation( | 423 FileSystemOperation* operation = CreateFileSystemOperationImpl( |
| 424 src_url, &error); | 424 src_url, &error); |
| 425 if (!operation) { | 425 if (!operation) { |
| 426 callback.Run(error); | 426 callback.Run(error); |
| 427 return kErrorOperationID; | 427 return kErrorOperationID; |
| 428 } | 428 } |
| 429 OperationID id = operations_.Add(operation); | 429 OperationID id = operations_.Add(operation); |
| 430 operation->AsLocalFileSystemOperation()->MoveFileLocal( | 430 operation->AsFileSystemOperationImpl()->MoveFileLocal( |
| 431 src_url, dest_url, | 431 src_url, dest_url, |
| 432 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 432 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 433 id, callback)); | 433 id, callback)); |
| 434 return id; | 434 return id; |
| 435 } | 435 } |
| 436 | 436 |
| 437 base::PlatformFileError FileSystemOperationRunner::SyncGetPlatformPath( | 437 base::PlatformFileError FileSystemOperationRunner::SyncGetPlatformPath( |
| 438 const FileSystemURL& url, | 438 const FileSystemURL& url, |
| 439 base::FilePath* platform_path) { | 439 base::FilePath* platform_path) { |
| 440 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 440 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 441 FileSystemOperation* operation = CreateLocalFileSystemOperation(url, &error); | 441 FileSystemOperation* operation = CreateFileSystemOperationImpl(url, &error); |
| 442 if (!operation) | 442 if (!operation) |
| 443 return error; | 443 return error; |
| 444 | 444 |
| 445 return operation->AsLocalFileSystemOperation()->SyncGetPlatformPath( | 445 return operation->AsFileSystemOperationImpl()->SyncGetPlatformPath( |
| 446 url, platform_path); | 446 url, platform_path); |
| 447 } | 447 } |
| 448 | 448 |
| 449 FileSystemOperationRunner::FileSystemOperationRunner( | 449 FileSystemOperationRunner::FileSystemOperationRunner( |
| 450 FileSystemContext* file_system_context) | 450 FileSystemContext* file_system_context) |
| 451 : file_system_context_(file_system_context) {} | 451 : file_system_context_(file_system_context) {} |
| 452 | 452 |
| 453 void FileSystemOperationRunner::DidFinish( | 453 void FileSystemOperationRunner::DidFinish( |
| 454 OperationID id, | 454 OperationID id, |
| 455 const StatusCallback& callback, | 455 const StatusCallback& callback, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 const SnapshotFileCallback& callback, | 505 const SnapshotFileCallback& callback, |
| 506 base::PlatformFileError rv, | 506 base::PlatformFileError rv, |
| 507 const base::PlatformFileInfo& file_info, | 507 const base::PlatformFileInfo& file_info, |
| 508 const base::FilePath& platform_path, | 508 const base::FilePath& platform_path, |
| 509 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 509 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
| 510 callback.Run(rv, file_info, platform_path, file_ref); | 510 callback.Run(rv, file_info, platform_path, file_ref); |
| 511 FinishOperation(id); | 511 FinishOperation(id); |
| 512 } | 512 } |
| 513 | 513 |
| 514 FileSystemOperation* | 514 FileSystemOperation* |
| 515 FileSystemOperationRunner::CreateLocalFileSystemOperation( | 515 FileSystemOperationRunner::CreateFileSystemOperationImpl( |
| 516 const FileSystemURL& url, base::PlatformFileError* error) { | 516 const FileSystemURL& url, base::PlatformFileError* error) { |
| 517 FileSystemOperation* operation = | 517 FileSystemOperation* operation = |
| 518 file_system_context_->CreateFileSystemOperation(url, error); | 518 file_system_context_->CreateFileSystemOperation(url, error); |
| 519 if (!operation) | 519 if (!operation) |
| 520 return NULL; | 520 return NULL; |
| 521 if (!operation->AsLocalFileSystemOperation()) { | 521 if (!operation->AsFileSystemOperationImpl()) { |
| 522 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 522 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 523 delete operation; | 523 delete operation; |
| 524 return NULL; | 524 return NULL; |
| 525 } | 525 } |
| 526 return operation; | 526 return operation; |
| 527 } | 527 } |
| 528 | 528 |
| 529 void FileSystemOperationRunner::PrepareForWrite(OperationID id, | 529 void FileSystemOperationRunner::PrepareForWrite(OperationID id, |
| 530 const FileSystemURL& url) { | 530 const FileSystemURL& url) { |
| 531 if (file_system_context_->GetUpdateObservers(url.type())) { | 531 if (file_system_context_->GetUpdateObservers(url.type())) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 554 &FileUpdateObserver::OnEndUpdate, MakeTuple(*iter)); | 554 &FileUpdateObserver::OnEndUpdate, MakeTuple(*iter)); |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 write_target_urls_.erase(found); | 557 write_target_urls_.erase(found); |
| 558 } | 558 } |
| 559 DCHECK(operations_.Lookup(id)); | 559 DCHECK(operations_.Lookup(id)); |
| 560 operations_.Remove(id); | 560 operations_.Remove(id); |
| 561 } | 561 } |
| 562 | 562 |
| 563 } // namespace fileapi | 563 } // namespace fileapi |
| OLD | NEW |