summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 19:29:39 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 19:29:39 +0000
commit70ab61c9109f3626b44f2bee96de626d0acf8442 (patch)
treea576bc8931b3520805246c4b14497416b21cd46d /chrome/renderer
parent682f714c3a4864858ff3eabf1f80d4c6fca71647 (diff)
downloadchromium_src-70ab61c9109f3626b44f2bee96de626d0acf8442.zip
chromium_src-70ab61c9109f3626b44f2bee96de626d0acf8442.tar.gz
chromium_src-70ab61c9109f3626b44f2bee96de626d0acf8442.tar.bz2
Access RenderThread::current() only on render thread
Since the renfer to RenderThread is now stored in the thread local storage, we can only access RenderThread::current() from render thread. Change BufferedDataSource accordingly. Review URL: http://codereview.chromium.org/126183 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18513 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/media/buffered_data_source.cc98
-rw-r--r--chrome/renderer/media/buffered_data_source.h25
-rw-r--r--chrome/renderer/render_view.cc4
3 files changed, 80 insertions, 47 deletions
diff --git a/chrome/renderer/media/buffered_data_source.cc b/chrome/renderer/media/buffered_data_source.cc
index 2a4f698..f0aa456 100644
--- a/chrome/renderer/media/buffered_data_source.cc
+++ b/chrome/renderer/media/buffered_data_source.cc
@@ -10,7 +10,6 @@
#include "chrome/common/extensions/url_pattern.h"
#include "chrome/renderer/media/buffered_data_source.h"
#include "chrome/renderer/render_view.h"
-#include "chrome/renderer/render_thread.h"
#include "media/base/filter_host.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
@@ -63,7 +62,8 @@ bool IsSchemeSupported(const GURL& url) {
/////////////////////////////////////////////////////////////////////////////
// BufferedResourceLoader
-BufferedResourceLoader::BufferedResourceLoader(int32 routing_id,
+BufferedResourceLoader::BufferedResourceLoader(MessageLoop* message_loop,
+ int32 routing_id,
const GURL& url,
int64 first_byte_position,
int64 last_byte_position)
@@ -82,7 +82,7 @@ BufferedResourceLoader::BufferedResourceLoader(int32 routing_id,
url_(url),
first_byte_position_(first_byte_position),
last_byte_position_(last_byte_position),
- render_loop_(RenderThread::current()->message_loop()),
+ render_loop_(message_loop),
buffer_available_(&lock_) {
}
@@ -102,40 +102,6 @@ int BufferedResourceLoader::Start(net::CompletionCallback* start_callback) {
if (start_callback_.get())
async_start_ = true;
- std::string header;
- if (first_byte_position_ != kPositionNotSpecified &&
- last_byte_position_ != kPositionNotSpecified) {
- header = StringPrintf("Range: bytes=%lld-%lld",
- first_byte_position_,
- last_byte_position_);
- range_requested_ = true;
- offset_ = first_byte_position_;
- } else if (first_byte_position_ != kPositionNotSpecified) {
- header = StringPrintf("Range: bytes=%lld-", first_byte_position_);
- range_requested_ = true;
- offset_ = first_byte_position_;
- } else if (last_byte_position_ != kPositionNotSpecified) {
- NOTIMPLEMENTED() << "Suffix length range request not implemented.";
- }
-
- bridge_.reset(RenderThread::current()->resource_dispatcher()->CreateBridge(
- "GET",
- GURL(url_),
- GURL(url_),
- GURL(), // TODO(hclam): provide referer here.
- "null", // TODO(abarth): provide frame_origin
- "null", // TODO(abarth): provide main_frame_origin
- header,
- net::LOAD_BYPASS_CACHE,
- base::GetCurrentProcId(),
- ResourceType::MEDIA,
- 0,
- // TODO(michaeln): delegate->mediaplayer->frame->
- // app_cache_context()->context_id()
- // For now don't service media resource requests from the appcache.
- WebAppCacheContext::kNoAppCacheContextId,
- routing_id_));
-
// We may receive stop signal while we are inside this method, it's because
// Start() may get called on demuxer thread while Stop() is called on
// pipeline thread.
@@ -478,7 +444,49 @@ bool BufferedResourceLoader::ShouldDisableDefer() {
void BufferedResourceLoader::OnStart() {
DCHECK(MessageLoop::current() == render_loop_);
- DCHECK(bridge_.get());
+ DCHECK(!bridge_.get());
+
+ AutoLock auto_lock(lock_);
+ if (stopped_)
+ return;
+
+ // Construct the range header.
+ std::string header;
+ if (first_byte_position_ != kPositionNotSpecified &&
+ last_byte_position_ != kPositionNotSpecified) {
+ header = StringPrintf("Range: bytes=%lld-%lld",
+ first_byte_position_,
+ last_byte_position_);
+ range_requested_ = true;
+ offset_ = first_byte_position_;
+ } else if (first_byte_position_ != kPositionNotSpecified) {
+ header = StringPrintf("Range: bytes=%lld-", first_byte_position_);
+ range_requested_ = true;
+ offset_ = first_byte_position_;
+ } else if (last_byte_position_ != kPositionNotSpecified) {
+ NOTIMPLEMENTED() << "Suffix length range request not implemented.";
+ }
+
+ // Creates the bridge on render thread since we can only access
+ // ResourceDispatcher on this thread.
+ bridge_.reset(webkit_glue::ResourceLoaderBridge::Create(
+ "GET",
+ GURL(url_),
+ GURL(url_),
+ GURL(), // TODO(hclam): provide referer here.
+ "null", // TODO(abarth): provide frame_origin
+ "null", // TODO(abarth): provide main_frame_origin
+ header,
+ net::LOAD_BYPASS_CACHE,
+ base::GetCurrentProcId(),
+ ResourceType::MEDIA,
+ // TODO(michaeln): delegate->mediaplayer->frame->
+ // app_cache_context()->context_id()
+ // For now don't service media resource requests from the appcache.
+ WebAppCacheContext::kNoAppCacheContextId,
+ routing_id_));
+
+ // And start the resource loading.
bridge_->Start(this);
}
@@ -515,12 +523,13 @@ void BufferedResourceLoader::InvokeAndResetStartCallback(int error) {
//////////////////////////////////////////////////////////////////////////////
// BufferedDataSource
-BufferedDataSource::BufferedDataSource(int routing_id)
+BufferedDataSource::BufferedDataSource(MessageLoop* render_loop, int routing_id)
: routing_id_(routing_id),
stopped_(false),
position_(0),
total_bytes_(kPositionNotSpecified),
buffered_resource_loader_(NULL),
+ render_loop_(render_loop),
pipeline_loop_(MessageLoop::current()) {
}
@@ -562,7 +571,11 @@ bool BufferedDataSource::Initialize(const std::string& url) {
AutoLock auto_lock(lock_);
if (!stopped_) {
buffered_resource_loader_ = new BufferedResourceLoader(
- routing_id_, url_, kPositionNotSpecified, kPositionNotSpecified);
+ render_loop_,
+ routing_id_,
+ url_,
+ kPositionNotSpecified,
+ kPositionNotSpecified);
resource_loader = buffered_resource_loader_;
}
}
@@ -622,7 +635,10 @@ size_t BufferedDataSource::Read(uint8* data, size_t size) {
// Create a new resource loader.
buffered_resource_loader_ =
- new BufferedResourceLoader(routing_id_, url_, position_,
+ new BufferedResourceLoader(render_loop_,
+ routing_id_,
+ url_,
+ position_,
kPositionNotSpecified);
// Save the local copy.
resource_loader = buffered_resource_loader_;
diff --git a/chrome/renderer/media/buffered_data_source.h b/chrome/renderer/media/buffered_data_source.h
index b5a0d91..0111629 100644
--- a/chrome/renderer/media/buffered_data_source.h
+++ b/chrome/renderer/media/buffered_data_source.h
@@ -30,7 +30,14 @@ class BufferedResourceLoader :
public base::RefCountedThreadSafe<BufferedResourceLoader>,
public webkit_glue::ResourceLoaderBridge::Peer {
public:
- BufferedResourceLoader(int32 routing_id,
+ // |message_loop| - The message loop this resource loader should run on.
+ // |routing_id| - Routing id to this view.
+ // |url| - URL for the resource to be loaded.
+ // |first_byte_position| - First byte to start loading from, -1 for not
+ // specified.
+ // |last_byte_position| - Last byte to be loaded, -1 for not specified.
+ BufferedResourceLoader(MessageLoop* message_loop,
+ int32 routing_id,
const GURL& url,
int64 first_byte_position,
int64 last_byte_position);
@@ -187,8 +194,11 @@ class BufferedDataSource : public media::DataSource {
public:
// Methods called from pipeline thread
// Static methods for creating this class.
- static media::FilterFactory* CreateFactory(int32 routing_id) {
- return new media::FilterFactoryImpl1<BufferedDataSource, int32>(routing_id);
+ static media::FilterFactory* CreateFactory(MessageLoop* message_loop,
+ int32 routing_id) {
+ return new media::FilterFactoryImpl2<BufferedDataSource,
+ MessageLoop*,
+ int32>(message_loop, routing_id);
}
virtual bool Initialize(const std::string& url);
@@ -206,7 +216,9 @@ class BufferedDataSource : public media::DataSource {
const media::MediaFormat& media_format();
private:
- friend class media::FilterFactoryImpl1<BufferedDataSource, int32>;
+ friend class media::FilterFactoryImpl2<BufferedDataSource,
+ MessageLoop*,
+ int32>;
// Call to filter host to trigger an error, be sure not to call this method
// while the lock is acquired.
void HandleError(media::PipelineError error);
@@ -217,7 +229,7 @@ class BufferedDataSource : public media::DataSource {
void InitialRequestStarted(int error);
void OnInitialRequestStarted(int error);
- explicit BufferedDataSource(int32 routing_id);
+ explicit BufferedDataSource(MessageLoop* render_loop, int32 routing_id);
virtual ~BufferedDataSource();
media::MediaFormat media_format_;
@@ -237,6 +249,9 @@ class BufferedDataSource : public media::DataSource {
// Members related to resource loading with RenderView.
scoped_refptr<BufferedResourceLoader> buffered_resource_loader_;
+ // The message loop of the render thread.
+ MessageLoop* render_loop_;
+
// The message loop of the pipeline thread.
MessageLoop* pipeline_loop_;
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index b99dc95..7c2bbf1 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1816,7 +1816,9 @@ WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer(
}
if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) {
// Add the chrome specific media data source.
- factory->AddFactory(BufferedDataSource::CreateFactory(routing_id()));
+ factory->AddFactory(
+ BufferedDataSource::CreateFactory(MessageLoop::current(),
+ routing_id()));
}
return new webkit_glue::WebMediaPlayerImpl(client, factory);
}