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> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 | 10 |
9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
10 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
11 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
13 | 15 |
14 using storage::FileStreamReader; | 16 using storage::FileStreamReader; |
15 | 17 |
16 namespace { | 18 namespace { |
(...skipping 27 matching lines...) Expand all Loading... |
44 if (result == net::ERR_IO_PENDING) { | 46 if (result == net::ERR_IO_PENDING) { |
45 DCHECK(!pending_sink_buffer_.get()); | 47 DCHECK(!pending_sink_buffer_.get()); |
46 DCHECK(pending_read_callback_.is_null()); | 48 DCHECK(pending_read_callback_.is_null()); |
47 pending_sink_buffer_ = sink; | 49 pending_sink_buffer_ = sink; |
48 pending_read_callback_ = callback; | 50 pending_read_callback_ = callback; |
49 } | 51 } |
50 | 52 |
51 return result; | 53 return result; |
52 } | 54 } |
53 | 55 |
54 int64 ReadaheadFileStreamReader::GetLength( | 56 int64_t ReadaheadFileStreamReader::GetLength( |
55 const net::Int64CompletionCallback& callback) { | 57 const net::Int64CompletionCallback& callback) { |
56 return source_->GetLength(callback); | 58 return source_->GetLength(callback); |
57 } | 59 } |
58 | 60 |
59 int ReadaheadFileStreamReader::FinishReadFromCacheOrStoredError( | 61 int ReadaheadFileStreamReader::FinishReadFromCacheOrStoredError( |
60 net::DrainableIOBuffer* sink) { | 62 net::DrainableIOBuffer* sink) { |
61 // If we don't have any ready cache, return the pending read code, or | 63 // If we don't have any ready cache, return the pending read code, or |
62 // the stored error code. | 64 // the stored error code. |
63 if (buffers_.empty()) { | 65 if (buffers_.empty()) { |
64 if (source_.get()) { | 66 if (source_.get()) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Free the pending callback before running it, as the callback often | 140 // Free the pending callback before running it, as the callback often |
139 // dispatches another read. | 141 // dispatches another read. |
140 scoped_refptr<net::DrainableIOBuffer> sink = pending_sink_buffer_; | 142 scoped_refptr<net::DrainableIOBuffer> sink = pending_sink_buffer_; |
141 pending_sink_buffer_ = NULL; | 143 pending_sink_buffer_ = NULL; |
142 net::CompletionCallback completion_callback = pending_read_callback_; | 144 net::CompletionCallback completion_callback = pending_read_callback_; |
143 pending_read_callback_.Reset(); | 145 pending_read_callback_.Reset(); |
144 | 146 |
145 completion_callback.Run(FinishReadFromCacheOrStoredError(sink.get())); | 147 completion_callback.Run(FinishReadFromCacheOrStoredError(sink.get())); |
146 } | 148 } |
147 } | 149 } |
OLD | NEW |