OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/streams/stream.h" | 5 #include "content/browser/streams/stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 buf_size : remaining_bytes; | 158 buf_size : remaining_bytes; |
159 memcpy(buf->data(), data_->data() + data_bytes_read_, to_read); | 159 memcpy(buf->data(), data_->data() + data_bytes_read_, to_read); |
160 data_bytes_read_ += to_read; | 160 data_bytes_read_ += to_read; |
161 if (data_bytes_read_ >= data_length_) | 161 if (data_bytes_read_ >= data_length_) |
162 ClearBuffer(); | 162 ClearBuffer(); |
163 | 163 |
164 *bytes_read = to_read; | 164 *bytes_read = to_read; |
165 return STREAM_HAS_DATA; | 165 return STREAM_HAS_DATA; |
166 } | 166 } |
167 | 167 |
168 scoped_ptr<StreamHandle> Stream::CreateHandle() { | 168 std::unique_ptr<StreamHandle> Stream::CreateHandle() { |
169 CHECK(!stream_handle_); | 169 CHECK(!stream_handle_); |
170 stream_handle_ = new StreamHandleImpl(weak_ptr_factory_.GetWeakPtr()); | 170 stream_handle_ = new StreamHandleImpl(weak_ptr_factory_.GetWeakPtr()); |
171 return scoped_ptr<StreamHandle>(stream_handle_); | 171 return std::unique_ptr<StreamHandle>(stream_handle_); |
172 } | 172 } |
173 | 173 |
174 void Stream::CloseHandle() { | 174 void Stream::CloseHandle() { |
175 // Prevent deletion until this function ends. | 175 // Prevent deletion until this function ends. |
176 scoped_refptr<Stream> ref(this); | 176 scoped_refptr<Stream> ref(this); |
177 | 177 |
178 CHECK(stream_handle_); | 178 CHECK(stream_handle_); |
179 stream_handle_ = NULL; | 179 stream_handle_ = NULL; |
180 registry_->UnregisterStream(url()); | 180 registry_->UnregisterStream(url()); |
181 if (write_observer_) | 181 if (write_observer_) |
(...skipping 11 matching lines...) Expand all Loading... |
193 read_observer_->OnDataAvailable(this); | 193 read_observer_->OnDataAvailable(this); |
194 } | 194 } |
195 | 195 |
196 void Stream::ClearBuffer() { | 196 void Stream::ClearBuffer() { |
197 data_ = NULL; | 197 data_ = NULL; |
198 data_length_ = 0; | 198 data_length_ = 0; |
199 data_bytes_read_ = 0; | 199 data_bytes_read_ = 0; |
200 } | 200 } |
201 | 201 |
202 } // namespace content | 202 } // namespace content |
OLD | NEW |