OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/process_util.h" | 6 #include "base/process_util.h" |
7 #include "media/base/filter_host.h" | 7 #include "media/base/filter_host.h" |
8 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
9 #include "net/http/http_response_headers.h" | 9 #include "net/http/http_response_headers.h" |
10 #include "net/url_request/url_request_status.h" | 10 #include "net/url_request/url_request_status.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 void SimpleDataSource::Stop() { | 49 void SimpleDataSource::Stop() { |
50 AutoLock auto_lock(lock_); | 50 AutoLock auto_lock(lock_); |
51 state_ = STOPPED; | 51 state_ = STOPPED; |
52 | 52 |
53 // Post a task to the render thread to cancel loading the resource. | 53 // Post a task to the render thread to cancel loading the resource. |
54 render_loop_->PostTask(FROM_HERE, | 54 render_loop_->PostTask(FROM_HERE, |
55 NewRunnableMethod(this, &SimpleDataSource::CancelTask)); | 55 NewRunnableMethod(this, &SimpleDataSource::CancelTask)); |
56 } | 56 } |
57 | 57 |
58 bool SimpleDataSource::Initialize(const std::string& url) { | 58 void SimpleDataSource::Initialize(const std::string& url, |
| 59 media::FilterCallback* callback) { |
59 AutoLock auto_lock(lock_); | 60 AutoLock auto_lock(lock_); |
60 DCHECK_EQ(state_, UNINITIALIZED); | 61 DCHECK_EQ(state_, UNINITIALIZED); |
| 62 DCHECK(callback); |
61 state_ = INITIALIZING; | 63 state_ = INITIALIZING; |
| 64 initialize_callback_.reset(callback); |
62 | 65 |
63 // Validate the URL. | 66 // Validate the URL. |
64 SetURL(GURL(url)); | 67 SetURL(GURL(url)); |
65 if (!url_.is_valid() || !IsSchemeSupported(url_)) { | 68 if (!url_.is_valid() || !IsSchemeSupported(url_)) { |
66 host()->Error(media::PIPELINE_ERROR_NETWORK); | 69 host()->Error(media::PIPELINE_ERROR_NETWORK); |
67 return false; | 70 initialize_callback_->Run(); |
| 71 initialize_callback_.reset(); |
| 72 return; |
68 } | 73 } |
69 | 74 |
70 // Post a task to the render thread to start loading the resource. | 75 // Post a task to the render thread to start loading the resource. |
71 render_loop_->PostTask(FROM_HERE, | 76 render_loop_->PostTask(FROM_HERE, |
72 NewRunnableMethod(this, &SimpleDataSource::StartTask)); | 77 NewRunnableMethod(this, &SimpleDataSource::StartTask)); |
73 return true; | |
74 } | 78 } |
75 | 79 |
76 const media::MediaFormat& SimpleDataSource::media_format() { | 80 const media::MediaFormat& SimpleDataSource::media_format() { |
77 return media_format_; | 81 return media_format_; |
78 } | 82 } |
79 | 83 |
80 size_t SimpleDataSource::Read(uint8* data, size_t size) { | 84 size_t SimpleDataSource::Read(uint8* data, size_t size) { |
81 DCHECK_GE(size_, 0); | 85 DCHECK_GE(size_, 0); |
82 size_t copied = std::min(size, static_cast<size_t>(size_ - position_)); | 86 size_t copied = std::min(size, static_cast<size_t>(size_ - position_)); |
83 memcpy(data, data_.c_str() + position_, copied); | 87 memcpy(data, data_.c_str() + position_, copied); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 DCHECK_EQ(state_, INITIALIZING); | 141 DCHECK_EQ(state_, INITIALIZING); |
138 DCHECK(bridge_.get()); | 142 DCHECK(bridge_.get()); |
139 bridge_.reset(); | 143 bridge_.reset(); |
140 | 144 |
141 // If we don't get a content length or the request has failed, report it | 145 // If we don't get a content length or the request has failed, report it |
142 // as a network error. | 146 // as a network error. |
143 DCHECK(size_ == -1 || size_ == data_.length()); | 147 DCHECK(size_ == -1 || size_ == data_.length()); |
144 if (size_ == -1) { | 148 if (size_ == -1) { |
145 size_ = data_.length(); | 149 size_ = data_.length(); |
146 } | 150 } |
147 if (!status.is_success()) { | |
148 host()->Error(media::PIPELINE_ERROR_NETWORK); | |
149 return; | |
150 } | |
151 | 151 |
152 // We're initialized! | 152 // We're initialized! |
153 state_ = INITIALIZED; | 153 if (status.is_success()) { |
154 host()->SetTotalBytes(size_); | 154 state_ = INITIALIZED; |
155 host()->SetBufferedBytes(size_); | 155 host()->SetTotalBytes(size_); |
156 host()->InitializationComplete(); | 156 host()->SetBufferedBytes(size_); |
| 157 } else { |
| 158 host()->Error(media::PIPELINE_ERROR_NETWORK); |
| 159 } |
| 160 initialize_callback_->Run(); |
| 161 initialize_callback_.reset(); |
157 } | 162 } |
158 | 163 |
159 std::string SimpleDataSource::GetURLForDebugging() { | 164 std::string SimpleDataSource::GetURLForDebugging() { |
160 return url_.spec(); | 165 return url_.spec(); |
161 } | 166 } |
162 | 167 |
163 void SimpleDataSource::SetURL(const GURL& url) { | 168 void SimpleDataSource::SetURL(const GURL& url) { |
164 url_ = url; | 169 url_ = url; |
165 media_format_.Clear(); | 170 media_format_.Clear(); |
166 media_format_.SetAsString(media::MediaFormat::kMimeType, | 171 media_format_.SetAsString(media::MediaFormat::kMimeType, |
(...skipping 22 matching lines...) Expand all Loading... |
189 DCHECK_EQ(state_, STOPPED); | 194 DCHECK_EQ(state_, STOPPED); |
190 | 195 |
191 // Cancel any pending requests. | 196 // Cancel any pending requests. |
192 if (bridge_.get()) { | 197 if (bridge_.get()) { |
193 bridge_->Cancel(); | 198 bridge_->Cancel(); |
194 bridge_.reset(); | 199 bridge_.reset(); |
195 } | 200 } |
196 } | 201 } |
197 | 202 |
198 } // namespace webkit_glue | 203 } // namespace webkit_glue |
OLD | NEW |