OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/streams/stream_handle_impl.h" |
| 6 |
| 7 #include "content/browser/streams/stream.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 StreamHandleImpl::StreamHandleImpl(const base::WeakPtr<Stream>& stream, |
| 13 const GURL& original_url, |
| 14 const std::string& mime_type) |
| 15 : stream_(stream), |
| 16 url_(stream->url()), |
| 17 original_url_(original_url), |
| 18 mime_type_(mime_type), |
| 19 stream_message_loop_(base::MessageLoopProxy::current()), |
| 20 callback_message_loop_(NULL) { |
| 21 } |
| 22 |
| 23 StreamHandleImpl::~StreamHandleImpl() { |
| 24 stream_message_loop_->PostTask(FROM_HERE, |
| 25 base::Bind(&Stream::CloseHandle, stream_)); |
| 26 } |
| 27 |
| 28 void StreamHandleImpl::OnStreamConsumed() { |
| 29 base::AutoLock lock(callback_lock_); |
| 30 stream_.reset(); |
| 31 if (!callback_.is_null()) { |
| 32 CHECK(callback_message_loop_); |
| 33 callback_message_loop_->PostTask(FROM_HERE, callback_); |
| 34 } |
| 35 } |
| 36 |
| 37 const GURL& StreamHandleImpl::GetURL() { |
| 38 return url_; |
| 39 } |
| 40 |
| 41 const GURL& StreamHandleImpl::GetOriginalURL() { |
| 42 return original_url_; |
| 43 } |
| 44 |
| 45 const std::string& StreamHandleImpl::GetMimeType() { |
| 46 return mime_type_; |
| 47 } |
| 48 |
| 49 void StreamHandleImpl::NotifyWhenConsumed(const base::Closure& callback) { |
| 50 base::AutoLock lock(callback_lock_); |
| 51 if (stream_) { |
| 52 callback_ = callback; |
| 53 callback_message_loop_ = base::MessageLoopProxy::current(); |
| 54 } else { |
| 55 // If the stream is NULL, the close event has already been sent. |
| 56 base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback); |
| 57 } |
| 58 } |
| 59 |
| 60 } // namespace content |
OLD | NEW |