| 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_handle_impl.h" | 5 #include "content/browser/streams/stream_handle_impl.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.h" | 10 #include "content/browser/streams/stream.h" |
| 11 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 namespace { |
| 16 |
| 17 void RunCloseListeners(const std::vector<base::Closure>& close_listeners) { |
| 18 for (size_t i = 0; i < close_listeners.size(); ++i) |
| 19 close_listeners[i].Run(); |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 15 StreamHandleImpl::StreamHandleImpl( | 24 StreamHandleImpl::StreamHandleImpl( |
| 16 const base::WeakPtr<Stream>& stream, | 25 const base::WeakPtr<Stream>& stream, |
| 17 const GURL& original_url, | 26 const GURL& original_url, |
| 18 const std::string& mime_type, | 27 const std::string& mime_type, |
| 19 scoped_refptr<net::HttpResponseHeaders> response_headers) | 28 scoped_refptr<net::HttpResponseHeaders> response_headers) |
| 20 : stream_(stream), | 29 : stream_(stream), |
| 21 url_(stream->url()), | 30 url_(stream->url()), |
| 22 original_url_(original_url), | 31 original_url_(original_url), |
| 23 mime_type_(mime_type), | 32 mime_type_(mime_type), |
| 24 response_headers_(response_headers), | 33 response_headers_(response_headers), |
| 25 stream_message_loop_(base::MessageLoopProxy::current().get()) {} | 34 stream_message_loop_(base::MessageLoopProxy::current().get()) {} |
| 26 | 35 |
| 27 StreamHandleImpl::~StreamHandleImpl() { | 36 StreamHandleImpl::~StreamHandleImpl() { |
| 28 stream_message_loop_->PostTask(FROM_HERE, | 37 stream_message_loop_->PostTaskAndReply(FROM_HERE, |
| 29 base::Bind(&Stream::CloseHandle, stream_)); | 38 base::Bind(&Stream::CloseHandle, stream_), |
| 39 base::Bind(&RunCloseListeners, close_listeners_)); |
| 30 } | 40 } |
| 31 | 41 |
| 32 const GURL& StreamHandleImpl::GetURL() { | 42 const GURL& StreamHandleImpl::GetURL() { |
| 33 return url_; | 43 return url_; |
| 34 } | 44 } |
| 35 | 45 |
| 36 const GURL& StreamHandleImpl::GetOriginalURL() { | 46 const GURL& StreamHandleImpl::GetOriginalURL() { |
| 37 return original_url_; | 47 return original_url_; |
| 38 } | 48 } |
| 39 | 49 |
| 40 const std::string& StreamHandleImpl::GetMimeType() { | 50 const std::string& StreamHandleImpl::GetMimeType() { |
| 41 return mime_type_; | 51 return mime_type_; |
| 42 } | 52 } |
| 43 | 53 |
| 44 scoped_refptr<net::HttpResponseHeaders> StreamHandleImpl::GetResponseHeaders() { | 54 scoped_refptr<net::HttpResponseHeaders> StreamHandleImpl::GetResponseHeaders() { |
| 45 return response_headers_; | 55 return response_headers_; |
| 46 } | 56 } |
| 47 | 57 |
| 58 void StreamHandleImpl::AddCloseListener(const base::Closure& callback) { |
| 59 close_listeners_.push_back(callback); |
| 60 } |
| 61 |
| 48 } // namespace content | 62 } // namespace content |
| OLD | NEW |