Commit 3717d9ae authored by tguilbert's avatar tguilbert Committed by Commit bot

Fix OnChannelError() in StreamTextureHost

StreamTextureHost is always created with a valid |route_id|, and it also
does not handle OnChannelError().

This change removes the useless |route_id| checks, sets |channel_| to
nullptr when OnChannelError() is called, and adds appropriate |channel_|
null checks.

This change also removes raw pointers from StreamTextureProxy, to fix
style conformance and StreamTextureHost ownership clearer.

BUG=667162

Review-Url: https://codereview.chromium.org/2530443002
Cr-Commit-Position: refs/heads/master@{#434715}
parent 0d4f64f5
......@@ -15,20 +15,22 @@ namespace content {
StreamTextureHost::StreamTextureHost(scoped_refptr<gpu::GpuChannelHost> channel,
int32_t route_id)
: route_id_(route_id),
listener_(NULL),
listener_(nullptr),
channel_(std::move(channel)),
weak_ptr_factory_(this) {
DCHECK(channel_);
DCHECK(route_id_);
}
StreamTextureHost::~StreamTextureHost() {
if (channel_.get() && route_id_)
if (channel_)
channel_->RemoveRoute(route_id_);
}
bool StreamTextureHost::BindToCurrentThread(Listener* listener) {
listener_ = listener;
if (channel_.get() && route_id_) {
if (channel_) {
channel_->AddRoute(route_id_, weak_ptr_factory_.GetWeakPtr());
channel_->Send(new GpuStreamTextureMsg_StartListening(route_id_));
return true;
......@@ -40,8 +42,7 @@ bool StreamTextureHost::BindToCurrentThread(Listener* listener) {
bool StreamTextureHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(StreamTextureHost, message)
IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_FrameAvailable,
OnFrameAvailable);
IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_FrameAvailable, OnFrameAvailable);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
DCHECK(handled);
......@@ -49,6 +50,7 @@ bool StreamTextureHost::OnMessageReceived(const IPC::Message& message) {
}
void StreamTextureHost::OnChannelError() {
channel_ = nullptr;
}
void StreamTextureHost::OnFrameAvailable() {
......@@ -57,20 +59,20 @@ void StreamTextureHost::OnFrameAvailable() {
}
void StreamTextureHost::EstablishPeer(int player_id, int frame_id) {
if (route_id_) {
if (channel_) {
channel_->Send(
new GpuStreamTextureMsg_EstablishPeer(route_id_, frame_id, player_id));
}
}
void StreamTextureHost::SetStreamTextureSize(const gfx::Size& size) {
if (route_id_)
if (channel_)
channel_->Send(new GpuStreamTextureMsg_SetSize(route_id_, size));
}
void StreamTextureHost::ForwardStreamTextureForSurfaceRequest(
const base::UnguessableToken& request_token) {
if (route_id_) {
if (channel_) {
channel_->Send(new GpuStreamTextureMsg_ForwardForSurfaceRequest(
route_id_, request_token));
}
......
......@@ -5,6 +5,7 @@
#include "content/renderer/media/android/stream_texture_factory.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "cc/output/context_provider.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "gpu/command_buffer/client/gles2_interface.h"
......@@ -15,7 +16,8 @@
namespace content {
StreamTextureProxy::StreamTextureProxy(StreamTextureHost* host) : host_(host) {}
StreamTextureProxy::StreamTextureProxy(std::unique_ptr<StreamTextureHost> host)
: host_(std::move(host)) {}
StreamTextureProxy::~StreamTextureProxy() {}
......@@ -94,16 +96,16 @@ StreamTextureFactory::StreamTextureFactory(
StreamTextureFactory::~StreamTextureFactory() {}
StreamTextureProxy* StreamTextureFactory::CreateProxy(
ScopedStreamTextureProxy StreamTextureFactory::CreateProxy(
unsigned texture_target,
unsigned* texture_id,
gpu::Mailbox* texture_mailbox) {
int32_t route_id =
CreateStreamTexture(texture_target, texture_id, texture_mailbox);
if (!route_id)
return nullptr;
StreamTextureHost* host = new StreamTextureHost(channel_, route_id);
return new StreamTextureProxy(host);
return ScopedStreamTextureProxy();
return ScopedStreamTextureProxy(new StreamTextureProxy(
base::MakeUnique<StreamTextureHost>(channel_, route_id)));
}
unsigned StreamTextureFactory::CreateStreamTexture(
......
......@@ -67,7 +67,7 @@ class StreamTextureProxy : public StreamTextureHost::Listener {
};
private:
friend class StreamTextureFactory;
explicit StreamTextureProxy(StreamTextureHost* host);
explicit StreamTextureProxy(std::unique_ptr<StreamTextureHost> host);
void BindOnThread();
void Release();
......@@ -100,9 +100,9 @@ class CONTENT_EXPORT StreamTextureFactory
// nullptr is returned and *texture_id will be set to 0. If the route_id is
// valid it returns StreamTextureProxy object. The caller needs to take care
// of cleaning up the texture_id.
StreamTextureProxy* CreateProxy(unsigned texture_target,
unsigned* texture_id,
gpu::Mailbox* texture_mailbox);
ScopedStreamTextureProxy CreateProxy(unsigned texture_target,
unsigned* texture_id,
gpu::Mailbox* texture_mailbox);
gpu::gles2::GLES2Interface* ContextGL();
......
......@@ -160,8 +160,8 @@ void StreamTextureWrapperImpl::InitializeOnMainThread(
DCHECK(main_task_runner_->BelongsToCurrentThread());
DVLOG(2) << __FUNCTION__;
stream_texture_proxy_.reset(factory_->CreateProxy(
kGLTextureExternalOES, &texture_id_, &texture_mailbox_));
stream_texture_proxy_ = factory_->CreateProxy(
kGLTextureExternalOES, &texture_id_, &texture_mailbox_);
if (!stream_texture_proxy_)
return;
......
......@@ -1148,8 +1148,8 @@ void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() {
return;
DCHECK(!texture_id_);
stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy(
kGLTextureExternalOES, &texture_id_, &texture_mailbox_));
stream_texture_proxy_ = stream_texture_factory_->CreateProxy(
kGLTextureExternalOES, &texture_id_, &texture_mailbox_);
if (!stream_texture_proxy_)
return;
ReallocateVideoFrame();
......
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