| 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/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "content/browser/streams/stream_handle_impl.h" | 10 #include "content/browser/streams/stream_handle_impl.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 void Stream::RemoveWriteObserver(StreamWriteObserver* observer) { | 65 void Stream::RemoveWriteObserver(StreamWriteObserver* observer) { |
| 66 DCHECK(observer == write_observer_); | 66 DCHECK(observer == write_observer_); |
| 67 write_observer_ = NULL; | 67 write_observer_ = NULL; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void Stream::AddData(scoped_refptr<net::IOBuffer> buffer, size_t size) { | 70 void Stream::AddData(scoped_refptr<net::IOBuffer> buffer, size_t size) { |
| 71 can_add_data_ = writer_->Write(buffer, size); | 71 can_add_data_ = writer_->Write(buffer, size); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void Stream::AddData(const char* data, size_t size) { |
| 75 scoped_refptr<net::IOBuffer> io_buffer(new net::IOBuffer(size)); |
| 76 memcpy(io_buffer->data(), data, size); |
| 77 can_add_data_ = writer_->Write(io_buffer, size); |
| 78 } |
| 79 |
| 74 void Stream::Finalize() { | 80 void Stream::Finalize() { |
| 75 writer_->Close(0); | 81 writer_->Close(0); |
| 76 writer_.reset(NULL); | 82 writer_.reset(NULL); |
| 77 | 83 |
| 78 // Continue asynchronously. | 84 // Continue asynchronously. |
| 79 base::MessageLoopProxy::current()->PostTask( | 85 base::MessageLoopProxy::current()->PostTask( |
| 80 FROM_HERE, | 86 FROM_HERE, |
| 81 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr())); | 87 base::Bind(&Stream::OnDataAvailable, weak_ptr_factory_.GetWeakPtr())); |
| 82 } | 88 } |
| 83 | 89 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 if (write_observer_) | 144 if (write_observer_) |
| 139 write_observer_->OnSpaceAvailable(this); | 145 write_observer_->OnSpaceAvailable(this); |
| 140 } | 146 } |
| 141 | 147 |
| 142 void Stream::OnDataAvailable() { | 148 void Stream::OnDataAvailable() { |
| 143 if (read_observer_) | 149 if (read_observer_) |
| 144 read_observer_->OnDataAvailable(this); | 150 read_observer_->OnDataAvailable(this); |
| 145 } | 151 } |
| 146 | 152 |
| 147 } // namespace content | 153 } // namespace content |
| OLD | NEW |