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/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "content/browser/streams/stream_read_observer.h" | 9 #include "content/browser/streams/stream_read_observer.h" |
10 #include "content/browser/streams/stream_registry.h" | 10 #include "content/browser/streams/stream_registry.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 StreamWriteObserver* write_observer, | 22 StreamWriteObserver* write_observer, |
23 const GURL& security_origin, | 23 const GURL& security_origin, |
24 const GURL& url) | 24 const GURL& url) |
25 : bytes_read_(0), | 25 : bytes_read_(0), |
26 can_add_data_(true), | 26 can_add_data_(true), |
27 security_origin_(security_origin), | 27 security_origin_(security_origin), |
28 url_(url), | 28 url_(url), |
29 data_length_(0), | 29 data_length_(0), |
30 registry_(registry), | 30 registry_(registry), |
31 read_observer_(NULL), | 31 read_observer_(NULL), |
32 write_observer_(write_observer) { | 32 write_observer_(write_observer), |
| 33 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
33 CreateByteStream(base::MessageLoopProxy::current(), | 34 CreateByteStream(base::MessageLoopProxy::current(), |
34 base::MessageLoopProxy::current(), | 35 base::MessageLoopProxy::current(), |
35 kDeferSizeThreshold, | 36 kDeferSizeThreshold, |
36 &writer_, | 37 &writer_, |
37 &reader_); | 38 &reader_); |
38 | 39 |
39 // Setup callback for writing. | 40 // Setup callback for writing. |
40 writer_->RegisterCallback(base::Bind(&Stream::OnSpaceAvailable, this)); | 41 writer_->RegisterCallback(base::Bind(&Stream::OnSpaceAvailable, |
41 reader_->RegisterCallback(base::Bind(&Stream::OnDataAvailable, this)); | 42 weak_ptr_factory_.GetWeakPtr())); |
| 43 reader_->RegisterCallback(base::Bind(&Stream::OnDataAvailable, |
| 44 weak_ptr_factory_.GetWeakPtr())); |
42 | 45 |
43 registry_->RegisterStream(this); | 46 registry_->RegisterStream(this); |
44 } | 47 } |
45 | 48 |
46 Stream::~Stream() { | 49 Stream::~Stream() { |
47 } | 50 } |
48 | 51 |
49 bool Stream::SetReadObserver(StreamReadObserver* observer) { | 52 bool Stream::SetReadObserver(StreamReadObserver* observer) { |
50 if (read_observer_) | 53 if (read_observer_) |
51 return false; | 54 return false; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 can_add_data_ = true; | 107 can_add_data_ = true; |
105 write_observer_->OnSpaceAvailable(this); | 108 write_observer_->OnSpaceAvailable(this); |
106 } | 109 } |
107 | 110 |
108 void Stream::OnDataAvailable() { | 111 void Stream::OnDataAvailable() { |
109 read_observer_->OnDataAvailable(this); | 112 read_observer_->OnDataAvailable(this); |
110 } | 113 } |
111 | 114 |
112 } // namespace content | 115 } // namespace content |
113 | 116 |
OLD | NEW |