| 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 "chrome/browser/chromeos/drive/drive_file_stream_reader.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_stream_reader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 NetworkReaderProxy::~NetworkReaderProxy() { | 136 NetworkReaderProxy::~NetworkReaderProxy() { |
| 137 if (!job_canceller_.is_null()) { | 137 if (!job_canceller_.is_null()) { |
| 138 job_canceller_.Run(); | 138 job_canceller_.Run(); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 int NetworkReaderProxy::Read(net::IOBuffer* buffer, int buffer_length, | 142 int NetworkReaderProxy::Read(net::IOBuffer* buffer, int buffer_length, |
| 143 const net::CompletionCallback& callback) { | 143 const net::CompletionCallback& callback) { |
| 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 145 // Check if there is no pending Read operation. | 145 // Check if there is no pending Read operation. |
| 146 DCHECK(!buffer_); | 146 DCHECK(!buffer_.get()); |
| 147 DCHECK_EQ(buffer_length_, 0); | 147 DCHECK_EQ(buffer_length_, 0); |
| 148 DCHECK(callback_.is_null()); | 148 DCHECK(callback_.is_null()); |
| 149 // Validate the arguments. | 149 // Validate the arguments. |
| 150 DCHECK(buffer); | 150 DCHECK(buffer); |
| 151 DCHECK_GT(buffer_length, 0); | 151 DCHECK_GT(buffer_length, 0); |
| 152 DCHECK(!callback.is_null()); | 152 DCHECK(!callback.is_null()); |
| 153 | 153 |
| 154 if (error_code_ != net::OK) { | 154 if (error_code_ != net::OK) { |
| 155 // An error is already found. Return it immediately. | 155 // An error is already found. Return it immediately. |
| 156 return error_code_; | 156 return error_code_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 return; | 190 return; |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (remaining_offset_ > 0) { | 193 if (remaining_offset_ > 0) { |
| 194 // Erase unnecessary leading bytes. | 194 // Erase unnecessary leading bytes. |
| 195 data->erase(0, static_cast<size_t>(remaining_offset_)); | 195 data->erase(0, static_cast<size_t>(remaining_offset_)); |
| 196 remaining_offset_ = 0; | 196 remaining_offset_ = 0; |
| 197 } | 197 } |
| 198 | 198 |
| 199 pending_data_.push_back(data.release()); | 199 pending_data_.push_back(data.release()); |
| 200 if (!buffer_) { | 200 if (!buffer_.get()) { |
| 201 // No pending Read operation. | 201 // No pending Read operation. |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 | 204 |
| 205 int result = ReadInternal(&pending_data_, buffer_.get(), buffer_length_); | 205 int result = ReadInternal(&pending_data_, buffer_.get(), buffer_length_); |
| 206 remaining_content_length_ -= result; | 206 remaining_content_length_ -= result; |
| 207 DCHECK_GE(remaining_content_length_, 0); | 207 DCHECK_GE(remaining_content_length_, 0); |
| 208 | 208 |
| 209 buffer_ = NULL; | 209 buffer_ = NULL; |
| 210 buffer_length_ = 0; | 210 buffer_length_ = 0; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 new internal::NetworkReaderProxy( | 373 new internal::NetworkReaderProxy( |
| 374 byte_range.first_byte_position(), range_length, | 374 byte_range.first_byte_position(), range_length, |
| 375 base::Bind(&google_apis::RunTaskOnUIThread, | 375 base::Bind(&google_apis::RunTaskOnUIThread, |
| 376 ui_cancel_download_closure))); | 376 ui_cancel_download_closure))); |
| 377 callback.Run(net::OK, entry.Pass()); | 377 callback.Run(net::OK, entry.Pass()); |
| 378 return; | 378 return; |
| 379 } | 379 } |
| 380 | 380 |
| 381 // Otherwise, open the stream for file. | 381 // Otherwise, open the stream for file. |
| 382 scoped_ptr<util::LocalFileReader> file_reader( | 382 scoped_ptr<util::LocalFileReader> file_reader( |
| 383 new util::LocalFileReader(file_task_runner_)); | 383 new util::LocalFileReader(file_task_runner_.get())); |
| 384 util::LocalFileReader* file_reader_ptr = file_reader.get(); | 384 util::LocalFileReader* file_reader_ptr = file_reader.get(); |
| 385 file_reader_ptr->Open( | 385 file_reader_ptr->Open( |
| 386 local_cache_file_path, | 386 local_cache_file_path, |
| 387 byte_range.first_byte_position(), | 387 byte_range.first_byte_position(), |
| 388 base::Bind( | 388 base::Bind( |
| 389 &DriveFileStreamReader::InitializeAfterLocalFileOpen, | 389 &DriveFileStreamReader::InitializeAfterLocalFileOpen, |
| 390 weak_ptr_factory_.GetWeakPtr(), | 390 weak_ptr_factory_.GetWeakPtr(), |
| 391 range_length, | 391 range_length, |
| 392 callback, | 392 callback, |
| 393 base::Passed(&entry), | 393 base::Passed(&entry), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // Note: due to the same reason, LocalReaderProxy::OnCompleted may | 437 // Note: due to the same reason, LocalReaderProxy::OnCompleted may |
| 438 // or may not be called. This is timing issue, and it is difficult to avoid | 438 // or may not be called. This is timing issue, and it is difficult to avoid |
| 439 // unfortunately. | 439 // unfortunately. |
| 440 if (error != FILE_ERROR_OK) { | 440 if (error != FILE_ERROR_OK) { |
| 441 callback.Run(FileErrorToNetError(error), scoped_ptr<ResourceEntry>()); | 441 callback.Run(FileErrorToNetError(error), scoped_ptr<ResourceEntry>()); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 } // namespace drive | 446 } // namespace drive |
| OLD | NEW |