| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 17 matching lines...) Expand all  Loading... | 
| 28     : render_loop_(render_loop), | 28     : render_loop_(render_loop), | 
| 29       frame_(frame), | 29       frame_(frame), | 
| 30       size_(-1), | 30       size_(-1), | 
| 31       single_origin_(true), | 31       single_origin_(true), | 
| 32       state_(UNINITIALIZED), | 32       state_(UNINITIALIZED), | 
| 33       keep_test_loader_(false) { | 33       keep_test_loader_(false) { | 
| 34   DCHECK(render_loop); | 34   DCHECK(render_loop); | 
| 35 } | 35 } | 
| 36 | 36 | 
| 37 SimpleDataSource::~SimpleDataSource() { | 37 SimpleDataSource::~SimpleDataSource() { | 
| 38   AutoLock auto_lock(lock_); | 38   base::AutoLock auto_lock(lock_); | 
| 39   DCHECK(state_ == UNINITIALIZED || state_ == STOPPED); | 39   DCHECK(state_ == UNINITIALIZED || state_ == STOPPED); | 
| 40 } | 40 } | 
| 41 | 41 | 
| 42 void SimpleDataSource::Stop(media::FilterCallback* callback) { | 42 void SimpleDataSource::Stop(media::FilterCallback* callback) { | 
| 43   AutoLock auto_lock(lock_); | 43   base::AutoLock auto_lock(lock_); | 
| 44   state_ = STOPPED; | 44   state_ = STOPPED; | 
| 45   if (callback) { | 45   if (callback) { | 
| 46     callback->Run(); | 46     callback->Run(); | 
| 47     delete callback; | 47     delete callback; | 
| 48   } | 48   } | 
| 49 | 49 | 
| 50   // Post a task to the render thread to cancel loading the resource. | 50   // Post a task to the render thread to cancel loading the resource. | 
| 51   render_loop_->PostTask(FROM_HERE, | 51   render_loop_->PostTask(FROM_HERE, | 
| 52       NewRunnableMethod(this, &SimpleDataSource::CancelTask)); | 52       NewRunnableMethod(this, &SimpleDataSource::CancelTask)); | 
| 53 } | 53 } | 
| 54 | 54 | 
| 55 void SimpleDataSource::Initialize(const std::string& url, | 55 void SimpleDataSource::Initialize(const std::string& url, | 
| 56                                   media::FilterCallback* callback) { | 56                                   media::FilterCallback* callback) { | 
| 57   AutoLock auto_lock(lock_); | 57   base::AutoLock auto_lock(lock_); | 
| 58   DCHECK_EQ(state_, UNINITIALIZED); | 58   DCHECK_EQ(state_, UNINITIALIZED); | 
| 59   DCHECK(callback); | 59   DCHECK(callback); | 
| 60   state_ = INITIALIZING; | 60   state_ = INITIALIZING; | 
| 61   initialize_callback_.reset(callback); | 61   initialize_callback_.reset(callback); | 
| 62 | 62 | 
| 63   // Validate the URL. | 63   // Validate the URL. | 
| 64   SetURL(GURL(url)); | 64   SetURL(GURL(url)); | 
| 65   if (!url_.is_valid() || !IsProtocolSupportedForMedia(url_)) { | 65   if (!url_.is_valid() || !IsProtocolSupportedForMedia(url_)) { | 
| 66     host()->SetError(media::PIPELINE_ERROR_NETWORK); | 66     host()->SetError(media::PIPELINE_ERROR_NETWORK); | 
| 67     initialize_callback_->Run(); | 67     initialize_callback_->Run(); | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 150     WebKit::WebURLLoader* loader, | 150     WebKit::WebURLLoader* loader, | 
| 151     const char* data, | 151     const char* data, | 
| 152     int dataLength) { | 152     int dataLength) { | 
| 153   NOTIMPLEMENTED(); | 153   NOTIMPLEMENTED(); | 
| 154 } | 154 } | 
| 155 | 155 | 
| 156 void SimpleDataSource::didFinishLoading( | 156 void SimpleDataSource::didFinishLoading( | 
| 157     WebKit::WebURLLoader* loader, | 157     WebKit::WebURLLoader* loader, | 
| 158     double finishTime) { | 158     double finishTime) { | 
| 159   DCHECK(MessageLoop::current() == render_loop_); | 159   DCHECK(MessageLoop::current() == render_loop_); | 
| 160   AutoLock auto_lock(lock_); | 160   base::AutoLock auto_lock(lock_); | 
| 161   // It's possible this gets called after Stop(), in which case |host_| is no | 161   // It's possible this gets called after Stop(), in which case |host_| is no | 
| 162   // longer valid. | 162   // longer valid. | 
| 163   if (state_ == STOPPED) | 163   if (state_ == STOPPED) | 
| 164     return; | 164     return; | 
| 165 | 165 | 
| 166   // Otherwise we should be initializing and have created a WebURLLoader. | 166   // Otherwise we should be initializing and have created a WebURLLoader. | 
| 167   DCHECK_EQ(state_, INITIALIZING); | 167   DCHECK_EQ(state_, INITIALIZING); | 
| 168 | 168 | 
| 169   // If we don't get a content length or the request has failed, report it | 169   // If we don't get a content length or the request has failed, report it | 
| 170   // as a network error. | 170   // as a network error. | 
| 171   if (size_ == -1) | 171   if (size_ == -1) | 
| 172     size_ = data_.length(); | 172     size_ = data_.length(); | 
| 173   DCHECK(static_cast<size_t>(size_) == data_.length()); | 173   DCHECK(static_cast<size_t>(size_) == data_.length()); | 
| 174 | 174 | 
| 175   DoneInitialization_Locked(true); | 175   DoneInitialization_Locked(true); | 
| 176 } | 176 } | 
| 177 | 177 | 
| 178 void SimpleDataSource::didFail( | 178 void SimpleDataSource::didFail( | 
| 179     WebKit::WebURLLoader* loader, | 179     WebKit::WebURLLoader* loader, | 
| 180     const WebKit::WebURLError& error) { | 180     const WebKit::WebURLError& error) { | 
| 181   DCHECK(MessageLoop::current() == render_loop_); | 181   DCHECK(MessageLoop::current() == render_loop_); | 
| 182   AutoLock auto_lock(lock_); | 182   base::AutoLock auto_lock(lock_); | 
| 183   // It's possible this gets called after Stop(), in which case |host_| is no | 183   // It's possible this gets called after Stop(), in which case |host_| is no | 
| 184   // longer valid. | 184   // longer valid. | 
| 185   if (state_ == STOPPED) | 185   if (state_ == STOPPED) | 
| 186     return; | 186     return; | 
| 187 | 187 | 
| 188   // Otherwise we should be initializing and have created a WebURLLoader. | 188   // Otherwise we should be initializing and have created a WebURLLoader. | 
| 189   DCHECK_EQ(state_, INITIALIZING); | 189   DCHECK_EQ(state_, INITIALIZING); | 
| 190 | 190 | 
| 191   // If we don't get a content length or the request has failed, report it | 191   // If we don't get a content length or the request has failed, report it | 
| 192   // as a network error. | 192   // as a network error. | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 210 void SimpleDataSource::SetURL(const GURL& url) { | 210 void SimpleDataSource::SetURL(const GURL& url) { | 
| 211   url_ = url; | 211   url_ = url; | 
| 212   media_format_.Clear(); | 212   media_format_.Clear(); | 
| 213   media_format_.SetAsString(media::MediaFormat::kMimeType, | 213   media_format_.SetAsString(media::MediaFormat::kMimeType, | 
| 214                             media::mime_type::kApplicationOctetStream); | 214                             media::mime_type::kApplicationOctetStream); | 
| 215   media_format_.SetAsString(media::MediaFormat::kURL, url.spec()); | 215   media_format_.SetAsString(media::MediaFormat::kURL, url.spec()); | 
| 216 } | 216 } | 
| 217 | 217 | 
| 218 void SimpleDataSource::StartTask() { | 218 void SimpleDataSource::StartTask() { | 
| 219   DCHECK(MessageLoop::current() == render_loop_); | 219   DCHECK(MessageLoop::current() == render_loop_); | 
| 220   AutoLock auto_lock(lock_); | 220   base::AutoLock auto_lock(lock_); | 
| 221 | 221 | 
| 222   // We may have stopped. | 222   // We may have stopped. | 
| 223   if (state_ == STOPPED) | 223   if (state_ == STOPPED) | 
| 224     return; | 224     return; | 
| 225 | 225 | 
| 226   CHECK(frame_); | 226   CHECK(frame_); | 
| 227 | 227 | 
| 228   DCHECK_EQ(state_, INITIALIZING); | 228   DCHECK_EQ(state_, INITIALIZING); | 
| 229 | 229 | 
| 230   if (url_.SchemeIs(kDataScheme)) { | 230   if (url_.SchemeIs(kDataScheme)) { | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 246     if (!keep_test_loader_) | 246     if (!keep_test_loader_) | 
| 247       url_loader_.reset(frame_->createAssociatedURLLoader()); | 247       url_loader_.reset(frame_->createAssociatedURLLoader()); | 
| 248 | 248 | 
| 249     // Start the resource loading. | 249     // Start the resource loading. | 
| 250     url_loader_->loadAsynchronously(request, this); | 250     url_loader_->loadAsynchronously(request, this); | 
| 251   } | 251   } | 
| 252 } | 252 } | 
| 253 | 253 | 
| 254 void SimpleDataSource::CancelTask() { | 254 void SimpleDataSource::CancelTask() { | 
| 255   DCHECK(MessageLoop::current() == render_loop_); | 255   DCHECK(MessageLoop::current() == render_loop_); | 
| 256   AutoLock auto_lock(lock_); | 256   base::AutoLock auto_lock(lock_); | 
| 257   DCHECK_EQ(state_, STOPPED); | 257   DCHECK_EQ(state_, STOPPED); | 
| 258 | 258 | 
| 259   // Cancel any pending requests. | 259   // Cancel any pending requests. | 
| 260   if (url_loader_.get()) { | 260   if (url_loader_.get()) { | 
| 261     url_loader_->cancel(); | 261     url_loader_->cancel(); | 
| 262     url_loader_.reset(); | 262     url_loader_.reset(); | 
| 263   } | 263   } | 
| 264 } | 264 } | 
| 265 | 265 | 
| 266 void SimpleDataSource::DoneInitialization_Locked(bool success) { | 266 void SimpleDataSource::DoneInitialization_Locked(bool success) { | 
| 267   lock_.AssertAcquired(); | 267   lock_.AssertAcquired(); | 
| 268   if (success) { | 268   if (success) { | 
| 269     state_ = INITIALIZED; | 269     state_ = INITIALIZED; | 
| 270     host()->SetTotalBytes(size_); | 270     host()->SetTotalBytes(size_); | 
| 271     host()->SetBufferedBytes(size_); | 271     host()->SetBufferedBytes(size_); | 
| 272     // If scheme is file or data, say we are loaded. | 272     // If scheme is file or data, say we are loaded. | 
| 273     host()->SetLoaded(url_.SchemeIsFile() || url_.SchemeIs(kDataScheme)); | 273     host()->SetLoaded(url_.SchemeIsFile() || url_.SchemeIs(kDataScheme)); | 
| 274   } else { | 274   } else { | 
| 275     host()->SetError(media::PIPELINE_ERROR_NETWORK); | 275     host()->SetError(media::PIPELINE_ERROR_NETWORK); | 
| 276   } | 276   } | 
| 277   initialize_callback_->Run(); | 277   initialize_callback_->Run(); | 
| 278   initialize_callback_.reset(); | 278   initialize_callback_.reset(); | 
| 279 } | 279 } | 
| 280 | 280 | 
| 281 }  // namespace webkit_glue | 281 }  // namespace webkit_glue | 
| OLD | NEW | 
|---|