Chromium Code Reviews| Index: content/renderer/media/android/stream_texture_factory_impl.cc |
| diff --git a/content/renderer/media/android/stream_texture_factory_impl.cc b/content/renderer/media/android/stream_texture_factory_impl.cc |
| index da9a70f4ba732222b0af8b9adad6228310af8d78..6190d940a85c1643466b5b283b630e8d70e6e83b 100644 |
| --- a/content/renderer/media/android/stream_texture_factory_impl.cc |
| +++ b/content/renderer/media/android/stream_texture_factory_impl.cc |
| @@ -22,8 +22,9 @@ class StreamTextureProxyImpl : public StreamTextureProxy, |
| virtual ~StreamTextureProxyImpl(); |
| // StreamTextureProxy implementation: |
| - virtual void BindToCurrentThread(int32 stream_id) OVERRIDE; |
| - virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; |
| + virtual void BindToLoop(int32 stream_id, |
| + cc::VideoFrameProvider::Client* client, |
| + scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE; |
| virtual void Release() OVERRIDE; |
| // StreamTextureHost::Listener implementation: |
| @@ -31,7 +32,12 @@ class StreamTextureProxyImpl : public StreamTextureProxy, |
| virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
| private: |
| - scoped_ptr<StreamTextureHost> host_; |
| + void SetClient(cc::VideoFrameProvider::Client* client); |
| + void BindOnThread(int32 stream_id, |
| + cc::VideoFrameProvider::Client* client, |
| + scoped_refptr<base::MessageLoopProxy> loop); |
| + |
| + const scoped_ptr<StreamTextureHost> host_; |
| scoped_refptr<base::MessageLoopProxy> loop_; |
| base::Lock client_lock_; |
| @@ -46,11 +52,13 @@ StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
| StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
| void StreamTextureProxyImpl::Release() { |
| + // Assumes this is the last reference to this object. So no need to acquire |
| + // lock. |
| SetClient(NULL); |
| - if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) |
| - loop_->DeleteSoon(FROM_HERE, this); |
| - else |
| + if (!loop_.get() || loop_->BelongsToCurrentThread() || |
| + !loop_->DeleteSoon(FROM_HERE, this)) { |
| delete this; |
| + } |
| } |
| void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
| @@ -58,8 +66,30 @@ void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
| client_ = client; |
| } |
| -void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { |
| - loop_ = base::MessageLoopProxy::current(); |
| +void StreamTextureProxyImpl::BindToLoop( |
| + int32 stream_id, |
| + cc::VideoFrameProvider::Client* client, |
| + scoped_refptr<base::MessageLoopProxy> loop) { |
| + if (loop->BelongsToCurrentThread()) { |
| + BindOnThread(stream_id, client, loop); |
| + return; |
| + } |
| + // Unretained is safe here only because the object is deleted on |loop_| |
| + // thread. |
| + loop->PostTask(FROM_HERE, |
| + base::Bind(&StreamTextureProxyImpl::BindOnThread, |
| + base::Unretained(this), |
| + stream_id, |
| + client, |
| + loop)); |
| +} |
| + |
| +void StreamTextureProxyImpl::BindOnThread( |
| + int32 stream_id, |
| + cc::VideoFrameProvider::Client* client, |
| + scoped_refptr<base::MessageLoopProxy> loop) { |
|
no sievers
2014/09/15 19:00:39
DCHECK(!client || (client && loop));
DCHECK(!loop_
boliu
2014/09/15 20:41:53
Actually easier to just DCHECK(loop) in this case
|
| + loop_ = loop; |
| + SetClient(client); |
|
no sievers
2014/09/15 19:00:40
move this to BindToLoop()
boliu
2014/09/15 20:41:53
Done.
|
| host_->BindToCurrentThread(stream_id, this); |
| } |
| @@ -134,4 +164,12 @@ gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { |
| return context_provider_->ContextGL(); |
| } |
| +void StreamTextureFactoryImpl::AddObserver( |
| + StreamTextureFactoryContextObserver* obs) { |
| +} |
| + |
| +void StreamTextureFactoryImpl::RemoveObserver( |
| + StreamTextureFactoryContextObserver* obs) { |
| +} |
| + |
| } // namespace content |