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..2c05a1ee99dd5fb1c3390024ed8037d1a5726fe9 |
--- /dev/null |
+++ b/content/browser/streams/stream_handle_impl.cc |
@@ -0,0 +1,60 @@ |
+// 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(const base::WeakPtr<Stream>& stream, |
+ const GURL& original_url, |
+ const std::string& mime_type) |
+ : stream_(stream), |
+ url_(stream->url()), |
+ original_url_(original_url), |
+ mime_type_(mime_type), |
+ 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::OnStreamConsumed() { |
+ 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_; |
+} |
+ |
+const GURL& StreamHandleImpl::GetOriginalURL() { |
+ return original_url_; |
+} |
+ |
+const std::string& StreamHandleImpl::GetMimeType() { |
+ return mime_type_; |
+} |
+ |
+void StreamHandleImpl::NotifyWhenConsumed(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 |