| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/glue/media/simple_data_source.h" | 5 #include "webkit/glue/media/simple_data_source.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 9 #include "media/base/filter_host.h" | 9 #include "media/base/filter_host.h" |
| 10 #include "net/base/data_url.h" | 10 #include "net/base/data_url.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 delete callback; | 73 delete callback; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Post a task to the render thread to cancel loading the resource. | 76 // Post a task to the render thread to cancel loading the resource. |
| 77 render_loop_->PostTask(FROM_HERE, | 77 render_loop_->PostTask(FROM_HERE, |
| 78 NewRunnableMethod(this, &SimpleDataSource::CancelTask)); | 78 NewRunnableMethod(this, &SimpleDataSource::CancelTask)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void SimpleDataSource::Initialize( | 81 void SimpleDataSource::Initialize( |
| 82 const std::string& url, | 82 const std::string& url, |
| 83 media::PipelineStatusCallback* callback) { | 83 const media::PipelineStatusCB& callback) { |
| 84 // Reference to prevent destruction while inside the |initialize_callback_| | 84 // Reference to prevent destruction while inside the |initialize_cb_| |
| 85 // call. This is a temporary fix to prevent crashes caused by holding the | 85 // call. This is a temporary fix to prevent crashes caused by holding the |
| 86 // lock and running the destructor. | 86 // lock and running the destructor. |
| 87 scoped_refptr<SimpleDataSource> destruction_guard(this); | 87 scoped_refptr<SimpleDataSource> destruction_guard(this); |
| 88 { | 88 { |
| 89 base::AutoLock auto_lock(lock_); | 89 base::AutoLock auto_lock(lock_); |
| 90 DCHECK_EQ(state_, UNINITIALIZED); | 90 DCHECK_EQ(state_, UNINITIALIZED); |
| 91 DCHECK(callback); | 91 DCHECK(!callback.is_null()); |
| 92 state_ = INITIALIZING; | 92 state_ = INITIALIZING; |
| 93 initialize_callback_.reset(callback); | 93 initialize_cb_ = callback; |
| 94 | 94 |
| 95 // Validate the URL. | 95 // Validate the URL. |
| 96 url_ = GURL(url); | 96 url_ = GURL(url); |
| 97 if (!url_.is_valid() || !IsProtocolSupportedForMedia(url_)) { | 97 if (!url_.is_valid() || !IsProtocolSupportedForMedia(url_)) { |
| 98 DoneInitialization_Locked(false); | 98 DoneInitialization_Locked(false); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Post a task to the render thread to start loading the resource. | 102 // Post a task to the render thread to start loading the resource. |
| 103 render_loop_->PostTask(FROM_HERE, | 103 render_loop_->PostTask(FROM_HERE, |
| 104 NewRunnableMethod(this, &SimpleDataSource::StartTask)); | 104 NewRunnableMethod(this, &SimpleDataSource::StartTask)); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 void SimpleDataSource::CancelInitialize() { | 108 void SimpleDataSource::CancelInitialize() { |
| 109 base::AutoLock auto_lock(lock_); | 109 base::AutoLock auto_lock(lock_); |
| 110 DCHECK(initialize_callback_.get()); | 110 DCHECK(!initialize_cb_.is_null()); |
| 111 state_ = STOPPED; | 111 state_ = STOPPED; |
| 112 initialize_callback_.reset(); | 112 initialize_cb_.Reset(); |
| 113 | 113 |
| 114 // Post a task to the render thread to cancel loading the resource. | 114 // Post a task to the render thread to cancel loading the resource. |
| 115 render_loop_->PostTask(FROM_HERE, | 115 render_loop_->PostTask(FROM_HERE, |
| 116 NewRunnableMethod(this, &SimpleDataSource::CancelTask)); | 116 NewRunnableMethod(this, &SimpleDataSource::CancelTask)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void SimpleDataSource::Read(int64 position, | 119 void SimpleDataSource::Read(int64 position, |
| 120 size_t size, | 120 size_t size, |
| 121 uint8* data, | 121 uint8* data, |
| 122 ReadCallback* read_callback) { | 122 ReadCallback* read_callback) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 WebKit::WebURLLoader* loader, | 195 WebKit::WebURLLoader* loader, |
| 196 const char* data, | 196 const char* data, |
| 197 int dataLength) { | 197 int dataLength) { |
| 198 NOTIMPLEMENTED(); | 198 NOTIMPLEMENTED(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void SimpleDataSource::didFinishLoading( | 201 void SimpleDataSource::didFinishLoading( |
| 202 WebKit::WebURLLoader* loader, | 202 WebKit::WebURLLoader* loader, |
| 203 double finishTime) { | 203 double finishTime) { |
| 204 DCHECK(MessageLoop::current() == render_loop_); | 204 DCHECK(MessageLoop::current() == render_loop_); |
| 205 // Reference to prevent destruction while inside the |initialize_callback_| | 205 // Reference to prevent destruction while inside the |initialize_cb_| |
| 206 // call. This is a temporary fix to prevent crashes caused by holding the | 206 // call. This is a temporary fix to prevent crashes caused by holding the |
| 207 // lock and running the destructor. | 207 // lock and running the destructor. |
| 208 scoped_refptr<SimpleDataSource> destruction_guard(this); | 208 scoped_refptr<SimpleDataSource> destruction_guard(this); |
| 209 { | 209 { |
| 210 base::AutoLock auto_lock(lock_); | 210 base::AutoLock auto_lock(lock_); |
| 211 // It's possible this gets called after Stop(), in which case |host_| is no | 211 // It's possible this gets called after Stop(), in which case |host_| is no |
| 212 // longer valid. | 212 // longer valid. |
| 213 if (state_ == STOPPED) | 213 if (state_ == STOPPED) |
| 214 return; | 214 return; |
| 215 | 215 |
| 216 // Otherwise we should be initializing and have created a WebURLLoader. | 216 // Otherwise we should be initializing and have created a WebURLLoader. |
| 217 DCHECK_EQ(state_, INITIALIZING); | 217 DCHECK_EQ(state_, INITIALIZING); |
| 218 | 218 |
| 219 // If we don't get a content length or the request has failed, report it | 219 // If we don't get a content length or the request has failed, report it |
| 220 // as a network error. | 220 // as a network error. |
| 221 if (size_ == -1) | 221 if (size_ == -1) |
| 222 size_ = data_.length(); | 222 size_ = data_.length(); |
| 223 DCHECK(static_cast<size_t>(size_) == data_.length()); | 223 DCHECK(static_cast<size_t>(size_) == data_.length()); |
| 224 | 224 |
| 225 DoneInitialization_Locked(true); | 225 DoneInitialization_Locked(true); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 void SimpleDataSource::didFail( | 229 void SimpleDataSource::didFail( |
| 230 WebKit::WebURLLoader* loader, | 230 WebKit::WebURLLoader* loader, |
| 231 const WebKit::WebURLError& error) { | 231 const WebKit::WebURLError& error) { |
| 232 DCHECK(MessageLoop::current() == render_loop_); | 232 DCHECK(MessageLoop::current() == render_loop_); |
| 233 // Reference to prevent destruction while inside the |initialize_callback_| | 233 // Reference to prevent destruction while inside the |initialize_cb_| |
| 234 // call. This is a temporary fix to prevent crashes caused by holding the | 234 // call. This is a temporary fix to prevent crashes caused by holding the |
| 235 // lock and running the destructor. | 235 // lock and running the destructor. |
| 236 scoped_refptr<SimpleDataSource> destruction_guard(this); | 236 scoped_refptr<SimpleDataSource> destruction_guard(this); |
| 237 { | 237 { |
| 238 base::AutoLock auto_lock(lock_); | 238 base::AutoLock auto_lock(lock_); |
| 239 // It's possible this gets called after Stop(), in which case |host_| is no | 239 // It's possible this gets called after Stop(), in which case |host_| is no |
| 240 // longer valid. | 240 // longer valid. |
| 241 if (state_ == STOPPED) | 241 if (state_ == STOPPED) |
| 242 return; | 242 return; |
| 243 | 243 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 259 return single_origin_; | 259 return single_origin_; |
| 260 } | 260 } |
| 261 | 261 |
| 262 void SimpleDataSource::Abort() { | 262 void SimpleDataSource::Abort() { |
| 263 DCHECK(MessageLoop::current() == render_loop_); | 263 DCHECK(MessageLoop::current() == render_loop_); |
| 264 frame_ = NULL; | 264 frame_ = NULL; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void SimpleDataSource::StartTask() { | 267 void SimpleDataSource::StartTask() { |
| 268 DCHECK(MessageLoop::current() == render_loop_); | 268 DCHECK(MessageLoop::current() == render_loop_); |
| 269 // Reference to prevent destruction while inside the |initialize_callback_| | 269 // Reference to prevent destruction while inside the |initialize_cb_| |
| 270 // call. This is a temporary fix to prevent crashes caused by holding the | 270 // call. This is a temporary fix to prevent crashes caused by holding the |
| 271 // lock and running the destructor. | 271 // lock and running the destructor. |
| 272 scoped_refptr<SimpleDataSource> destruction_guard(this); | 272 scoped_refptr<SimpleDataSource> destruction_guard(this); |
| 273 { | 273 { |
| 274 base::AutoLock auto_lock(lock_); | 274 base::AutoLock auto_lock(lock_); |
| 275 | 275 |
| 276 // We may have stopped. | 276 // We may have stopped. |
| 277 if (state_ == STOPPED) | 277 if (state_ == STOPPED) |
| 278 return; | 278 return; |
| 279 | 279 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 if (success) { | 334 if (success) { |
| 335 state_ = INITIALIZED; | 335 state_ = INITIALIZED; |
| 336 | 336 |
| 337 UpdateHostState(); | 337 UpdateHostState(); |
| 338 status = media::PIPELINE_OK; | 338 status = media::PIPELINE_OK; |
| 339 } else { | 339 } else { |
| 340 state_ = UNINITIALIZED; | 340 state_ = UNINITIALIZED; |
| 341 url_loader_.reset(); | 341 url_loader_.reset(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 scoped_ptr<media::PipelineStatusCallback> initialize_callback( | 344 initialize_cb_.Run(status); |
| 345 initialize_callback_.release()); | 345 initialize_cb_.Reset(); |
| 346 initialize_callback->Run(status); | |
| 347 } | 346 } |
| 348 | 347 |
| 349 void SimpleDataSource::UpdateHostState() { | 348 void SimpleDataSource::UpdateHostState() { |
| 350 if (host()) { | 349 if (host()) { |
| 351 host()->SetTotalBytes(size_); | 350 host()->SetTotalBytes(size_); |
| 352 host()->SetBufferedBytes(size_); | 351 host()->SetBufferedBytes(size_); |
| 353 // If scheme is file or data, say we are loaded. | 352 // If scheme is file or data, say we are loaded. |
| 354 host()->SetLoaded(url_.SchemeIsFile() || url_.SchemeIs(kDataScheme)); | 353 host()->SetLoaded(url_.SchemeIsFile() || url_.SchemeIs(kDataScheme)); |
| 355 } | 354 } |
| 356 } | 355 } |
| 357 | 356 |
| 358 } // namespace webkit_glue | 357 } // namespace webkit_glue |
| OLD | NEW |