diff options
-rw-r--r-- | webkit/media/buffered_data_source.cc | 63 | ||||
-rw-r--r-- | webkit/media/buffered_data_source.h | 4 | ||||
-rw-r--r-- | webkit/media/simple_data_source.cc | 92 | ||||
-rw-r--r-- | webkit/media/simple_data_source.h | 3 | ||||
-rw-r--r-- | webkit/media/web_data_source.h | 2 |
5 files changed, 61 insertions, 103 deletions
diff --git a/webkit/media/buffered_data_source.cc b/webkit/media/buffered_data_source.cc index 70c29cd..8537073 100644 --- a/webkit/media/buffered_data_source.cc +++ b/webkit/media/buffered_data_source.cc @@ -78,6 +78,9 @@ void BufferedDataSource::set_host(media::DataSourceHost* host) { void BufferedDataSource::Initialize(const GURL& url, const media::PipelineStatusCB& callback) { + DCHECK(MessageLoop::current() == render_loop_); + DCHECK(!callback.is_null()); + DCHECK(!loader_.get()); url_ = url; // This data source doesn't support data:// protocol so reject it. @@ -86,15 +89,28 @@ void BufferedDataSource::Initialize(const GURL& url, return; } - DCHECK(!callback.is_null()); - { - base::AutoLock auto_lock(lock_); - initialize_cb_ = callback; + initialize_cb_ = callback; + + if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { + // Do an unbounded range request starting at the beginning. If the server + // responds with 200 instead of 206 we'll fall back into a streaming mode. + loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); + loader_->Start( + base::Bind(&BufferedDataSource::HttpInitialStartCallback, this), + base::Bind(&BufferedDataSource::NetworkEventCallback, this), + frame_); + return; } - // Post a task to complete the initialization task. - render_loop_->PostTask(FROM_HERE, - base::Bind(&BufferedDataSource::InitializeTask, this)); + // For all other protocols, assume they support range request. We fetch + // the full range of the resource to obtain the instance size because + // we won't be served HTTP headers. + loader_.reset(CreateResourceLoader(kPositionNotSpecified, + kPositionNotSpecified)); + loader_->Start( + base::Bind(&BufferedDataSource::NonHttpInitialStartCallback, this), + base::Bind(&BufferedDataSource::NetworkEventCallback, this), + frame_); } ///////////////////////////////////////////////////////////////////////////// @@ -178,39 +194,6 @@ void BufferedDataSource::Abort() { ///////////////////////////////////////////////////////////////////////////// // Render thread tasks. -void BufferedDataSource::InitializeTask() { - DCHECK(MessageLoop::current() == render_loop_); - DCHECK(!loader_.get()); - - { - base::AutoLock auto_lock(lock_); - if (stopped_on_render_loop_ || initialize_cb_.is_null() || - stop_signal_received_) { - return; - } - } - - if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { - // Do an unbounded range request starting at the beginning. If the server - // responds with 200 instead of 206 we'll fall back into a streaming mode. - loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); - loader_->Start( - base::Bind(&BufferedDataSource::HttpInitialStartCallback, this), - base::Bind(&BufferedDataSource::NetworkEventCallback, this), - frame_); - } else { - // For all other protocols, assume they support range request. We fetch - // the full range of the resource to obtain the instance size because - // we won't be served HTTP headers. - loader_.reset(CreateResourceLoader(kPositionNotSpecified, - kPositionNotSpecified)); - loader_->Start( - base::Bind(&BufferedDataSource::NonHttpInitialStartCallback, this), - base::Bind(&BufferedDataSource::NetworkEventCallback, this), - frame_); - } -} - void BufferedDataSource::ReadTask( int64 position, int read_size, diff --git a/webkit/media/buffered_data_source.h b/webkit/media/buffered_data_source.h index 8e4215f..079edd0 100644 --- a/webkit/media/buffered_data_source.h +++ b/webkit/media/buffered_data_source.h @@ -62,10 +62,6 @@ class BufferedDataSource : public WebDataSource { private: friend class BufferedDataSourceTest; - // Posted to perform initialization on render thread and start resource - // loading. - void InitializeTask(); - // Task posted to perform actual reading on the render thread. void ReadTask(int64 position, int read_size, uint8* read_buffer); diff --git a/webkit/media/simple_data_source.cc b/webkit/media/simple_data_source.cc index d521b32..b8e1317 100644 --- a/webkit/media/simple_data_source.cc +++ b/webkit/media/simple_data_source.cc @@ -64,6 +64,9 @@ void SimpleDataSource::Stop(const base::Closure& callback) { void SimpleDataSource::Initialize( const GURL& url, const media::PipelineStatusCB& callback) { + DCHECK(MessageLoop::current() == render_loop_); + DCHECK(!callback.is_null()); + // Reference to prevent destruction while inside the |initialize_cb_| // call. This is a temporary fix to prevent crashes caused by holding the // lock and running the destructor. @@ -71,7 +74,6 @@ void SimpleDataSource::Initialize( { base::AutoLock auto_lock(lock_); DCHECK_EQ(state_, UNINITIALIZED); - DCHECK(!callback.is_null()); state_ = INITIALIZING; initialize_cb_ = callback; @@ -82,9 +84,39 @@ void SimpleDataSource::Initialize( return; } - // Post a task to the render thread to start loading the resource. - render_loop_->PostTask(FROM_HERE, - base::Bind(&SimpleDataSource::StartTask, this)); + // If |url_| contains a data:// scheme we can decode it immediately. + if (url_.SchemeIs(kDataScheme)) { + std::string mime_type, charset; + bool success = net::DataURL::Parse(url_, &mime_type, &charset, &data_); + + // Don't care about the mime-type just proceed if decoding was successful. + size_ = data_.length(); + DoneInitialization_Locked(success); + return; + } + + // For all other schemes issue a request for the full resource. + WebKit::WebURLRequest request(url_); + request.setTargetType(WebKit::WebURLRequest::TargetIsMedia); + + frame_->setReferrerForRequest(request, WebKit::WebURL()); + + // Disable compression, compression for audio/video doesn't make sense. + request.setHTTPHeaderField( + WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), + WebString::fromUTF8("identity;q=1, *;q=0")); + + // This flag is for unittests as we don't want to reset |url_loader| + if (!keep_test_loader_) { + WebURLLoaderOptions options; + options.allowCredentials = true; + options.crossOriginRequestPolicy = + WebURLLoaderOptions::CrossOriginRequestPolicyAllow; + url_loader_.reset(frame_->createAssociatedURLLoader(options)); + } + + // Start the resource loading. + url_loader_->loadAsynchronously(request, this); } } @@ -242,58 +274,6 @@ void SimpleDataSource::Abort() { frame_ = NULL; } -void SimpleDataSource::StartTask() { - DCHECK(MessageLoop::current() == render_loop_); - // Reference to prevent destruction while inside the |initialize_cb_| - // call. This is a temporary fix to prevent crashes caused by holding the - // lock and running the destructor. - scoped_refptr<SimpleDataSource> destruction_guard(this); - { - base::AutoLock auto_lock(lock_); - - // We may have stopped. - if (state_ == STOPPED) - return; - - CHECK(frame_); - - DCHECK_EQ(state_, INITIALIZING); - - if (url_.SchemeIs(kDataScheme)) { - // If this using data protocol, we just need to decode it. - std::string mime_type, charset; - bool success = net::DataURL::Parse(url_, &mime_type, &charset, &data_); - - // Don't care about the mime-type just proceed if decoding was successful. - size_ = data_.length(); - DoneInitialization_Locked(success); - } else { - // Prepare the request. - WebKit::WebURLRequest request(url_); - request.setTargetType(WebKit::WebURLRequest::TargetIsMedia); - - frame_->setReferrerForRequest(request, WebKit::WebURL()); - - // Disable compression, compression for audio/video doesn't make sense... - request.setHTTPHeaderField( - WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), - WebString::fromUTF8("identity;q=1, *;q=0")); - - // This flag is for unittests as we don't want to reset |url_loader| - if (!keep_test_loader_) { - WebURLLoaderOptions options; - options.allowCredentials = true; - options.crossOriginRequestPolicy = - WebURLLoaderOptions::CrossOriginRequestPolicyAllow; - url_loader_.reset(frame_->createAssociatedURLLoader(options)); - } - - // Start the resource loading. - url_loader_->loadAsynchronously(request, this); - } - } -} - void SimpleDataSource::CancelTask() { DCHECK(MessageLoop::current() == render_loop_); base::AutoLock auto_lock(lock_); diff --git a/webkit/media/simple_data_source.h b/webkit/media/simple_data_source.h index 94f144f..b999ed7 100644 --- a/webkit/media/simple_data_source.h +++ b/webkit/media/simple_data_source.h @@ -91,9 +91,6 @@ class SimpleDataSource virtual void Abort() OVERRIDE; private: - // Creates and starts the resource loading on the render thread. - void StartTask(); - // Cancels and deletes the resource loading on the render thread. void CancelTask(); diff --git a/webkit/media/web_data_source.h b/webkit/media/web_data_source.h index 260e003..e2f9b1f 100644 --- a/webkit/media/web_data_source.h +++ b/webkit/media/web_data_source.h @@ -22,6 +22,8 @@ class WebDataSource : public media::DataSource { // Initialize this object using |url|. This object calls |callback| when // initialization has completed. + // + // Method called on the render thread. virtual void Initialize(const GURL& url, const media::PipelineStatusCB& callback) = 0; |