Changing constructor of BufferedDataSource to accept GURL and CORSMode

BufferedDataSource should accept the 'url' and the 'CORS mode' parameters
in the constructor instead via the initialize() method. This patch makes
this change and now only the 'initializeCallBack' is passed to initialize()
method. Also now the WebMediaPlayerImpl directly queries the BufferedDataSource
whether the resource is local or not, instead of finding it out itself.

Review URL: https://codereview.chromium.org/306953005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274513 0039d316-1c4b-4281-b951-d872f2087c98
parent dab5bae2
...@@ -79,14 +79,16 @@ void BufferedDataSource::ReadOperation::Run( ...@@ -79,14 +79,16 @@ void BufferedDataSource::ReadOperation::Run(
} }
BufferedDataSource::BufferedDataSource( BufferedDataSource::BufferedDataSource(
const GURL& url,
BufferedResourceLoader::CORSMode cors_mode,
const scoped_refptr<base::MessageLoopProxy>& render_loop, const scoped_refptr<base::MessageLoopProxy>& render_loop,
WebFrame* frame, WebFrame* frame,
media::MediaLog* media_log, media::MediaLog* media_log,
BufferedDataSourceHost* host, BufferedDataSourceHost* host,
const DownloadingCB& downloading_cb) const DownloadingCB& downloading_cb)
: cors_mode_(BufferedResourceLoader::kUnspecified), : url_(url),
cors_mode_(cors_mode),
total_bytes_(kPositionNotSpecified), total_bytes_(kPositionNotSpecified),
assume_fully_buffered_(false),
streaming_(false), streaming_(false),
frame_(frame), frame_(frame),
intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), intermediate_read_buffer_(new uint8[kInitialReadBufferSize]),
...@@ -128,19 +130,14 @@ BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( ...@@ -128,19 +130,14 @@ BufferedResourceLoader* BufferedDataSource::CreateResourceLoader(
media_log_.get()); media_log_.get());
} }
void BufferedDataSource::Initialize( void BufferedDataSource::Initialize(const InitializeCB& init_cb) {
const GURL& url,
BufferedResourceLoader::CORSMode cors_mode,
const InitializeCB& init_cb) {
DCHECK(render_loop_->BelongsToCurrentThread()); DCHECK(render_loop_->BelongsToCurrentThread());
DCHECK(!init_cb.is_null()); DCHECK(!init_cb.is_null());
DCHECK(!loader_.get()); DCHECK(!loader_.get());
url_ = url;
cors_mode_ = cors_mode;
init_cb_ = init_cb; init_cb_ = init_cb;
if (url_.SchemeIs(url::kHttpScheme) || url_.SchemeIs(url::kHttpsScheme)) { if (url_.SchemeIsHTTPOrHTTPS()) {
// Do an unbounded range request starting at the beginning. If the server // 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. // responds with 200 instead of 206 we'll fall back into a streaming mode.
loader_.reset(CreateResourceLoader(0, kPositionNotSpecified)); loader_.reset(CreateResourceLoader(0, kPositionNotSpecified));
...@@ -150,7 +147,6 @@ void BufferedDataSource::Initialize( ...@@ -150,7 +147,6 @@ void BufferedDataSource::Initialize(
// we won't be served HTTP headers. // we won't be served HTTP headers.
loader_.reset(CreateResourceLoader(kPositionNotSpecified, loader_.reset(CreateResourceLoader(kPositionNotSpecified,
kPositionNotSpecified)); kPositionNotSpecified));
assume_fully_buffered_ = true;
} }
base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr(); base::WeakPtr<BufferedDataSource> weak_this = weak_factory_.GetWeakPtr();
...@@ -353,12 +349,13 @@ void BufferedDataSource::StartCallback( ...@@ -353,12 +349,13 @@ void BufferedDataSource::StartCallback(
// All responses must be successful. Resources that are assumed to be fully // All responses must be successful. Resources that are assumed to be fully
// buffered must have a known content length. // buffered must have a known content length.
bool success = status == BufferedResourceLoader::kOk && bool success = status == BufferedResourceLoader::kOk &&
(!assume_fully_buffered_ || (!assume_fully_buffered() ||
loader_->instance_size() != kPositionNotSpecified); loader_->instance_size() != kPositionNotSpecified);
if (success) { if (success) {
total_bytes_ = loader_->instance_size(); total_bytes_ = loader_->instance_size();
streaming_ = !assume_fully_buffered_ && streaming_ =
!assume_fully_buffered() &&
(total_bytes_ == kPositionNotSpecified || !loader_->range_supported()); (total_bytes_ == kPositionNotSpecified || !loader_->range_supported());
media_log_->SetDoubleProperty("total_bytes", media_log_->SetDoubleProperty("total_bytes",
...@@ -377,7 +374,7 @@ void BufferedDataSource::StartCallback( ...@@ -377,7 +374,7 @@ void BufferedDataSource::StartCallback(
if (success) { if (success) {
if (total_bytes_ != kPositionNotSpecified) { if (total_bytes_ != kPositionNotSpecified) {
host_->SetTotalBytes(total_bytes_); host_->SetTotalBytes(total_bytes_);
if (assume_fully_buffered_) if (assume_fully_buffered())
host_->AddBufferedByteRange(0, total_bytes_); host_->AddBufferedByteRange(0, total_bytes_);
} }
...@@ -473,7 +470,7 @@ void BufferedDataSource::LoadingStateChangedCallback( ...@@ -473,7 +470,7 @@ void BufferedDataSource::LoadingStateChangedCallback(
BufferedResourceLoader::LoadingState state) { BufferedResourceLoader::LoadingState state) {
DCHECK(render_loop_->BelongsToCurrentThread()); DCHECK(render_loop_->BelongsToCurrentThread());
if (assume_fully_buffered_) if (assume_fully_buffered())
return; return;
bool is_downloading_data; bool is_downloading_data;
...@@ -501,7 +498,7 @@ void BufferedDataSource::LoadingStateChangedCallback( ...@@ -501,7 +498,7 @@ void BufferedDataSource::LoadingStateChangedCallback(
void BufferedDataSource::ProgressCallback(int64 position) { void BufferedDataSource::ProgressCallback(int64 position) {
DCHECK(render_loop_->BelongsToCurrentThread()); DCHECK(render_loop_->BelongsToCurrentThread());
if (assume_fully_buffered_) if (assume_fully_buffered())
return; return;
// TODO(scherkus): we shouldn't have to lock to signal host(), see // TODO(scherkus): we shouldn't have to lock to signal host(), see
......
...@@ -50,24 +50,23 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource { ...@@ -50,24 +50,23 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource {
public: public:
typedef base::Callback<void(bool)> DownloadingCB; typedef base::Callback<void(bool)> DownloadingCB;
// Buffered byte range changes will be reported to |host|. |downloading_cb| // |url| and |cors_mode| are passed to the object. Buffered byte range changes
// will be called whenever the downloading/paused state of the source changes. // will be reported to |host|. |downloading_cb| will be called whenever the
BufferedDataSource(const scoped_refptr<base::MessageLoopProxy>& render_loop, // downloading/paused state of the source changes.
BufferedDataSource(const GURL& url,
BufferedResourceLoader::CORSMode cors_mode,
const scoped_refptr<base::MessageLoopProxy>& render_loop,
blink::WebFrame* frame, blink::WebFrame* frame,
media::MediaLog* media_log, media::MediaLog* media_log,
BufferedDataSourceHost* host, BufferedDataSourceHost* host,
const DownloadingCB& downloading_cb); const DownloadingCB& downloading_cb);
virtual ~BufferedDataSource(); virtual ~BufferedDataSource();
// Initialize this object using |url| and |cors_mode|, executing |init_cb| // Executes |init_cb| with the result of initialization when it has completed.
// with the result of initialization when it has completed.
// //
// Method called on the render thread. // Method called on the render thread.
typedef base::Callback<void(bool)> InitializeCB; typedef base::Callback<void(bool)> InitializeCB;
void Initialize( void Initialize(const InitializeCB& init_cb);
const GURL& url,
BufferedResourceLoader::CORSMode cors_mode,
const InitializeCB& init_cb);
// Adjusts the buffering algorithm based on the given preload value. // Adjusts the buffering algorithm based on the given preload value.
void SetPreload(Preload preload); void SetPreload(Preload preload);
...@@ -94,6 +93,9 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource { ...@@ -94,6 +93,9 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource {
void MediaIsPlaying(); void MediaIsPlaying();
void MediaIsPaused(); void MediaIsPaused();
// Returns true if the resource is local.
bool assume_fully_buffered() { return !url_.SchemeIsHTTPOrHTTPS(); }
// media::DataSource implementation. // media::DataSource implementation.
// Called from demuxer thread. // Called from demuxer thread.
virtual void Stop(const base::Closure& closure) OVERRIDE; virtual void Stop(const base::Closure& closure) OVERRIDE;
...@@ -157,10 +159,6 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource { ...@@ -157,10 +159,6 @@ class CONTENT_EXPORT BufferedDataSource : public media::DataSource {
// determined by reaching EOF. // determined by reaching EOF.
int64 total_bytes_; int64 total_bytes_;
// Some resources are assumed to be fully buffered (i.e., file://) so we don't
// need to report what |loader_| has buffered.
bool assume_fully_buffered_;
// This value will be true if this data source can only support streaming. // This value will be true if this data source can only support streaming.
// i.e. range request is not supported. // i.e. range request is not supported.
bool streaming_; bool streaming_;
......
...@@ -48,15 +48,20 @@ class MockBufferedDataSourceHost : public BufferedDataSourceHost { ...@@ -48,15 +48,20 @@ class MockBufferedDataSourceHost : public BufferedDataSourceHost {
class MockBufferedDataSource : public BufferedDataSource { class MockBufferedDataSource : public BufferedDataSource {
public: public:
MockBufferedDataSource( MockBufferedDataSource(
const GURL& url,
const scoped_refptr<base::MessageLoopProxy>& message_loop, const scoped_refptr<base::MessageLoopProxy>& message_loop,
WebLocalFrame* frame, WebLocalFrame* frame,
BufferedDataSourceHost* host) BufferedDataSourceHost* host)
: BufferedDataSource(message_loop, frame, new media::MediaLog(), host, : BufferedDataSource(url,
BufferedResourceLoader::kUnspecified,
message_loop,
frame,
new media::MediaLog(),
host,
base::Bind(&MockBufferedDataSource::set_downloading, base::Bind(&MockBufferedDataSource::set_downloading,
base::Unretained(this))), base::Unretained(this))),
downloading_(false), downloading_(false),
loading_(false) { loading_(false) {}
}
virtual ~MockBufferedDataSource() {} virtual ~MockBufferedDataSource() {}
MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64));
...@@ -107,11 +112,6 @@ class BufferedDataSourceTest : public testing::Test { ...@@ -107,11 +112,6 @@ class BufferedDataSourceTest : public testing::Test {
BufferedDataSourceTest() BufferedDataSourceTest()
: view_(WebView::create(NULL)), frame_(WebLocalFrame::create(&client_)) { : view_(WebView::create(NULL)), frame_(WebLocalFrame::create(&client_)) {
view_->setMainFrame(frame_); view_->setMainFrame(frame_);
data_source_.reset(
new MockBufferedDataSource(message_loop_.message_loop_proxy(),
view_->mainFrame()->toWebLocalFrame(),
&host_));
} }
virtual ~BufferedDataSourceTest() { virtual ~BufferedDataSourceTest() {
...@@ -123,17 +123,20 @@ class BufferedDataSourceTest : public testing::Test { ...@@ -123,17 +123,20 @@ class BufferedDataSourceTest : public testing::Test {
void Initialize(const char* url, bool expected) { void Initialize(const char* url, bool expected) {
GURL gurl(url); GURL gurl(url);
response_generator_.reset(new TestResponseGenerator(gurl, kFileSize)); data_source_.reset(
new MockBufferedDataSource(gurl,
message_loop_.message_loop_proxy(),
view_->mainFrame()->toWebLocalFrame(),
&host_));
response_generator_.reset(new TestResponseGenerator(gurl, kFileSize));
ExpectCreateResourceLoader(); ExpectCreateResourceLoader();
EXPECT_CALL(*this, OnInitialize(expected)); EXPECT_CALL(*this, OnInitialize(expected));
data_source_->Initialize( data_source_->Initialize(base::Bind(&BufferedDataSourceTest::OnInitialize,
gurl, BufferedResourceLoader::kUnspecified, base::Bind( base::Unretained(this)));
&BufferedDataSourceTest::OnInitialize, base::Unretained(this)));
message_loop_.RunUntilIdle(); message_loop_.RunUntilIdle();
bool is_http = bool is_http = gurl.SchemeIsHTTPOrHTTPS();
gurl.SchemeIs(url::kHttpScheme) || gurl.SchemeIs(url::kHttpsScheme);
EXPECT_EQ(data_source_->downloading(), is_http); EXPECT_EQ(data_source_->downloading(), is_http);
} }
......
...@@ -167,7 +167,6 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( ...@@ -167,7 +167,6 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
accelerated_compositing_reported_(false), accelerated_compositing_reported_(false),
incremented_externally_allocated_memory_(false), incremented_externally_allocated_memory_(false),
gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()), gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()),
is_local_source_(false),
supports_save_(true), supports_save_(true),
starting_(false), starting_(false),
chunk_demuxer_(NULL), chunk_demuxer_(NULL),
...@@ -318,18 +317,15 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type, ...@@ -318,18 +317,15 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type,
// Otherwise it's a regular request which requires resolving the URL first. // Otherwise it's a regular request which requires resolving the URL first.
data_source_.reset(new BufferedDataSource( data_source_.reset(new BufferedDataSource(
url,
static_cast<BufferedResourceLoader::CORSMode>(cors_mode),
main_loop_, main_loop_,
frame_, frame_,
media_log_.get(), media_log_.get(),
&buffered_data_source_host_, &buffered_data_source_host_,
base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr())));
data_source_->Initialize( data_source_->Initialize(
url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr()));
base::Bind(
&WebMediaPlayerImpl::DataSourceInitialized,
AsWeakPtr(), gurl));
is_local_source_ = !gurl.SchemeIsHTTPOrHTTPS();
} }
void WebMediaPlayerImpl::play() { void WebMediaPlayerImpl::play() {
...@@ -1112,7 +1108,7 @@ void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id, ...@@ -1112,7 +1108,7 @@ void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id,
destination_url); destination_url);
} }
void WebMediaPlayerImpl::DataSourceInitialized(const GURL& gurl, bool success) { void WebMediaPlayerImpl::DataSourceInitialized(bool success) {
DCHECK(main_loop_->BelongsToCurrentThread()); DCHECK(main_loop_->BelongsToCurrentThread());
if (!success) { if (!success) {
...@@ -1248,8 +1244,8 @@ void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { ...@@ -1248,8 +1244,8 @@ void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) {
DCHECK(main_loop_->BelongsToCurrentThread()); DCHECK(main_loop_->BelongsToCurrentThread());
DVLOG(1) << "SetReadyState: " << state; DVLOG(1) << "SetReadyState: " << state;
if (state == WebMediaPlayer::ReadyStateHaveEnoughData && if (state == WebMediaPlayer::ReadyStateHaveEnoughData && data_source_ &&
is_local_source_ && data_source_->assume_fully_buffered() &&
network_state_ == WebMediaPlayer::NetworkStateLoading) network_state_ == WebMediaPlayer::NetworkStateLoading)
SetNetworkState(WebMediaPlayer::NetworkStateLoaded); SetNetworkState(WebMediaPlayer::NetworkStateLoaded);
......
...@@ -191,7 +191,7 @@ class WebMediaPlayerImpl ...@@ -191,7 +191,7 @@ class WebMediaPlayerImpl
CORSMode cors_mode); CORSMode cors_mode);
// Called after asynchronous initialization of a data source completed. // Called after asynchronous initialization of a data source completed.
void DataSourceInitialized(const GURL& gurl, bool success); void DataSourceInitialized(bool success);
// Called when the data source is downloading or paused. // Called when the data source is downloading or paused.
void NotifyDownloading(bool is_downloading); void NotifyDownloading(bool is_downloading);
...@@ -310,7 +310,6 @@ class WebMediaPlayerImpl ...@@ -310,7 +310,6 @@ class WebMediaPlayerImpl
// Routes audio playback to either AudioRendererSink or WebAudio. // Routes audio playback to either AudioRendererSink or WebAudio.
scoped_refptr<WebAudioSourceProviderImpl> audio_source_provider_; scoped_refptr<WebAudioSourceProviderImpl> audio_source_provider_;
bool is_local_source_;
bool supports_save_; bool supports_save_;
bool starting_; bool starting_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment