Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1256)

Unified Diff: content/browser/streams/stream_handle_impl.cc

Issue 12645004: Add Resource Handler for creating Streams to forward to extensions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make sure things are called on the right thread. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698