Chromium Code Reviews| 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 // Continue asynchronously. | |
|
kinuko
2016/07/20 06:35:59
nit: A bit more detailed comment might be helpful.
yhirano
2016/07/20 11:30:20
Done.
| |
| 81 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 82 FROM_HERE, | |
| 83 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr())); | |
| 80 } | 84 } |
| 81 | 85 |
| 82 void Stream::AddData(scoped_refptr<net::IOBuffer> buffer, size_t size) { | 86 void Stream::AddData(scoped_refptr<net::IOBuffer> buffer, size_t size) { |
| 83 if (!writer_.get()) | 87 if (!writer_.get()) |
| 84 return; | 88 return; |
| 85 | 89 |
| 86 size_t current_buffered_bytes = writer_->GetTotalBufferedBytes(); | 90 size_t current_buffered_bytes = writer_->GetTotalBufferedBytes(); |
| 87 if (!registry_->UpdateMemoryUsage(url(), current_buffered_bytes, size)) { | 91 if (!registry_->UpdateMemoryUsage(url(), current_buffered_bytes, size)) { |
| 88 Abort(); | 92 Abort(); |
| 89 return; | 93 return; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 read_observer_->OnDataAvailable(this); | 197 read_observer_->OnDataAvailable(this); |
| 194 } | 198 } |
| 195 | 199 |
| 196 void Stream::ClearBuffer() { | 200 void Stream::ClearBuffer() { |
| 197 data_ = NULL; | 201 data_ = NULL; |
| 198 data_length_ = 0; | 202 data_length_ = 0; |
| 199 data_bytes_read_ = 0; | 203 data_bytes_read_ = 0; |
| 200 } | 204 } |
| 201 | 205 |
| 202 } // namespace content | 206 } // namespace content |
| OLD | NEW |