| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/local_file_system_operation.h" | 5 #include "webkit/browser/fileapi/local_file_system_operation.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.h" | 10 #include "base/time.h" |
| 11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request.h" |
| 13 #include "webkit/browser/fileapi/async_file_util.h" | 13 #include "webkit/browser/fileapi/async_file_util.h" |
| 14 #include "webkit/browser/fileapi/copy_or_move_operation_delegate.h" | 14 #include "webkit/browser/fileapi/copy_or_move_operation_delegate.h" |
| 15 #include "webkit/browser/fileapi/file_observers.h" | 15 #include "webkit/browser/fileapi/file_observers.h" |
| 16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "webkit/browser/fileapi/file_system_context.h" |
| 17 #include "webkit/browser/fileapi/file_system_file_util.h" | 17 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 18 #include "webkit/browser/fileapi/file_system_mount_point_provider.h" | 18 #include "webkit/browser/fileapi/file_system_mount_point_provider.h" |
| 19 #include "webkit/browser/fileapi/file_system_operation_context.h" | 19 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/browser/fileapi/file_system_task_runners.h" | 20 #include "webkit/browser/fileapi/file_system_task_runners.h" |
| 21 #include "webkit/browser/fileapi/file_system_url.h" | 21 #include "webkit/browser/fileapi/file_system_url.h" |
| 22 #include "webkit/browser/fileapi/file_writer_delegate.h" | 22 #include "webkit/browser/fileapi/file_writer_delegate.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 file_system_context(), url, | 149 file_system_context(), url, |
| 150 base::Bind(&LocalFileSystemOperation::DidFinishOperation, | 150 base::Bind(&LocalFileSystemOperation::DidFinishOperation, |
| 151 AsWeakPtr(), callback))); | 151 AsWeakPtr(), callback))); |
| 152 if (recursive) | 152 if (recursive) |
| 153 recursive_operation_delegate_->RunRecursively(); | 153 recursive_operation_delegate_->RunRecursively(); |
| 154 else | 154 else |
| 155 recursive_operation_delegate_->Run(); | 155 recursive_operation_delegate_->Run(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void LocalFileSystemOperation::Write( | 158 void LocalFileSystemOperation::Write( |
| 159 const net::URLRequestContext* url_request_context, | |
| 160 const FileSystemURL& url, | 159 const FileSystemURL& url, |
| 161 const GURL& blob_url, | 160 scoped_ptr<FileWriterDelegate> writer_delegate, |
| 162 int64 offset, | 161 scoped_ptr<net::URLRequest> blob_request, |
| 163 const WriteCallback& callback) { | 162 const WriteCallback& callback) { |
| 164 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); | 163 DCHECK(SetPendingOperationType(kOperationWrite)); |
| 164 file_writer_delegate_ = writer_delegate.Pass(); |
| 165 file_writer_delegate_->Start( |
| 166 blob_request.Pass(), |
| 167 base::Bind(&LocalFileSystemOperation::DidWrite, AsWeakPtr(), |
| 168 url, callback)); |
| 165 } | 169 } |
| 166 | 170 |
| 167 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, | 171 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, |
| 168 const StatusCallback& callback) { | 172 const StatusCallback& callback) { |
| 169 DCHECK(SetPendingOperationType(kOperationTruncate)); | 173 DCHECK(SetPendingOperationType(kOperationTruncate)); |
| 170 GetUsageAndQuotaThenRunTask( | 174 GetUsageAndQuotaThenRunTask( |
| 171 url, | 175 url, |
| 172 base::Bind(&LocalFileSystemOperation::DoTruncate, | 176 base::Bind(&LocalFileSystemOperation::DoTruncate, |
| 173 AsWeakPtr(), url, callback, length), | 177 AsWeakPtr(), url, callback, length), |
| 174 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 178 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 if (status != quota::kQuotaStatusOk) { | 348 if (status != quota::kQuotaStatusOk) { |
| 345 LOG(WARNING) << "Got unexpected quota error : " << status; | 349 LOG(WARNING) << "Got unexpected quota error : " << status; |
| 346 error_callback.Run(); | 350 error_callback.Run(); |
| 347 return; | 351 return; |
| 348 } | 352 } |
| 349 | 353 |
| 350 operation_context_->set_allowed_bytes_growth(quota - usage); | 354 operation_context_->set_allowed_bytes_growth(quota - usage); |
| 351 task.Run(); | 355 task.Run(); |
| 352 } | 356 } |
| 353 | 357 |
| 354 base::Closure LocalFileSystemOperation::GetWriteClosure( | |
| 355 const net::URLRequestContext* url_request_context, | |
| 356 const FileSystemURL& url, | |
| 357 const GURL& blob_url, | |
| 358 int64 offset, | |
| 359 const WriteCallback& callback) { | |
| 360 DCHECK(SetPendingOperationType(kOperationWrite)); | |
| 361 scoped_ptr<FileStreamWriter> writer( | |
| 362 file_system_context()->CreateFileStreamWriter(url, offset)); | |
| 363 | |
| 364 if (!writer) { | |
| 365 // Write is not supported. | |
| 366 return base::Bind(&LocalFileSystemOperation::DidFailWrite, | |
| 367 AsWeakPtr(), callback, | |
| 368 base::PLATFORM_FILE_ERROR_SECURITY); | |
| 369 } | |
| 370 | |
| 371 DCHECK(blob_url.is_valid()); | |
| 372 file_writer_delegate_.reset(new FileWriterDelegate( | |
| 373 base::Bind(&LocalFileSystemOperation::DidWrite, AsWeakPtr(), | |
| 374 url, callback), | |
| 375 writer.Pass())); | |
| 376 | |
| 377 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest( | |
| 378 blob_url, file_writer_delegate_.get())); | |
| 379 | |
| 380 return base::Bind(&FileWriterDelegate::Start, | |
| 381 base::Unretained(file_writer_delegate_.get()), | |
| 382 base::Passed(&blob_request)); | |
| 383 } | |
| 384 | |
| 385 void LocalFileSystemOperation::DidFailWrite( | |
| 386 const WriteCallback& callback, | |
| 387 base::PlatformFileError result) { | |
| 388 callback.Run(result, 0, false); | |
| 389 } | |
| 390 | |
| 391 void LocalFileSystemOperation::DoCreateFile( | 358 void LocalFileSystemOperation::DoCreateFile( |
| 392 const FileSystemURL& url, | 359 const FileSystemURL& url, |
| 393 const StatusCallback& callback, | 360 const StatusCallback& callback, |
| 394 bool exclusive) { | 361 bool exclusive) { |
| 395 async_file_util_->EnsureFileExists( | 362 async_file_util_->EnsureFileExists( |
| 396 operation_context_.Pass(), url, | 363 operation_context_.Pass(), url, |
| 397 base::Bind( | 364 base::Bind( |
| 398 exclusive ? | 365 exclusive ? |
| 399 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : | 366 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : |
| 400 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, | 367 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 511 } |
| 545 | 512 |
| 546 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 513 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
| 547 if (pending_operation_ != kOperationNone) | 514 if (pending_operation_ != kOperationNone) |
| 548 return false; | 515 return false; |
| 549 pending_operation_ = type; | 516 pending_operation_ = type; |
| 550 return true; | 517 return true; |
| 551 } | 518 } |
| 552 | 519 |
| 553 } // namespace fileapi | 520 } // namespace fileapi |
| OLD | NEW |