| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 void Stream::Abort() { | 72 void Stream::Abort() { |
| 73 // Clear all buffer. It's safe to clear reader_ here since the same thread | 73 // Clear all buffer. It's safe to clear reader_ here since the same thread |
| 74 // is used for both input and output operation. | 74 // is used for both input and output operation. |
| 75 writer_.reset(); | 75 writer_.reset(); |
| 76 reader_.reset(); | 76 reader_.reset(); |
| 77 ClearBuffer(); | 77 ClearBuffer(); |
| 78 can_add_data_ = false; | 78 can_add_data_ = false; |
| 79 registry_->UnregisterStream(url()); | 79 registry_->UnregisterStream(url()); |
| 80 // Notify the observer that something happens. Read will return |
| 81 // STREAM_ABORTED. |
| 82 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 83 FROM_HERE, |
| 84 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr())); |
| 80 } | 85 } |
| 81 | 86 |
| 82 void Stream::AddData(scoped_refptr<net::IOBuffer> buffer, size_t size) { | 87 void Stream::AddData(scoped_refptr<net::IOBuffer> buffer, size_t size) { |
| 83 if (!writer_.get()) | 88 if (!writer_.get()) |
| 84 return; | 89 return; |
| 85 | 90 |
| 86 size_t current_buffered_bytes = writer_->GetTotalBufferedBytes(); | 91 size_t current_buffered_bytes = writer_->GetTotalBufferedBytes(); |
| 87 if (!registry_->UpdateMemoryUsage(url(), current_buffered_bytes, size)) { | 92 if (!registry_->UpdateMemoryUsage(url(), current_buffered_bytes, size)) { |
| 88 Abort(); | 93 Abort(); |
| 89 return; | 94 return; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 read_observer_->OnDataAvailable(this); | 198 read_observer_->OnDataAvailable(this); |
| 194 } | 199 } |
| 195 | 200 |
| 196 void Stream::ClearBuffer() { | 201 void Stream::ClearBuffer() { |
| 197 data_ = NULL; | 202 data_ = NULL; |
| 198 data_length_ = 0; | 203 data_length_ = 0; |
| 199 data_bytes_read_ = 0; | 204 data_bytes_read_ = 0; |
| 200 } | 205 } |
| 201 | 206 |
| 202 } // namespace content | 207 } // namespace content |
| OLD | NEW |