#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "content/public/common/url_constants.h"
#include "media/base/media_log.h"
#include "net/base/net_errors.h"
const scoped_refptr<base::MessageLoopProxy>& render_loop,
WebFrame* frame,
media::MediaLog* media_log,
+ BufferedDataSourceHost* host,
const DownloadingCB& downloading_cb)
: cors_mode_(BufferedResourceLoader::kUnspecified),
total_bytes_(kPositionNotSpecified),
bitrate_(0),
playback_rate_(0.0),
media_log_(media_log),
+ host_(host),
downloading_cb_(downloading_cb),
weak_factory_(this) {
+ DCHECK(host_);
DCHECK(!downloading_cb_.is_null());
}
media_log_.get());
}
-void BufferedDataSource::set_host(media::DataSourceHost* host) {
- DataSource::set_host(host);
-
- if (loader_) {
- base::AutoLock auto_lock(lock_);
- UpdateHostState_Locked();
- }
-}
-
void BufferedDataSource::Initialize(
const GURL& url,
BufferedResourceLoader::CORSMode cors_mode,
init_cb_ = init_cb;
- if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) {
+ if (url_.SchemeIs(url::kHttpScheme) || url_.SchemeIs(url::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));
return;
if (success) {
- UpdateHostState_Locked();
+ if (total_bytes_ != kPositionNotSpecified) {
+ host_->SetTotalBytes(total_bytes_);
+ if (assume_fully_buffered_)
+ host_->AddBufferedByteRange(0, total_bytes_);
+ }
+
media_log_->SetBooleanProperty("single_origin", loader_->HasSingleOrigin());
media_log_->SetBooleanProperty("passed_cors_access_check",
loader_->DidPassCORSAccessCheck());
// fail like they would if we had known the file size at the beginning.
total_bytes_ = loader_->instance_size();
- if (host() && total_bytes_ != kPositionNotSpecified) {
- host()->SetTotalBytes(total_bytes_);
- host()->AddBufferedByteRange(loader_->first_byte_position(),
- total_bytes_);
+ if (total_bytes_ != kPositionNotSpecified) {
+ host_->SetTotalBytes(total_bytes_);
+ host_->AddBufferedByteRange(loader_->first_byte_position(),
+ total_bytes_);
}
}
ReadOperation::Run(read_op_.Pass(), bytes_read);
if (stop_signal_received_)
return;
- ReportOrQueueBufferedBytes(loader_->first_byte_position(), position);
-}
-
-void BufferedDataSource::ReportOrQueueBufferedBytes(int64 start, int64 end) {
- if (host())
- host()->AddBufferedByteRange(start, end);
- else
- queued_buffered_byte_ranges_.Add(start, end);
-}
-
-void BufferedDataSource::UpdateHostState_Locked() {
- lock_.AssertAcquired();
-
- if (!host())
- return;
-
- for (size_t i = 0; i < queued_buffered_byte_ranges_.size(); ++i) {
- host()->AddBufferedByteRange(queued_buffered_byte_ranges_.start(i),
- queued_buffered_byte_ranges_.end(i));
- }
- queued_buffered_byte_ranges_.clear();
-
- if (total_bytes_ == kPositionNotSpecified)
- return;
-
- host()->SetTotalBytes(total_bytes_);
-
- if (assume_fully_buffered_)
- host()->AddBufferedByteRange(0, total_bytes_);
+ host_->AddBufferedByteRange(loader_->first_byte_position(), position);
}
void BufferedDataSource::UpdateDeferStrategy(bool paused) {