Chromium Code Reviews| Index: content/browser/streams/stream_handle_impl.cc |
| diff --git a/content/browser/streams/stream_handle_impl.cc b/content/browser/streams/stream_handle_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6319b3a8af872ee56906a40b2f2dc8f320cac825 |
| --- /dev/null |
| +++ b/content/browser/streams/stream_handle_impl.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/streams/stream_handle_impl.h" |
| + |
| +#include "content/browser/streams/stream.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace content { |
| + |
| +StreamHandleImpl::StreamHandleImpl(base::WeakPtr<Stream> stream) |
|
darin (slow to review)
2013/03/19 06:12:51
nit: we normally pass WeakPtr using |const WeakPtr
Zachary Kuznia
2013/03/19 06:59:35
Done.
|
| + : stream_(stream), |
| + url_(stream->url()), |
| + stream_message_loop_(base::MessageLoopProxy::current()), |
| + callback_message_loop_(NULL) { |
| +} |
| + |
| +StreamHandleImpl::~StreamHandleImpl() { |
| + stream_message_loop_->PostTask(FROM_HERE, |
| + base::Bind(&Stream::CloseHandle, stream_)); |
| +} |
| + |
| +void StreamHandleImpl::SendCloseEvent() { |
|
darin (slow to review)
2013/03/19 06:12:51
nit: Stream::CloseHandle and StreamHandle::SendClo
Zachary Kuznia
2013/03/19 06:59:35
Done.
|
| + base::AutoLock lock(callback_lock_); |
| + stream_.reset(); |
| + if (!callback_.is_null()) { |
| + CHECK(callback_message_loop_); |
| + callback_message_loop_->PostTask(FROM_HERE, callback_); |
| + } |
| +} |
| + |
| +const GURL& StreamHandleImpl::GetUrl() { |
| + return url_; |
| +} |
| + |
| +void StreamHandleImpl::RegisterCloseCallback(const base::Closure& callback) { |
| + base::AutoLock lock(callback_lock_); |
| + if (stream_) { |
| + callback_ = callback; |
| + callback_message_loop_ = base::MessageLoopProxy::current(); |
| + } else { |
| + // If the stream is NULL, the close event has already been sent. |
| + base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback); |
| + } |
| +} |
| + |
| +} // namespace content |