| 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/file_stream_reade
r.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_reade
r.h" |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/abort_callback.h" | 12 #include "chrome/browser/chromeos/file_system_provider/abort_callback.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" | 13 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 14 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 15 #include "chrome/browser/chromeos/file_system_provider/scoped_file_opener.h" | 16 #include "chrome/browser/chromeos/file_system_provider/scoped_file_opener.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Requests metadata of a file. In case of either succes or a failure, | 95 // Requests metadata of a file. In case of either succes or a failure, |
| 95 // |callback| is executed. Must be called on UI thread. | 96 // |callback| is executed. Must be called on UI thread. |
| 96 void GetMetadataOnUIThread( | 97 void GetMetadataOnUIThread( |
| 97 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { | 98 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 99 DCHECK(abort_callback_.is_null()); | 100 DCHECK(abort_callback_.is_null()); |
| 100 | 101 |
| 101 // If the file system got unmounted, then abort the get length operation. | 102 // If the file system got unmounted, then abort the get length operation. |
| 102 if (!file_system_.get()) { | 103 if (!file_system_.get()) { |
| 103 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 104 BrowserThread::IO, | 105 BrowserThread::IO, FROM_HERE, |
| 105 FROM_HERE, | |
| 106 base::Bind(callback, | 106 base::Bind(callback, |
| 107 base::Passed(make_scoped_ptr<EntryMetadata>(NULL)), | 107 base::Passed(base::WrapUnique<EntryMetadata>(NULL)), |
| 108 base::File::FILE_ERROR_ABORT)); | 108 base::File::FILE_ERROR_ABORT)); |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 | 111 |
| 112 abort_callback_ = file_system_->GetMetadata( | 112 abort_callback_ = file_system_->GetMetadata( |
| 113 file_path_, | 113 file_path_, |
| 114 ProvidedFileSystemInterface::METADATA_FIELD_SIZE | | 114 ProvidedFileSystemInterface::METADATA_FIELD_SIZE | |
| 115 ProvidedFileSystemInterface::METADATA_FIELD_MODIFICATION_TIME, | 115 ProvidedFileSystemInterface::METADATA_FIELD_MODIFICATION_TIME, |
| 116 base::Bind(&OperationRunner::OnGetMetadataCompletedOnUIThread, this, | 116 base::Bind(&OperationRunner::OnGetMetadataCompletedOnUIThread, this, |
| 117 callback)); | 117 callback)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (result == base::File::FILE_OK) | 151 if (result == base::File::FILE_OK) |
| 152 file_handle_ = file_handle; | 152 file_handle_ = file_handle; |
| 153 | 153 |
| 154 BrowserThread::PostTask( | 154 BrowserThread::PostTask( |
| 155 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 155 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Forwards a metadata to the IO thread. | 158 // Forwards a metadata to the IO thread. |
| 159 void OnGetMetadataCompletedOnUIThread( | 159 void OnGetMetadataCompletedOnUIThread( |
| 160 const ProvidedFileSystemInterface::GetMetadataCallback& callback, | 160 const ProvidedFileSystemInterface::GetMetadataCallback& callback, |
| 161 scoped_ptr<EntryMetadata> metadata, | 161 std::unique_ptr<EntryMetadata> metadata, |
| 162 base::File::Error result) { | 162 base::File::Error result) { |
| 163 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 163 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 164 abort_callback_ = AbortCallback(); | 164 abort_callback_ = AbortCallback(); |
| 165 | 165 |
| 166 BrowserThread::PostTask( | 166 BrowserThread::PostTask( |
| 167 BrowserThread::IO, | 167 BrowserThread::IO, |
| 168 FROM_HERE, | 168 FROM_HERE, |
| 169 base::Bind(callback, base::Passed(&metadata), result)); | 169 base::Bind(callback, base::Passed(&metadata), result)); |
| 170 } | 170 } |
| 171 | 171 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 182 | 182 |
| 183 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
| 184 BrowserThread::IO, | 184 BrowserThread::IO, |
| 185 FROM_HERE, | 185 FROM_HERE, |
| 186 base::Bind(chunk_received_callback, chunk_length, has_more, result)); | 186 base::Bind(chunk_received_callback, chunk_length, has_more, result)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 AbortCallback abort_callback_; | 189 AbortCallback abort_callback_; |
| 190 base::WeakPtr<ProvidedFileSystemInterface> file_system_; | 190 base::WeakPtr<ProvidedFileSystemInterface> file_system_; |
| 191 base::FilePath file_path_; | 191 base::FilePath file_path_; |
| 192 scoped_ptr<ScopedFileOpener> file_opener_; | 192 std::unique_ptr<ScopedFileOpener> file_opener_; |
| 193 int file_handle_; | 193 int file_handle_; |
| 194 | 194 |
| 195 DISALLOW_COPY_AND_ASSIGN(OperationRunner); | 195 DISALLOW_COPY_AND_ASSIGN(OperationRunner); |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 FileStreamReader::FileStreamReader(storage::FileSystemContext* context, | 198 FileStreamReader::FileStreamReader(storage::FileSystemContext* context, |
| 199 const storage::FileSystemURL& url, | 199 const storage::FileSystemURL& url, |
| 200 int64_t initial_offset, | 200 int64_t initial_offset, |
| 201 const base::Time& expected_modification_time) | 201 const base::Time& expected_modification_time) |
| 202 : url_(url), | 202 : url_(url), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 runner_, | 263 runner_, |
| 264 base::Bind(&FileStreamReader::OnInitializeCompleted, | 264 base::Bind(&FileStreamReader::OnInitializeCompleted, |
| 265 weak_ptr_factory_.GetWeakPtr(), | 265 weak_ptr_factory_.GetWeakPtr(), |
| 266 pending_closure, | 266 pending_closure, |
| 267 error_callback))); | 267 error_callback))); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void FileStreamReader::OnInitializeCompleted( | 270 void FileStreamReader::OnInitializeCompleted( |
| 271 const base::Closure& pending_closure, | 271 const base::Closure& pending_closure, |
| 272 const net::Int64CompletionCallback& error_callback, | 272 const net::Int64CompletionCallback& error_callback, |
| 273 scoped_ptr<EntryMetadata> metadata, | 273 std::unique_ptr<EntryMetadata> metadata, |
| 274 base::File::Error result) { | 274 base::File::Error result) { |
| 275 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 275 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 276 DCHECK_EQ(INITIALIZING, state_); | 276 DCHECK_EQ(INITIALIZING, state_); |
| 277 | 277 |
| 278 // In case of an error, abort. | 278 // In case of an error, abort. |
| 279 if (result != base::File::FILE_OK) { | 279 if (result != base::File::FILE_OK) { |
| 280 state_ = FAILED; | 280 state_ = FAILED; |
| 281 error_callback.Run(net::FileErrorToNetError(result)); | 281 error_callback.Run(net::FileErrorToNetError(result)); |
| 282 return; | 282 return; |
| 283 } | 283 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 callback.Run(net::FileErrorToNetError(result)); | 443 callback.Run(net::FileErrorToNetError(result)); |
| 444 return; | 444 return; |
| 445 } | 445 } |
| 446 | 446 |
| 447 // More data is about to come, so do not call the callback yet. | 447 // More data is about to come, so do not call the callback yet. |
| 448 DCHECK(has_more); | 448 DCHECK(has_more); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void FileStreamReader::OnGetMetadataForGetLengthReceived( | 451 void FileStreamReader::OnGetMetadataForGetLengthReceived( |
| 452 const net::Int64CompletionCallback& callback, | 452 const net::Int64CompletionCallback& callback, |
| 453 scoped_ptr<EntryMetadata> metadata, | 453 std::unique_ptr<EntryMetadata> metadata, |
| 454 base::File::Error result) { | 454 base::File::Error result) { |
| 455 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 455 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 456 DCHECK_EQ(INITIALIZED, state_); | 456 DCHECK_EQ(INITIALIZED, state_); |
| 457 | 457 |
| 458 // In case of an error, abort. | 458 // In case of an error, abort. |
| 459 if (result != base::File::FILE_OK) { | 459 if (result != base::File::FILE_OK) { |
| 460 state_ = FAILED; | 460 state_ = FAILED; |
| 461 callback.Run(net::FileErrorToNetError(result)); | 461 callback.Run(net::FileErrorToNetError(result)); |
| 462 return; | 462 return; |
| 463 } | 463 } |
| 464 | 464 |
| 465 // If the file modification time has changed, then abort. Note, that the file | 465 // If the file modification time has changed, then abort. Note, that the file |
| 466 // may be changed without affecting the modification time. | 466 // may be changed without affecting the modification time. |
| 467 DCHECK(metadata.get()); | 467 DCHECK(metadata.get()); |
| 468 if (!expected_modification_time_.is_null() && | 468 if (!expected_modification_time_.is_null() && |
| 469 *metadata->modification_time != expected_modification_time_) { | 469 *metadata->modification_time != expected_modification_time_) { |
| 470 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); | 470 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); |
| 471 return; | 471 return; |
| 472 } | 472 } |
| 473 | 473 |
| 474 DCHECK_EQ(base::File::FILE_OK, result); | 474 DCHECK_EQ(base::File::FILE_OK, result); |
| 475 callback.Run(*metadata->size); | 475 callback.Run(*metadata->size); |
| 476 } | 476 } |
| 477 | 477 |
| 478 } // namespace file_system_provider | 478 } // namespace file_system_provider |
| 479 } // namespace chromeos | 479 } // namespace chromeos |
| OLD | NEW |