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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 int LocalReaderProxy::Read(net::IOBuffer* buffer, int buffer_length, | 112 int LocalReaderProxy::Read(net::IOBuffer* buffer, int buffer_length, |
113 const net::CompletionCallback& callback) { | 113 const net::CompletionCallback& callback) { |
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
115 DCHECK(file_reader_); | 115 DCHECK(file_reader_); |
116 | 116 |
117 if (buffer_length > remaining_length_) { | 117 if (buffer_length > remaining_length_) { |
118 // Here, narrowing is safe. | 118 // Here, narrowing is safe. |
119 buffer_length = static_cast<int>(remaining_length_); | 119 buffer_length = static_cast<int>(remaining_length_); |
120 } | 120 } |
121 | 121 |
| 122 if (!buffer_length) |
| 123 return 0; |
| 124 |
122 file_reader_->Read(buffer, buffer_length, | 125 file_reader_->Read(buffer, buffer_length, |
123 base::Bind(&LocalReaderProxy::OnReadCompleted, | 126 base::Bind(&LocalReaderProxy::OnReadCompleted, |
124 weak_ptr_factory_.GetWeakPtr(), callback)); | 127 weak_ptr_factory_.GetWeakPtr(), callback)); |
125 return net::ERR_IO_PENDING; | 128 return net::ERR_IO_PENDING; |
126 } | 129 } |
127 | 130 |
128 void LocalReaderProxy::OnGetContent(scoped_ptr<std::string> data) { | 131 void LocalReaderProxy::OnGetContent(scoped_ptr<std::string> data) { |
129 // This method should never be called, because no data should be received | 132 // This method should never be called, because no data should be received |
130 // from the network during the reading of local-cache file. | 133 // from the network during the reading of local-cache file. |
131 NOTREACHED(); | 134 NOTREACHED(); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // Note: due to the same reason, LocalReaderProxy::OnCompleted may | 466 // Note: due to the same reason, LocalReaderProxy::OnCompleted may |
464 // or may not be called. This is timing issue, and it is difficult to avoid | 467 // or may not be called. This is timing issue, and it is difficult to avoid |
465 // unfortunately. | 468 // unfortunately. |
466 if (error != FILE_ERROR_OK) { | 469 if (error != FILE_ERROR_OK) { |
467 callback.Run(FileErrorToNetError(error), scoped_ptr<ResourceEntry>()); | 470 callback.Run(FileErrorToNetError(error), scoped_ptr<ResourceEntry>()); |
468 } | 471 } |
469 } | 472 } |
470 } | 473 } |
471 | 474 |
472 } // namespace drive | 475 } // namespace drive |
OLD | NEW |