| 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/media_galleries/fileapi/readahead_file_stream_reader.h" | 5 #include "chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 void ReadaheadFileStreamReader::ReadFromSourceIfNeeded() { | 98 void ReadaheadFileStreamReader::ReadFromSourceIfNeeded() { |
| 99 if (!source_.get() || source_has_pending_read_ || | 99 if (!source_.get() || source_has_pending_read_ || |
| 100 buffers_.size() >= kDesiredNumberOfBuffers) { | 100 buffers_.size() >= kDesiredNumberOfBuffers) { |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 | 103 |
| 104 source_has_pending_read_ = true; | 104 source_has_pending_read_ = true; |
| 105 | 105 |
| 106 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kBufferSize)); | 106 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kBufferSize)); |
| 107 int result = source_->Read( | 107 int result = source_->Read( |
| 108 buf.get(), | 108 buf.get(), kBufferSize, |
| 109 kBufferSize, | |
| 110 base::Bind(&ReadaheadFileStreamReader::OnFinishReadFromSource, | 109 base::Bind(&ReadaheadFileStreamReader::OnFinishReadFromSource, |
| 111 weak_factory_.GetWeakPtr(), | 110 weak_factory_.GetWeakPtr(), base::RetainedRef(buf))); |
| 112 buf)); | |
| 113 | 111 |
| 114 if (result != net::ERR_IO_PENDING) | 112 if (result != net::ERR_IO_PENDING) |
| 115 OnFinishReadFromSource(buf.get(), result); | 113 OnFinishReadFromSource(buf.get(), result); |
| 116 } | 114 } |
| 117 | 115 |
| 118 void ReadaheadFileStreamReader::OnFinishReadFromSource(net::IOBuffer* buf, | 116 void ReadaheadFileStreamReader::OnFinishReadFromSource(net::IOBuffer* buf, |
| 119 int result) { | 117 int result) { |
| 120 DCHECK(result != net::ERR_IO_PENDING); | 118 DCHECK(result != net::ERR_IO_PENDING); |
| 121 DCHECK(source_has_pending_read_); | 119 DCHECK(source_has_pending_read_); |
| 122 source_has_pending_read_ = false; | 120 source_has_pending_read_ = false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 140 // Free the pending callback before running it, as the callback often | 138 // Free the pending callback before running it, as the callback often |
| 141 // dispatches another read. | 139 // dispatches another read. |
| 142 scoped_refptr<net::DrainableIOBuffer> sink = pending_sink_buffer_; | 140 scoped_refptr<net::DrainableIOBuffer> sink = pending_sink_buffer_; |
| 143 pending_sink_buffer_ = NULL; | 141 pending_sink_buffer_ = NULL; |
| 144 net::CompletionCallback completion_callback = pending_read_callback_; | 142 net::CompletionCallback completion_callback = pending_read_callback_; |
| 145 pending_read_callback_.Reset(); | 143 pending_read_callback_.Reset(); |
| 146 | 144 |
| 147 completion_callback.Run(FinishReadFromCacheOrStoredError(sink.get())); | 145 completion_callback.Run(FinishReadFromCacheOrStoredError(sink.get())); |
| 148 } | 146 } |
| 149 } | 147 } |
| OLD | NEW |