| 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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 memcpy(io_buffer->data(), data, size); | 111 memcpy(io_buffer->data(), data, size); |
| 112 AddData(io_buffer, size); | 112 AddData(io_buffer, size); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void Stream::Flush() { | 115 void Stream::Flush() { |
| 116 if (!writer_.get()) | 116 if (!writer_.get()) |
| 117 return; | 117 return; |
| 118 writer_->Flush(); | 118 writer_->Flush(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void Stream::Finalize() { | 121 void Stream::Finalize(int status) { |
| 122 if (!writer_.get()) | 122 if (!writer_.get()) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 writer_->Close(0); | 125 writer_->Close(status); |
| 126 writer_.reset(); | 126 writer_.reset(); |
| 127 | 127 |
| 128 // Continue asynchronously. | 128 // Continue asynchronously. |
| 129 base::ThreadTaskRunnerHandle::Get()->PostTask( | 129 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 130 FROM_HERE, | 130 FROM_HERE, |
| 131 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr())); | 131 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr())); |
| 132 } | 132 } |
| 133 | 133 |
| 134 Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf, | 134 Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf, |
| 135 int buf_size, | 135 int buf_size, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // Prevent deletion until this function ends. | 180 // Prevent deletion until this function ends. |
| 181 scoped_refptr<Stream> ref(this); | 181 scoped_refptr<Stream> ref(this); |
| 182 | 182 |
| 183 CHECK(stream_handle_); | 183 CHECK(stream_handle_); |
| 184 stream_handle_ = NULL; | 184 stream_handle_ = NULL; |
| 185 registry_->UnregisterStream(url()); | 185 registry_->UnregisterStream(url()); |
| 186 if (write_observer_) | 186 if (write_observer_) |
| 187 write_observer_->OnClose(this); | 187 write_observer_->OnClose(this); |
| 188 } | 188 } |
| 189 | 189 |
| 190 int Stream::GetStatus() { |
| 191 return reader_->GetStatus(); |
| 192 } |
| 193 |
| 190 void Stream::OnSpaceAvailable() { | 194 void Stream::OnSpaceAvailable() { |
| 191 can_add_data_ = true; | 195 can_add_data_ = true; |
| 192 if (write_observer_) | 196 if (write_observer_) |
| 193 write_observer_->OnSpaceAvailable(this); | 197 write_observer_->OnSpaceAvailable(this); |
| 194 } | 198 } |
| 195 | 199 |
| 196 void Stream::OnDataAvailable() { | 200 void Stream::OnDataAvailable() { |
| 197 if (read_observer_) | 201 if (read_observer_) |
| 198 read_observer_->OnDataAvailable(this); | 202 read_observer_->OnDataAvailable(this); |
| 199 } | 203 } |
| 200 | 204 |
| 201 void Stream::ClearBuffer() { | 205 void Stream::ClearBuffer() { |
| 202 data_ = NULL; | 206 data_ = NULL; |
| 203 data_length_ = 0; | 207 data_length_ = 0; |
| 204 data_bytes_read_ = 0; | 208 data_bytes_read_ = 0; |
| 205 } | 209 } |
| 206 | 210 |
| 207 } // namespace content | 211 } // namespace content |
| OLD | NEW |