Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: content/browser/streams/stream.cc

Issue 2146773002: [Stream] Notify ReadObserver of Stream abortion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/streams/stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | content/browser/streams/stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698