diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-28 06:36:15 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-28 06:36:15 +0000 |
commit | 69d5c51f4e36b7de5e89a2eab2d1fd179e4f4a27 (patch) | |
tree | 26e7e6c146725e92e66e1226a727add18fa563bc /content | |
parent | 355b853894c91bc1822d0737d55a5883d865d839 (diff) | |
download | chromium_src-69d5c51f4e36b7de5e89a2eab2d1fd179e4f4a27.zip chromium_src-69d5c51f4e36b7de5e89a2eab2d1fd179e4f4a27.tar.gz chromium_src-69d5c51f4e36b7de5e89a2eab2d1fd179e4f4a27.tar.bz2 |
RefCounted types should not have public destructors, content/browser part 2
BUG=123295
TEST=none
TBR=brettw
Review URL: https://chromiumcodereview.appspot.com/10071038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134446 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
49 files changed, 824 insertions, 779 deletions
diff --git a/content/common/child_trace_message_filter.cc b/content/common/child_trace_message_filter.cc index cac19ea..adc5426 100644 --- a/content/common/child_trace_message_filter.cc +++ b/content/common/child_trace_message_filter.cc @@ -11,11 +11,7 @@ #include "content/common/child_process_messages.h" -ChildTraceMessageFilter::ChildTraceMessageFilter() : channel_(NULL) { -} - -ChildTraceMessageFilter::~ChildTraceMessageFilter() { -} +ChildTraceMessageFilter::ChildTraceMessageFilter() : channel_(NULL) {} void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) { channel_ = channel; @@ -45,6 +41,8 @@ bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { return handled; } +ChildTraceMessageFilter::~ChildTraceMessageFilter() {} + void ChildTraceMessageFilter::OnBeginTracing( const std::vector<std::string>& included_categories, const std::vector<std::string>& excluded_categories) { diff --git a/content/common/child_trace_message_filter.h b/content/common/child_trace_message_filter.h index 51f7bd3..d913d6a 100644 --- a/content/common/child_trace_message_filter.h +++ b/content/common/child_trace_message_filter.h @@ -15,13 +15,15 @@ class ChildTraceMessageFilter : public IPC::ChannelProxy::MessageFilter { public: ChildTraceMessageFilter(); - virtual ~ChildTraceMessageFilter(); // IPC::ChannelProxy::MessageFilter implementation. virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; virtual void OnFilterRemoved() OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + protected: + virtual ~ChildTraceMessageFilter(); + private: // Message handlers. void OnBeginTracing(const std::vector<std::string>& included_categories, diff --git a/content/common/db_message_filter.h b/content/common/db_message_filter.h index 29d45d0..c77ee22 100644 --- a/content/common/db_message_filter.h +++ b/content/common/db_message_filter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,9 +14,13 @@ class DBMessageFilter : public IPC::ChannelProxy::MessageFilter { public: DBMessageFilter(); - private: + // IPC::ChannelProxy::MessageFilter virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + protected: + virtual ~DBMessageFilter() {} + + private: void OnDatabaseUpdateSize(const string16& origin_identifier, const string16& database_name, int64 database_size); diff --git a/content/common/gpu/client/gpu_channel_host.cc b/content/common/gpu/client/gpu_channel_host.cc index 2446101..19a87df 100644 --- a/content/common/gpu/client/gpu_channel_host.cc +++ b/content/common/gpu/client/gpu_channel_host.cc @@ -16,82 +16,9 @@ using base::AutoLock; using base::MessageLoopProxy; -GpuListenerInfo::GpuListenerInfo() { -} - -GpuListenerInfo::~GpuListenerInfo() { -} - -GpuChannelHost::MessageFilter::MessageFilter(GpuChannelHost* parent) - : parent_(parent) { -} - -GpuChannelHost::MessageFilter::~MessageFilter() { - -} - -void GpuChannelHost::MessageFilter::AddRoute( - int route_id, - base::WeakPtr<IPC::Channel::Listener> listener, - scoped_refptr<MessageLoopProxy> loop) { - DCHECK(parent_->factory_->IsIOThread()); - DCHECK(listeners_.find(route_id) == listeners_.end()); - GpuListenerInfo info; - info.listener = listener; - info.loop = loop; - listeners_[route_id] = info; -} - -void GpuChannelHost::MessageFilter::RemoveRoute(int route_id) { - DCHECK(parent_->factory_->IsIOThread()); - ListenerMap::iterator it = listeners_.find(route_id); - if (it != listeners_.end()) - listeners_.erase(it); -} - -bool GpuChannelHost::MessageFilter::OnMessageReceived( - const IPC::Message& message) { - DCHECK(parent_->factory_->IsIOThread()); - // Never handle sync message replies or we will deadlock here. - if (message.is_reply()) - return false; - - DCHECK(message.routing_id() != MSG_ROUTING_CONTROL); - - ListenerMap::iterator it = listeners_.find(message.routing_id()); - - if (it != listeners_.end()) { - const GpuListenerInfo& info = it->second; - info.loop->PostTask( - FROM_HERE, - base::Bind( - base::IgnoreResult(&IPC::Channel::Listener::OnMessageReceived), - info.listener, - message)); - } - - return true; -} - -void GpuChannelHost::MessageFilter::OnChannelError() { - DCHECK(parent_->factory_->IsIOThread()); - // Inform all the proxies that an error has occurred. This will be reported - // via OpenGL as a lost context. - for (ListenerMap::iterator it = listeners_.begin(); - it != listeners_.end(); - it++) { - const GpuListenerInfo& info = it->second; - info.loop->PostTask( - FROM_HERE, - base::Bind(&IPC::Channel::Listener::OnChannelError, info.listener)); - } +GpuListenerInfo::GpuListenerInfo() {} - listeners_.clear(); - - MessageLoop* main_loop = parent_->factory_->GetMainLoop(); - main_loop->PostTask(FROM_HERE, - base::Bind(&GpuChannelHost::OnChannelError, parent_)); -} +GpuListenerInfo::~GpuListenerInfo() {} GpuChannelHost::GpuChannelHost( GpuChannelHostFactory* factory, int gpu_host_id, int client_id) @@ -101,9 +28,6 @@ GpuChannelHost::GpuChannelHost( state_(kUnconnected) { } -GpuChannelHost::~GpuChannelHost() { -} - void GpuChannelHost::Connect( const IPC::ChannelHandle& channel_handle) { DCHECK(factory_->IsMainThread()); @@ -136,14 +60,14 @@ void GpuChannelHost::set_gpu_info(const content::GPUInfo& gpu_info) { gpu_info_ = gpu_info; } -const content::GPUInfo& GpuChannelHost::gpu_info() const { - return gpu_info_; -} - void GpuChannelHost::SetStateLost() { state_ = kLost; } +const content::GPUInfo& GpuChannelHost::gpu_info() const { + return gpu_info_; +} + void GpuChannelHost::OnChannelError() { state_ = kLost; @@ -215,17 +139,6 @@ CommandBufferProxy* GpuChannelHost::CreateViewCommandBuffer( #endif } -GpuVideoDecodeAcceleratorHost* GpuChannelHost::CreateVideoDecoder( - int command_buffer_route_id, - media::VideoCodecProfile profile, - media::VideoDecodeAccelerator::Client* client) { - AutoLock lock(context_lock_); - ProxyMap::iterator it = proxies_.find(command_buffer_route_id); - DCHECK(it != proxies_.end()); - CommandBufferProxyImpl* proxy = it->second; - return proxy->CreateVideoDecoder(profile, client); -} - CommandBufferProxy* GpuChannelHost::CreateOffscreenCommandBuffer( const gfx::Size& size, CommandBufferProxy* share_group, @@ -266,6 +179,17 @@ CommandBufferProxy* GpuChannelHost::CreateOffscreenCommandBuffer( #endif } +GpuVideoDecodeAcceleratorHost* GpuChannelHost::CreateVideoDecoder( + int command_buffer_route_id, + media::VideoCodecProfile profile, + media::VideoDecodeAccelerator::Client* client) { + AutoLock lock(context_lock_); + ProxyMap::iterator it = proxies_.find(command_buffer_route_id); + DCHECK(it != proxies_.end()); + CommandBufferProxyImpl* proxy = it->second; + return proxy->CreateVideoDecoder(profile, client); +} + void GpuChannelHost::DestroyCommandBuffer( CommandBufferProxy* command_buffer) { #if defined(ENABLE_GPU) @@ -313,3 +237,77 @@ void GpuChannelHost::ForciblyCloseChannel() { Send(new GpuChannelMsg_CloseChannel()); SetStateLost(); } + +GpuChannelHost::~GpuChannelHost() {} + + +GpuChannelHost::MessageFilter::MessageFilter(GpuChannelHost* parent) + : parent_(parent) { +} + +GpuChannelHost::MessageFilter::~MessageFilter() {} + +void GpuChannelHost::MessageFilter::AddRoute( + int route_id, + base::WeakPtr<IPC::Channel::Listener> listener, + scoped_refptr<MessageLoopProxy> loop) { + DCHECK(parent_->factory_->IsIOThread()); + DCHECK(listeners_.find(route_id) == listeners_.end()); + GpuListenerInfo info; + info.listener = listener; + info.loop = loop; + listeners_[route_id] = info; +} + +void GpuChannelHost::MessageFilter::RemoveRoute(int route_id) { + DCHECK(parent_->factory_->IsIOThread()); + ListenerMap::iterator it = listeners_.find(route_id); + if (it != listeners_.end()) + listeners_.erase(it); +} + +bool GpuChannelHost::MessageFilter::OnMessageReceived( + const IPC::Message& message) { + DCHECK(parent_->factory_->IsIOThread()); + // Never handle sync message replies or we will deadlock here. + if (message.is_reply()) + return false; + + DCHECK(message.routing_id() != MSG_ROUTING_CONTROL); + + ListenerMap::iterator it = listeners_.find(message.routing_id()); + + if (it != listeners_.end()) { + const GpuListenerInfo& info = it->second; + info.loop->PostTask( + FROM_HERE, + base::Bind( + base::IgnoreResult(&IPC::Channel::Listener::OnMessageReceived), + info.listener, + message)); + } + + return true; +} + +void GpuChannelHost::MessageFilter::OnChannelError() { + DCHECK(parent_->factory_->IsIOThread()); + // Inform all the proxies that an error has occurred. This will be reported + // via OpenGL as a lost context. + for (ListenerMap::iterator it = listeners_.begin(); + it != listeners_.end(); + it++) { + const GpuListenerInfo& info = it->second; + info.loop->PostTask( + FROM_HERE, + base::Bind(&IPC::Channel::Listener::OnChannelError, info.listener)); + } + + listeners_.clear(); + + MessageLoop* main_loop = parent_->factory_->GetMainLoop(); + main_loop->PostTask(FROM_HERE, + base::Bind(&GpuChannelHost::OnChannelError, parent_)); +} + + diff --git a/content/common/gpu/client/gpu_channel_host.h b/content/common/gpu/client/gpu_channel_host.h index b82efe9..179a780 100644 --- a/content/common/gpu/client/gpu_channel_host.h +++ b/content/common/gpu/client/gpu_channel_host.h @@ -86,7 +86,6 @@ class GpuChannelHost : public IPC::Message::Sender, GpuChannelHost(GpuChannelHostFactory* factory, int gpu_host_id, int client_id); - virtual ~GpuChannelHost(); // Connect to GPU process channel. void Connect(const IPC::ChannelHandle& channel_handle); @@ -157,12 +156,14 @@ class GpuChannelHost : public IPC::Message::Sender, int client_id() const { return client_id_; } private: + friend class base::RefCountedThreadSafe<GpuChannelHost>; + virtual ~GpuChannelHost(); + // A filter used internally to route incoming messages from the IO thread // to the correct message loop. class MessageFilter : public IPC::ChannelProxy::MessageFilter { public: explicit MessageFilter(GpuChannelHost* parent); - virtual ~MessageFilter(); void AddRoute(int route_id, base::WeakPtr<IPC::Channel::Listener> listener, @@ -174,6 +175,8 @@ class GpuChannelHost : public IPC::Message::Sender, virtual void OnChannelError() OVERRIDE; private: + virtual ~MessageFilter(); + GpuChannelHost* parent_; typedef base::hash_map<int, GpuListenerInfo> ListenerMap; diff --git a/content/common/gpu/client/gpu_video_decode_accelerator_host.cc b/content/common/gpu/client/gpu_video_decode_accelerator_host.cc index 6cd519b..0ac5167a 100644 --- a/content/common/gpu/client/gpu_video_decode_accelerator_host.cc +++ b/content/common/gpu/client/gpu_video_decode_accelerator_host.cc @@ -30,8 +30,6 @@ GpuVideoDecodeAcceleratorHost::GpuVideoDecodeAcceleratorHost( DCHECK(client_); } -GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() {} - void GpuVideoDecodeAcceleratorHost::OnChannelError() { DLOG(ERROR) << "GpuVideoDecodeAcceleratorHost::OnChannelError()"; OnErrorNotification(PLATFORM_FAILURE); @@ -126,6 +124,8 @@ void GpuVideoDecodeAcceleratorHost::Destroy() { Send(new AcceleratedVideoDecoderMsg_Destroy(decoder_route_id_)); } +GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() {} + void GpuVideoDecodeAcceleratorHost::Send(IPC::Message* message) { // After OnChannelError is called, the client should no longer send // messages to the gpu channel through this object. diff --git a/content/common/gpu/client/gpu_video_decode_accelerator_host.h b/content/common/gpu/client/gpu_video_decode_accelerator_host.h index c1479b8..a2a6a24 100644 --- a/content/common/gpu/client/gpu_video_decode_accelerator_host.h +++ b/content/common/gpu/client/gpu_video_decode_accelerator_host.h @@ -26,7 +26,6 @@ class GpuVideoDecodeAcceleratorHost GpuVideoDecodeAcceleratorHost(GpuChannelHost* channel, int32 decoder_route_id, media::VideoDecodeAccelerator::Client* client); - virtual ~GpuVideoDecodeAcceleratorHost(); // IPC::Channel::Listener implementation. virtual void OnChannelError() OVERRIDE; @@ -42,6 +41,9 @@ class GpuVideoDecodeAcceleratorHost virtual void Reset() OVERRIDE; virtual void Destroy() OVERRIDE; + protected: + virtual ~GpuVideoDecodeAcceleratorHost(); + private: void Send(IPC::Message* message); diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index 96c3553..9785ce7 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -59,9 +59,37 @@ GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); } -GpuChannel::~GpuChannel() { + +bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, + base::WaitableEvent* shutdown_event) { + DCHECK(!channel_.get()); + + // Map renderer ID to a (single) channel to that process. + channel_.reset(new IPC::SyncChannel( + channel_id_, + IPC::Channel::MODE_SERVER, + this, + io_message_loop, + false, + shutdown_event)); + + return true; } +std::string GpuChannel::GetChannelName() { + return channel_id_; +} + +#if defined(OS_POSIX) +int GpuChannel::TakeRendererFileDescriptor() { + if (!channel_.get()) { + NOTREACHED(); + return -1; + } + return channel_->TakeClientFileDescriptor(); +} +#endif // defined(OS_POSIX) + bool GpuChannel::OnMessageReceived(const IPC::Message& message) { if (log_messages_) { DVLOG(1) << "received message @" << &message << " on channel @" << this @@ -146,20 +174,6 @@ void GpuChannel::OnScheduled() { handle_messages_scheduled_ = true; } -void GpuChannel::LoseAllContexts() { - gpu_channel_manager_->LoseAllContexts(); -} - -void GpuChannel::DestroySoon() { - MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&GpuChannel::OnDestroy, this)); -} - -void GpuChannel::OnDestroy() { - TRACE_EVENT0("gpu", "GpuChannel::OnDestroy"); - gpu_channel_manager_->RemoveChannel(client_id_); -} - void GpuChannel::CreateViewCommandBuffer( const gfx::GLSurfaceHandle& window, int32 surface_id, @@ -196,6 +210,39 @@ GpuCommandBufferStub* GpuChannel::LookupCommandBuffer(int32 route_id) { return stubs_.Lookup(route_id); } +void GpuChannel::LoseAllContexts() { + gpu_channel_manager_->LoseAllContexts(); +} + +void GpuChannel::DestroySoon() { + MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(&GpuChannel::OnDestroy, this)); +} + +int GpuChannel::GenerateRouteID() { + static int last_id = 0; + return ++last_id; +} + +void GpuChannel::AddRoute(int32 route_id, IPC::Channel::Listener* listener) { + router_.AddRoute(route_id, listener); +} + +void GpuChannel::RemoveRoute(int32 route_id) { + router_.RemoveRoute(route_id); +} + +bool GpuChannel::ShouldPreferDiscreteGpu() const { + return num_contexts_preferring_discrete_gpu_ > 0; +} + +GpuChannel::~GpuChannel() {} + +void GpuChannel::OnDestroy() { + TRACE_EVENT0("gpu", "GpuChannel::OnDestroy"); + gpu_channel_manager_->RemoveChannel(client_id_); +} + bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers // here. This is so the reply can be delayed if the scheduler is unscheduled. @@ -284,23 +331,6 @@ void GpuChannel::ScheduleDelayedWork(GpuCommandBufferStub *stub, } } -int GpuChannel::GenerateRouteID() { - static int last_id = 0; - return ++last_id; -} - -void GpuChannel::AddRoute(int32 route_id, IPC::Channel::Listener* listener) { - router_.AddRoute(route_id, listener); -} - -void GpuChannel::RemoveRoute(int32 route_id) { - router_.RemoveRoute(route_id); -} - -bool GpuChannel::ShouldPreferDiscreteGpu() const { - return num_contexts_preferring_discrete_gpu_ > 0; -} - void GpuChannel::OnCreateOffscreenCommandBuffer( const gfx::Size& size, const GPUCreateCommandBufferConfig& init_params, @@ -391,22 +421,6 @@ void GpuChannel::OnCloseChannel() { // At this point "this" is deleted! } -bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, - base::WaitableEvent* shutdown_event) { - DCHECK(!channel_.get()); - - // Map renderer ID to a (single) channel to that process. - channel_.reset(new IPC::SyncChannel( - channel_id_, - IPC::Channel::MODE_SERVER, - this, - io_message_loop, - false, - shutdown_event)); - - return true; -} - void GpuChannel::WillCreateCommandBuffer(gfx::GpuPreference gpu_preference) { if (gpu_preference == gfx::PreferDiscreteGpu) ++num_contexts_preferring_discrete_gpu_; @@ -417,17 +431,3 @@ void GpuChannel::DidDestroyCommandBuffer(gfx::GpuPreference gpu_preference) { --num_contexts_preferring_discrete_gpu_; DCHECK_GE(num_contexts_preferring_discrete_gpu_, 0); } - -std::string GpuChannel::GetChannelName() { - return channel_id_; -} - -#if defined(OS_POSIX) -int GpuChannel::TakeRendererFileDescriptor() { - if (!channel_.get()) { - NOTREACHED(); - return -1; - } - return channel_->TakeClientFileDescriptor(); -} -#endif // defined(OS_POSIX) diff --git a/content/common/gpu/gpu_channel.h b/content/common/gpu/gpu_channel.h index d9c5192..42e4d8b 100644 --- a/content/common/gpu/gpu_channel.h +++ b/content/common/gpu/gpu_channel.h @@ -45,7 +45,6 @@ class GpuChannel : public IPC::Channel::Listener, gfx::GLShareGroup* share_group, int client_id, bool software); - virtual ~GpuChannel(); bool Init(base::MessageLoopProxy* io_message_loop, base::WaitableEvent* shutdown_event); @@ -106,7 +105,12 @@ class GpuChannel : public IPC::Channel::Listener, // discrete GPU even if they would otherwise use the integrated GPU. bool ShouldPreferDiscreteGpu() const; + protected: + virtual ~GpuChannel(); + private: + friend class base::RefCountedThreadSafe<GpuChannel>; + void OnDestroy(); bool OnControlMessageReceived(const IPC::Message& msg); diff --git a/content/common/gpu/image_transport_surface.cc b/content/common/gpu/image_transport_surface.cc index 6601637..e1fadf6 100644 --- a/content/common/gpu/image_transport_surface.cc +++ b/content/common/gpu/image_transport_surface.cc @@ -17,11 +17,9 @@ #include "gpu/command_buffer/service/gpu_scheduler.h" #include "ui/gfx/gl/gl_switches.h" -ImageTransportSurface::ImageTransportSurface() { -} +ImageTransportSurface::ImageTransportSurface() {} -ImageTransportSurface::~ImageTransportSurface() { -} +ImageTransportSurface::~ImageTransportSurface() {} void ImageTransportSurface::GetRegionsToCopy( const gfx::Rect& previous_damage_rect, @@ -87,8 +85,7 @@ bool ImageTransportHelper::Initialize() { return true; } -void ImageTransportHelper::Destroy() { -} +void ImageTransportHelper::Destroy() {} bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { bool handled = true; @@ -105,13 +102,6 @@ bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { return handled; } -void ImageTransportHelper::SendAcceleratedSurfaceRelease( - GpuHostMsg_AcceleratedSurfaceRelease_Params params) { - params.surface_id = stub_->surface_id(); - params.route_id = route_id_; - manager_->Send(new GpuHostMsg_AcceleratedSurfaceRelease(params)); -} - void ImageTransportHelper::SendAcceleratedSurfaceNew( GpuHostMsg_AcceleratedSurfaceNew_Params params) { params.surface_id = stub_->surface_id(); @@ -142,6 +132,13 @@ void ImageTransportHelper::SendAcceleratedSurfacePostSubBuffer( manager_->Send(new GpuHostMsg_AcceleratedSurfacePostSubBuffer(params)); } +void ImageTransportHelper::SendAcceleratedSurfaceRelease( + GpuHostMsg_AcceleratedSurfaceRelease_Params params) { + params.surface_id = stub_->surface_id(); + params.route_id = route_id_; + manager_->Send(new GpuHostMsg_AcceleratedSurfaceRelease(params)); +} + void ImageTransportHelper::SendResizeView(const gfx::Size& size) { manager_->Send(new GpuHostMsg_ResizeView(stub_->surface_id(), route_id_, @@ -168,12 +165,34 @@ void ImageTransportHelper::DeferToFence(base::Closure task) { scheduler->DeferToFence(task); } -void ImageTransportHelper::OnBuffersSwappedACK() { - surface_->OnBuffersSwappedACK(); +bool ImageTransportHelper::MakeCurrent() { + gpu::gles2::GLES2Decoder* decoder = Decoder(); + if (!decoder) + return false; + return decoder->MakeCurrent(); } -void ImageTransportHelper::OnPostSubBufferACK() { - surface_->OnPostSubBufferACK(); +void ImageTransportHelper::SetSwapInterval() { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) + Decoder()->GetGLContext()->SetSwapInterval(0); + else + Decoder()->GetGLContext()->SetSwapInterval(1); +} + +void ImageTransportHelper::Suspend() { + manager_->Send(new GpuHostMsg_AcceleratedSurfaceSuspend(stub_->surface_id())); +} + +gpu::GpuScheduler* ImageTransportHelper::Scheduler() { + if (!stub_.get()) + return NULL; + return stub_->scheduler(); +} + +gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { + if (!stub_.get()) + return NULL; + return stub_->decoder(); } void ImageTransportHelper::OnNewSurfaceACK( @@ -182,6 +201,14 @@ void ImageTransportHelper::OnNewSurfaceACK( surface_->OnNewSurfaceACK(surface_handle, shm_handle); } +void ImageTransportHelper::OnBuffersSwappedACK() { + surface_->OnBuffersSwappedACK(); +} + +void ImageTransportHelper::OnPostSubBufferACK() { + surface_->OnPostSubBufferACK(); +} + void ImageTransportHelper::OnResizeViewACK() { surface_->OnResizeViewACK(); } @@ -203,36 +230,6 @@ void ImageTransportHelper::Resize(gfx::Size size) { #endif } -void ImageTransportHelper::SetSwapInterval() { - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) - Decoder()->GetGLContext()->SetSwapInterval(0); - else - Decoder()->GetGLContext()->SetSwapInterval(1); -} - -bool ImageTransportHelper::MakeCurrent() { - gpu::gles2::GLES2Decoder* decoder = Decoder(); - if (!decoder) - return false; - return decoder->MakeCurrent(); -} - -void ImageTransportHelper::Suspend() { - manager_->Send(new GpuHostMsg_AcceleratedSurfaceSuspend(stub_->surface_id())); -} - -gpu::GpuScheduler* ImageTransportHelper::Scheduler() { - if (!stub_.get()) - return NULL; - return stub_->scheduler(); -} - -gpu::gles2::GLES2Decoder* ImageTransportHelper::Decoder() { - if (!stub_.get()) - return NULL; - return stub_->decoder(); -} - PassThroughImageTransportSurface::PassThroughImageTransportSurface( GpuChannelManager* manager, GpuCommandBufferStub* stub, @@ -247,9 +244,6 @@ PassThroughImageTransportSurface::PassThroughImageTransportSurface( gfx::kNullPluginWindow)); } -PassThroughImageTransportSurface::~PassThroughImageTransportSurface() { -} - bool PassThroughImageTransportSurface::Initialize() { // The surface is assumed to have already been initialized. return helper_->Initialize(); @@ -260,10 +254,6 @@ void PassThroughImageTransportSurface::Destroy() { GLSurfaceAdapter::Destroy(); } -void PassThroughImageTransportSurface::OnNewSurfaceACK( - uint64 surface_handle, TransportDIB::Handle shm_handle) { -} - bool PassThroughImageTransportSurface::SwapBuffers() { bool result = gfx::GLSurfaceAdapter::SwapBuffers(); @@ -310,6 +300,11 @@ bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { return true; } +void PassThroughImageTransportSurface::OnNewSurfaceACK( + uint64 surface_handle, + TransportDIB::Handle shm_handle) { +} + void PassThroughImageTransportSurface::OnBuffersSwappedACK() { DCHECK(transport_); helper_->SetScheduled(true); @@ -338,4 +333,6 @@ void PassThroughImageTransportSurface::OnResize(gfx::Size size) { } } +PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} + #endif // defined(ENABLE_GPU) diff --git a/content/common/gpu/image_transport_surface.h b/content/common/gpu/image_transport_surface.h index b2d27d4..9e1a05c 100644 --- a/content/common/gpu/image_transport_surface.h +++ b/content/common/gpu/image_transport_surface.h @@ -158,7 +158,6 @@ class PassThroughImageTransportSurface GpuCommandBufferStub* stub, gfx::GLSurface* surface, bool transport); - virtual ~PassThroughImageTransportSurface(); // GLSurface implementation. virtual bool Initialize() OVERRIDE; @@ -175,6 +174,9 @@ class PassThroughImageTransportSurface virtual void OnResizeViewACK() OVERRIDE; virtual void OnResize(gfx::Size size) OVERRIDE; + protected: + virtual ~PassThroughImageTransportSurface(); + private: scoped_ptr<ImageTransportHelper> helper_; gfx::Size new_size_; diff --git a/content/common/indexed_db/indexed_db_message_filter.cc b/content/common/indexed_db/indexed_db_message_filter.cc index b01aefa..66a0fc6 100644 --- a/content/common/indexed_db/indexed_db_message_filter.cc +++ b/content/common/indexed_db/indexed_db_message_filter.cc @@ -16,9 +16,6 @@ IndexedDBMessageFilter::IndexedDBMessageFilter() : main_thread_loop_proxy_(base::MessageLoopProxy::current()) { } -IndexedDBMessageFilter::~IndexedDBMessageFilter() { -} - bool IndexedDBMessageFilter::OnMessageReceived(const IPC::Message& msg) { if (IPC_MESSAGE_CLASS(msg) != IndexedDBMsgStart) return false; @@ -32,6 +29,8 @@ bool IndexedDBMessageFilter::OnMessageReceived(const IPC::Message& msg) { return true; } +IndexedDBMessageFilter::~IndexedDBMessageFilter() {} + void IndexedDBMessageFilter::DispatchMessage(const IPC::Message& msg) { IndexedDBDispatcher::ThreadSpecificInstance()->OnMessageReceived(msg); } diff --git a/content/common/indexed_db/indexed_db_message_filter.h b/content/common/indexed_db/indexed_db_message_filter.h index 3486784..57eed0f 100644 --- a/content/common/indexed_db/indexed_db_message_filter.h +++ b/content/common/indexed_db/indexed_db_message_filter.h @@ -13,11 +13,13 @@ class IndexedDBDispatcher; class IndexedDBMessageFilter : public IPC::ChannelProxy::MessageFilter { public: IndexedDBMessageFilter(); - virtual ~IndexedDBMessageFilter(); // IPC::Channel::Listener implementation. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + protected: + virtual ~IndexedDBMessageFilter(); + private: void DispatchMessage(const IPC::Message& msg); scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; diff --git a/content/gpu/gpu_watchdog_thread.cc b/content/gpu/gpu_watchdog_thread.cc index d3b5c9a..5d6c088 100644 --- a/content/gpu/gpu_watchdog_thread.cc +++ b/content/gpu/gpu_watchdog_thread.cc @@ -50,18 +50,6 @@ GpuWatchdogThread::GpuWatchdogThread(int timeout) watched_message_loop_->AddTaskObserver(&task_observer_); } -GpuWatchdogThread::~GpuWatchdogThread() { - // Verify that the thread was explicitly stopped. If the thread is stopped - // implicitly by the destructor, CleanUp() will not be called. - DCHECK(!weak_factory_.HasWeakPtrs()); - -#if defined(OS_WIN) - CloseHandle(watched_thread_handle_); -#endif - - watched_message_loop_->RemoveTaskObserver(&task_observer_); -} - void GpuWatchdogThread::PostAcknowledge() { // Called on the monitored thread. Responds with OnAcknowledge. Cannot use // the method factory. Rely on reference counting instead. @@ -70,6 +58,14 @@ void GpuWatchdogThread::PostAcknowledge() { base::Bind(&GpuWatchdogThread::OnAcknowledge, this)); } +void GpuWatchdogThread::CheckArmed() { + // Acknowledge the watchdog if it has armed itself. The watchdog will not + // change its armed state until it is acknowledged. + if (armed()) { + PostAcknowledge(); + } +} + void GpuWatchdogThread::Init() { // Schedule the first check. OnCheck(); @@ -97,12 +93,16 @@ void GpuWatchdogThread::GpuWatchdogTaskObserver::DidProcessTask( watchdog_->CheckArmed(); } -void GpuWatchdogThread::CheckArmed() { - // Acknowledge the watchdog if it has armed itself. The watchdog will not - // change its armed state until it is acknowledged. - if (armed()) { - PostAcknowledge(); - } +GpuWatchdogThread::~GpuWatchdogThread() { + // Verify that the thread was explicitly stopped. If the thread is stopped + // implicitly by the destructor, CleanUp() will not be called. + DCHECK(!weak_factory_.HasWeakPtrs()); + +#if defined(OS_WIN) + CloseHandle(watched_thread_handle_); +#endif + + watched_message_loop_->RemoveTaskObserver(&task_observer_); } void GpuWatchdogThread::OnAcknowledge() { @@ -124,39 +124,6 @@ void GpuWatchdogThread::OnAcknowledge() { base::TimeDelta::FromMilliseconds(kCheckPeriodMs)); } -#if defined(OS_WIN) -base::TimeDelta GpuWatchdogThread::GetWatchedThreadTime() { - FILETIME creation_time; - FILETIME exit_time; - FILETIME user_time; - FILETIME kernel_time; - BOOL result = GetThreadTimes(watched_thread_handle_, - &creation_time, - &exit_time, - &kernel_time, - &user_time); - DCHECK(result); - - ULARGE_INTEGER user_time64; - user_time64.HighPart = user_time.dwHighDateTime; - user_time64.LowPart = user_time.dwLowDateTime; - - ULARGE_INTEGER kernel_time64; - kernel_time64.HighPart = kernel_time.dwHighDateTime; - kernel_time64.LowPart = kernel_time.dwLowDateTime; - - // Time is reported in units of 100 nanoseconds. Kernel and user time are - // summed to deal with to kinds of hangs. One is where the GPU process is - // stuck in user level, never calling into the kernel and kernel time is - // not increasing. The other is where either the kernel hangs and never - // returns to user level or where user level code - // calls into kernel level repeatedly, giving up its quanta before it is - // tracked, for example a loop that repeatedly Sleeps. - return base::TimeDelta::FromMilliseconds(static_cast<int64>( - (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); -} -#endif - void GpuWatchdogThread::OnCheck() { if (armed_) return; @@ -236,3 +203,36 @@ void GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang() { terminated = true; } + +#if defined(OS_WIN) +base::TimeDelta GpuWatchdogThread::GetWatchedThreadTime() { + FILETIME creation_time; + FILETIME exit_time; + FILETIME user_time; + FILETIME kernel_time; + BOOL result = GetThreadTimes(watched_thread_handle_, + &creation_time, + &exit_time, + &kernel_time, + &user_time); + DCHECK(result); + + ULARGE_INTEGER user_time64; + user_time64.HighPart = user_time.dwHighDateTime; + user_time64.LowPart = user_time.dwLowDateTime; + + ULARGE_INTEGER kernel_time64; + kernel_time64.HighPart = kernel_time.dwHighDateTime; + kernel_time64.LowPart = kernel_time.dwLowDateTime; + + // Time is reported in units of 100 nanoseconds. Kernel and user time are + // summed to deal with to kinds of hangs. One is where the GPU process is + // stuck in user level, never calling into the kernel and kernel time is + // not increasing. The other is where either the kernel hangs and never + // returns to user level or where user level code + // calls into kernel level repeatedly, giving up its quanta before it is + // tracked, for example a loop that repeatedly Sleeps. + return base::TimeDelta::FromMilliseconds(static_cast<int64>( + (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); +} +#endif diff --git a/content/gpu/gpu_watchdog_thread.h b/content/gpu/gpu_watchdog_thread.h index 8f3ee90..66a7d67 100644 --- a/content/gpu/gpu_watchdog_thread.h +++ b/content/gpu/gpu_watchdog_thread.h @@ -20,7 +20,6 @@ class GpuWatchdogThread : public base::Thread, public base::RefCountedThreadSafe<GpuWatchdogThread> { public: explicit GpuWatchdogThread(int timeout); - virtual ~GpuWatchdogThread(); // Accessible on watched thread but only modified by watchdog thread. bool armed() const { return armed_; } @@ -34,6 +33,7 @@ class GpuWatchdogThread : public base::Thread, virtual void CleanUp() OVERRIDE; private: + friend class base::RefCountedThreadSafe<GpuWatchdogThread>; // An object of this type intercepts the reception and completion of all tasks // on the watched thread and checks whether the watchdog is armed. @@ -50,12 +50,15 @@ class GpuWatchdogThread : public base::Thread, GpuWatchdogThread* watchdog_; }; + virtual ~GpuWatchdogThread(); + void OnAcknowledge(); void OnCheck(); void DeliberatelyTerminateToRecoverFromHang(); - void Disable(); +#if defined(OS_WIN) base::TimeDelta GetWatchedThreadTime(); +#endif MessageLoop* watched_message_loop_; base::TimeDelta timeout_; diff --git a/content/renderer/devtools_agent_filter.cc b/content/renderer/devtools_agent_filter.cc index 4e42ce3..312e599 100644 --- a/content/renderer/devtools_agent_filter.cc +++ b/content/renderer/devtools_agent_filter.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,7 +21,8 @@ class MessageImpl : public WebDevToolsAgent::MessageDescriptor { public: MessageImpl(const std::string& message, int host_id) : msg(message), - host_id(host_id) {} + host_id(host_id) { + } virtual ~MessageImpl() {} virtual WebDevToolsAgent* agent() { DevToolsAgent* agent = DevToolsAgent::FromHostId(host_id); @@ -35,25 +36,21 @@ class MessageImpl : public WebDevToolsAgent::MessageDescriptor { int host_id; }; -} +// Made static to allow DevToolsAgent to use it for replying directly +// from IO thread. +int g_current_routing_id = 0; -// static -IPC::Channel* DevToolsAgentFilter::channel_ = NULL; -// static -int DevToolsAgentFilter::current_routing_id_ = 0; +} // namespace DevToolsAgentFilter::DevToolsAgentFilter() : message_handled_(false), render_thread_loop_(MessageLoop::current()) { } -DevToolsAgentFilter::~DevToolsAgentFilter() { -} - bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { // Dispatch debugger commands directly from IO. message_handled_ = true; - current_routing_id_ = message.routing_id(); + g_current_routing_id = message.routing_id(); IPC_BEGIN_MESSAGE_MAP(DevToolsAgentFilter, message) IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, OnDispatchOnInspectorBackend) @@ -62,9 +59,7 @@ bool DevToolsAgentFilter::OnMessageReceived(const IPC::Message& message) { return message_handled_; } -void DevToolsAgentFilter::OnFilterAdded(IPC::Channel* channel) { - channel_ = channel; -} +DevToolsAgentFilter::~DevToolsAgentFilter() {} void DevToolsAgentFilter::OnDispatchOnInspectorBackend( const std::string& message) { @@ -74,7 +69,7 @@ void DevToolsAgentFilter::OnDispatchOnInspectorBackend( return; } WebDevToolsAgent::interruptAndDispatch( - new MessageImpl(message, current_routing_id_)); + new MessageImpl(message, g_current_routing_id)); render_thread_loop_->PostTask( FROM_HERE, base::Bind(&WebDevToolsAgent::processPendingMessages)); diff --git a/content/renderer/devtools_agent_filter.h b/content/renderer/devtools_agent_filter.h index 217827e..767291e 100644 --- a/content/renderer/devtools_agent_filter.h +++ b/content/renderer/devtools_agent_filter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -23,26 +23,21 @@ class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { public: // There is a single instance of this class instantiated by the RenderThread. DevToolsAgentFilter(); - virtual ~DevToolsAgentFilter(); static void SendRpcMessage(const DevToolsMessageData& data); - private: // IPC::ChannelProxy::MessageFilter override. Called on IO thread. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; + protected: + virtual ~DevToolsAgentFilter(); + private: void OnDispatchOnInspectorBackend(const std::string& message); bool message_handled_; MessageLoop* render_thread_loop_; - // Made static to allow DevToolsAgent to use it for replying directly - // from IO thread. - static int current_routing_id_; - static IPC::Channel* channel_; - DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter); }; diff --git a/content/renderer/gpu/compositor_thread.cc b/content/renderer/gpu/compositor_thread.cc index 665ae33..8cbe079 100644 --- a/content/renderer/gpu/compositor_thread.cc +++ b/content/renderer/gpu/compositor_thread.cc @@ -42,10 +42,6 @@ class CompositorThread::InputHandlerWrapper render_view_impl_, params)); } - virtual ~InputHandlerWrapper() { - input_handler_->setClient(NULL); - } - int routing_id() const { return routing_id_; } WebKit::WebCompositorInputHandler* input_handler() const { return input_handler_; @@ -66,6 +62,12 @@ class CompositorThread::InputHandlerWrapper } private: + friend class base::RefCountedThreadSafe<InputHandlerWrapper>; + + virtual ~InputHandlerWrapper() { + input_handler_->setClient(NULL); + } + CompositorThread* compositor_thread_; int routing_id_; WebKit::WebCompositorInputHandler* input_handler_; diff --git a/content/renderer/media/audio_input_device.cc b/content/renderer/media/audio_input_device.cc index 09c0ba7..8dcf8d7 100644 --- a/content/renderer/media/audio_input_device.cc +++ b/content/renderer/media/audio_input_device.cc @@ -52,10 +52,10 @@ AudioInputDevice::AudioInputDevice(const media::AudioParameters& params, filter_ = RenderThreadImpl::current()->audio_input_message_filter(); } -AudioInputDevice::~AudioInputDevice() { - // TODO(henrika): The current design requires that the user calls - // Stop before deleting this class. - CHECK_EQ(0, stream_id_); +void AudioInputDevice::SetDevice(int session_id) { + DVLOG(1) << "SetDevice (session_id=" << session_id << ")"; + message_loop()->PostTask(FROM_HERE, + base::Bind(&AudioInputDevice::SetSessionIdOnIOThread, this, session_id)); } void AudioInputDevice::Start() { @@ -64,12 +64,6 @@ void AudioInputDevice::Start() { base::Bind(&AudioInputDevice::InitializeOnIOThread, this)); } -void AudioInputDevice::SetDevice(int session_id) { - DVLOG(1) << "SetDevice (session_id=" << session_id << ")"; - message_loop()->PostTask(FROM_HERE, - base::Bind(&AudioInputDevice::SetSessionIdOnIOThread, this, session_id)); -} - void AudioInputDevice::Stop() { DVLOG(1) << "Stop()"; @@ -104,83 +98,6 @@ void AudioInputDevice::SetAutomaticGainControl(bool enabled) { this, enabled)); } -void AudioInputDevice::InitializeOnIOThread() { - DCHECK(message_loop()->BelongsToCurrentThread()); - // Make sure we don't call Start() more than once. - DCHECK_EQ(0, stream_id_); - if (stream_id_) - return; - - stream_id_ = filter_->AddDelegate(this); - // If |session_id_| is not specified, it will directly create the stream; - // otherwise it will send a AudioInputHostMsg_StartDevice msg to the browser - // and create the stream when getting a OnDeviceReady() callback. - if (!session_id_) { - Send(new AudioInputHostMsg_CreateStream( - stream_id_, audio_parameters_, - media::AudioManagerBase::kDefaultDeviceId, - agc_is_enabled_)); - } else { - Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); - pending_device_ready_ = true; - } -} - -void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { - DCHECK(message_loop()->BelongsToCurrentThread()); - session_id_ = session_id; -} - -void AudioInputDevice::StartOnIOThread() { - DCHECK(message_loop()->BelongsToCurrentThread()); - if (stream_id_) - Send(new AudioInputHostMsg_RecordStream(stream_id_)); -} - -void AudioInputDevice::ShutDownOnIOThread() { - DCHECK(message_loop()->BelongsToCurrentThread()); - // NOTE: |completion| may be NULL. - // Make sure we don't call shutdown more than once. - if (stream_id_) { - filter_->RemoveDelegate(stream_id_); - Send(new AudioInputHostMsg_CloseStream(stream_id_)); - - stream_id_ = 0; - session_id_ = 0; - pending_device_ready_ = false; - agc_is_enabled_ = false; - } - - // We can run into an issue where ShutDownOnIOThread is called right after - // OnStreamCreated is called in cases where Start/Stop are called before we - // get the OnStreamCreated callback. To handle that corner case, we call - // Stop(). In most cases, the thread will already be stopped. - // Another situation is when the IO thread goes away before Stop() is called - // in which case, we cannot use the message loop to close the thread handle - // and can't not rely on the main thread existing either. - base::ThreadRestrictions::ScopedAllowIO allow_io; - audio_thread_.Stop(NULL); - audio_callback_.reset(); -} - -void AudioInputDevice::SetVolumeOnIOThread(double volume) { - DCHECK(message_loop()->BelongsToCurrentThread()); - if (stream_id_) - Send(new AudioInputHostMsg_SetVolume(stream_id_, volume)); -} - -void AudioInputDevice::SetAutomaticGainControlOnIOThread(bool enabled) { - DCHECK(message_loop()->BelongsToCurrentThread()); - DCHECK_EQ(0, stream_id_) << - "The AGC state can not be modified while capturing is active."; - if (stream_id_) - return; - - // We simply store the new AGC setting here. This value will be used when - // a new stream is initialized and by GetAutomaticGainControl(). - agc_is_enabled_ = enabled; -} - void AudioInputDevice::OnStreamCreated( base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, @@ -287,6 +204,89 @@ void AudioInputDevice::OnDeviceReady(const std::string& device_id) { event_handler_->OnDeviceStarted(device_id); } +AudioInputDevice::~AudioInputDevice() { + // TODO(henrika): The current design requires that the user calls + // Stop before deleting this class. + CHECK_EQ(0, stream_id_); +} + +void AudioInputDevice::InitializeOnIOThread() { + DCHECK(message_loop()->BelongsToCurrentThread()); + // Make sure we don't call Start() more than once. + DCHECK_EQ(0, stream_id_); + if (stream_id_) + return; + + stream_id_ = filter_->AddDelegate(this); + // If |session_id_| is not specified, it will directly create the stream; + // otherwise it will send a AudioInputHostMsg_StartDevice msg to the browser + // and create the stream when getting a OnDeviceReady() callback. + if (!session_id_) { + Send(new AudioInputHostMsg_CreateStream( + stream_id_, audio_parameters_, + media::AudioManagerBase::kDefaultDeviceId, + agc_is_enabled_)); + } else { + Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); + pending_device_ready_ = true; + } +} + +void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { + DCHECK(message_loop()->BelongsToCurrentThread()); + session_id_ = session_id; +} + +void AudioInputDevice::StartOnIOThread() { + DCHECK(message_loop()->BelongsToCurrentThread()); + if (stream_id_) + Send(new AudioInputHostMsg_RecordStream(stream_id_)); +} + +void AudioInputDevice::ShutDownOnIOThread() { + DCHECK(message_loop()->BelongsToCurrentThread()); + // NOTE: |completion| may be NULL. + // Make sure we don't call shutdown more than once. + if (stream_id_) { + filter_->RemoveDelegate(stream_id_); + Send(new AudioInputHostMsg_CloseStream(stream_id_)); + + stream_id_ = 0; + session_id_ = 0; + pending_device_ready_ = false; + agc_is_enabled_ = false; + } + + // We can run into an issue where ShutDownOnIOThread is called right after + // OnStreamCreated is called in cases where Start/Stop are called before we + // get the OnStreamCreated callback. To handle that corner case, we call + // Stop(). In most cases, the thread will already be stopped. + // Another situation is when the IO thread goes away before Stop() is called + // in which case, we cannot use the message loop to close the thread handle + // and can't not rely on the main thread existing either. + base::ThreadRestrictions::ScopedAllowIO allow_io; + audio_thread_.Stop(NULL); + audio_callback_.reset(); +} + +void AudioInputDevice::SetVolumeOnIOThread(double volume) { + DCHECK(message_loop()->BelongsToCurrentThread()); + if (stream_id_) + Send(new AudioInputHostMsg_SetVolume(stream_id_, volume)); +} + +void AudioInputDevice::SetAutomaticGainControlOnIOThread(bool enabled) { + DCHECK(message_loop()->BelongsToCurrentThread()); + DCHECK_EQ(0, stream_id_) << + "The AGC state can not be modified while capturing is active."; + if (stream_id_) + return; + + // We simply store the new AGC setting here. This value will be used when + // a new stream is initialized and by GetAutomaticGainControl(). + agc_is_enabled_ = enabled; +} + void AudioInputDevice::Send(IPC::Message* message) { filter_->Send(message); } diff --git a/content/renderer/media/audio_input_device.h b/content/renderer/media/audio_input_device.h index 787dfad..b6751ee 100644 --- a/content/renderer/media/audio_input_device.h +++ b/content/renderer/media/audio_input_device.h @@ -121,7 +121,6 @@ class CONTENT_EXPORT AudioInputDevice AudioInputDevice(const media::AudioParameters& params, CaptureCallback* callback, CaptureEventHandler* event_handler); - virtual ~AudioInputDevice(); // Specify the |session_id| to query which device to use. This method is // asynchronous/non-blocking. @@ -166,7 +165,12 @@ class CONTENT_EXPORT AudioInputDevice virtual void OnStateChanged(AudioStreamState state) OVERRIDE; virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; + protected: + virtual ~AudioInputDevice(); + private: + friend class base::RefCountedThreadSafe<AudioInputDevice>; + // Methods called on IO thread ---------------------------------------------- // The following methods are tasks posted on the IO thread that needs to // be executed on that thread. They interact with AudioInputMessageFilter and diff --git a/content/renderer/media/audio_input_message_filter.h b/content/renderer/media/audio_input_message_filter.h index a537e70..b2ec1f2 100644 --- a/content/renderer/media/audio_input_message_filter.h +++ b/content/renderer/media/audio_input_message_filter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -20,7 +20,7 @@ #include "media/audio/audio_buffers_state.h" class CONTENT_EXPORT AudioInputMessageFilter - : public IPC::ChannelProxy::MessageFilter { + : public IPC::ChannelProxy::MessageFilter { public: class CONTENT_EXPORT Delegate { public: @@ -46,7 +46,6 @@ class CONTENT_EXPORT AudioInputMessageFilter }; AudioInputMessageFilter(); - virtual ~AudioInputMessageFilter(); // Add a delegate to the map and return id of the entry. int32 AddDelegate(Delegate* delegate); @@ -58,6 +57,8 @@ class CONTENT_EXPORT AudioInputMessageFilter bool Send(IPC::Message* message); private: + virtual ~AudioInputMessageFilter(); + // IPC::ChannelProxy::MessageFilter override. Called on IO thread. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; diff --git a/content/renderer/media/audio_message_filter.cc b/content/renderer/media/audio_message_filter.cc index 4996ea9..65c41f3 100644 --- a/content/renderer/media/audio_message_filter.cc +++ b/content/renderer/media/audio_message_filter.cc @@ -16,8 +16,12 @@ AudioMessageFilter::AudioMessageFilter() VLOG(1) << "AudioMessageFilter::AudioMessageFilter()"; } -AudioMessageFilter::~AudioMessageFilter() { - VLOG(1) << "AudioMessageFilter::~AudioMessageFilter()"; +int32 AudioMessageFilter::AddDelegate(Delegate* delegate) { + return delegates_.Add(delegate); +} + +void AudioMessageFilter::RemoveDelegate(int32 id) { + delegates_.Remove(id); } bool AudioMessageFilter::Send(IPC::Message* message) { @@ -63,6 +67,10 @@ void AudioMessageFilter::OnChannelClosing() { channel_ = NULL; } +AudioMessageFilter::~AudioMessageFilter() { + VLOG(1) << "AudioMessageFilter::~AudioMessageFilter()"; +} + void AudioMessageFilter::OnStreamCreated( int stream_id, base::SharedMemoryHandle handle, @@ -96,11 +104,3 @@ void AudioMessageFilter::OnStreamStateChanged( } delegate->OnStateChanged(state); } - -int32 AudioMessageFilter::AddDelegate(Delegate* delegate) { - return delegates_.Add(delegate); -} - -void AudioMessageFilter::RemoveDelegate(int32 id) { - delegates_.Remove(id); -} diff --git a/content/renderer/media/audio_message_filter.h b/content/renderer/media/audio_message_filter.h index 8df9d3f..40faeab 100644 --- a/content/renderer/media/audio_message_filter.h +++ b/content/renderer/media/audio_message_filter.h @@ -38,7 +38,6 @@ class CONTENT_EXPORT AudioMessageFilter }; AudioMessageFilter(); - virtual ~AudioMessageFilter(); // Add a delegate to the map and return id of the entry. int32 AddDelegate(Delegate* delegate); @@ -49,16 +48,19 @@ class CONTENT_EXPORT AudioMessageFilter // Sends an IPC message using |channel_|. bool Send(IPC::Message* message); - private: - FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Basic); - FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Delegates); - // IPC::ChannelProxy::MessageFilter override. Called on IO thread. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; virtual void OnFilterRemoved() OVERRIDE; virtual void OnChannelClosing() OVERRIDE; + protected: + virtual ~AudioMessageFilter(); + + private: + FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Basic); + FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Delegates); + // Received when browser process has created an audio output stream. void OnStreamCreated(int stream_id, base::SharedMemoryHandle handle, #if defined(OS_WIN) @@ -73,9 +75,6 @@ class CONTENT_EXPORT AudioMessageFilter // changed. void OnStreamStateChanged(int stream_id, AudioStreamState state); - // Notification of volume property of an audio output stream. - void OnStreamVolume(int stream_id, double volume); - // A map of stream ids to delegates. IDMap<Delegate> delegates_; diff --git a/content/renderer/media/capture_video_decoder.cc b/content/renderer/media/capture_video_decoder.cc index 211d0e8..72d2d1ba 100644 --- a/content/renderer/media/capture_video_decoder.cc +++ b/content/renderer/media/capture_video_decoder.cc @@ -31,35 +31,19 @@ CaptureVideoDecoder::CaptureVideoDecoder( DCHECK(vc_manager); } -CaptureVideoDecoder::~CaptureVideoDecoder() {} - -void CaptureVideoDecoder::Initialize( - media::DemuxerStream* demuxer_stream, - const media::PipelineStatusCB& status_cb, - const media::StatisticsCB& statistics_cb) { - message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind(&CaptureVideoDecoder::InitializeOnDecoderThread, - this, make_scoped_refptr(demuxer_stream), - status_cb, statistics_cb)); -} - -void CaptureVideoDecoder::Read(const ReadCB& read_cb) { +void CaptureVideoDecoder::Play(const base::Closure& callback) { message_loop_proxy_->PostTask( FROM_HERE, - base::Bind(&CaptureVideoDecoder::ReadOnDecoderThread, - this, read_cb)); -} - -const gfx::Size& CaptureVideoDecoder::natural_size() { - return natural_size_; + base::Bind(&CaptureVideoDecoder::PlayOnDecoderThread, + this, callback)); } -void CaptureVideoDecoder::Play(const base::Closure& callback) { +void CaptureVideoDecoder::Seek(base::TimeDelta time, + const media::PipelineStatusCB& cb) { message_loop_proxy_->PostTask( FROM_HERE, - base::Bind(&CaptureVideoDecoder::PlayOnDecoderThread, - this, callback)); + base::Bind(&CaptureVideoDecoder::SeekOnDecoderThread, + this, time, cb)); } void CaptureVideoDecoder::Pause(const base::Closure& callback) { @@ -83,12 +67,26 @@ void CaptureVideoDecoder::Stop(const base::Closure& callback) { this, callback)); } -void CaptureVideoDecoder::Seek(base::TimeDelta time, - const media::PipelineStatusCB& cb) { +void CaptureVideoDecoder::Initialize( + media::DemuxerStream* demuxer_stream, + const media::PipelineStatusCB& status_cb, + const media::StatisticsCB& statistics_cb) { message_loop_proxy_->PostTask( FROM_HERE, - base::Bind(&CaptureVideoDecoder::SeekOnDecoderThread, - this, time, cb)); + base::Bind(&CaptureVideoDecoder::InitializeOnDecoderThread, + this, make_scoped_refptr(demuxer_stream), + status_cb, statistics_cb)); +} + +void CaptureVideoDecoder::Read(const ReadCB& read_cb) { + message_loop_proxy_->PostTask( + FROM_HERE, + base::Bind(&CaptureVideoDecoder::ReadOnDecoderThread, + this, read_cb)); +} + +const gfx::Size& CaptureVideoDecoder::natural_size() { + return natural_size_; } void CaptureVideoDecoder::OnStarted(media::VideoCapture* capture) { @@ -134,26 +132,7 @@ void CaptureVideoDecoder::OnDeviceInfoReceived( this, capture, device_info)); } -void CaptureVideoDecoder::InitializeOnDecoderThread( - media::DemuxerStream* demuxer_stream, - const media::PipelineStatusCB& status_cb, - const media::StatisticsCB& statistics_cb) { - DVLOG(1) << "InitializeOnDecoderThread"; - DCHECK(message_loop_proxy_->BelongsToCurrentThread()); - - capture_engine_ = vc_manager_->AddDevice(video_stream_id_, this); - - statistics_cb_ = statistics_cb; - status_cb.Run(media::PIPELINE_OK); - state_ = kNormal; - capture_engine_->StartCapture(this, capability_); -} - -void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) { - DCHECK(message_loop_proxy_->BelongsToCurrentThread()); - CHECK(read_cb_.is_null()); - read_cb_ = read_cb; -} +CaptureVideoDecoder::~CaptureVideoDecoder() {} void CaptureVideoDecoder::PlayOnDecoderThread(const base::Closure& callback) { DVLOG(1) << "PlayOnDecoderThread"; @@ -161,6 +140,16 @@ void CaptureVideoDecoder::PlayOnDecoderThread(const base::Closure& callback) { callback.Run(); } +void CaptureVideoDecoder::SeekOnDecoderThread( + base::TimeDelta time, + const media::PipelineStatusCB& cb) { + DVLOG(1) << "SeekOnDecoderThread"; + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); + + cb.Run(media::PIPELINE_OK); + state_ = kNormal; +} + void CaptureVideoDecoder::PauseOnDecoderThread(const base::Closure& callback) { DVLOG(1) << "PauseOnDecoderThread"; DCHECK(message_loop_proxy_->BelongsToCurrentThread()); @@ -188,14 +177,25 @@ void CaptureVideoDecoder::StopOnDecoderThread(const base::Closure& callback) { capture_engine_->StopCapture(this); } -void CaptureVideoDecoder::SeekOnDecoderThread( - base::TimeDelta time, - const media::PipelineStatusCB& cb) { - DVLOG(1) << "SeekOnDecoderThread"; +void CaptureVideoDecoder::InitializeOnDecoderThread( + media::DemuxerStream* demuxer_stream, + const media::PipelineStatusCB& status_cb, + const media::StatisticsCB& statistics_cb) { + DVLOG(1) << "InitializeOnDecoderThread"; DCHECK(message_loop_proxy_->BelongsToCurrentThread()); - cb.Run(media::PIPELINE_OK); + capture_engine_ = vc_manager_->AddDevice(video_stream_id_, this); + + statistics_cb_ = statistics_cb; + status_cb.Run(media::PIPELINE_OK); state_ = kNormal; + capture_engine_->StartCapture(this, capability_); +} + +void CaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& read_cb) { + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); + CHECK(read_cb_.is_null()); + read_cb_ = read_cb; } void CaptureVideoDecoder::OnStoppedOnDecoderThread( diff --git a/content/renderer/media/capture_video_decoder.h b/content/renderer/media/capture_video_decoder.h index d4bbd25..cafd533f 100644 --- a/content/renderer/media/capture_video_decoder.h +++ b/content/renderer/media/capture_video_decoder.h @@ -30,7 +30,6 @@ class CONTENT_EXPORT CaptureVideoDecoder media::VideoCaptureSessionId video_stream_id, VideoCaptureImplManager* vc_manager, const media::VideoCaptureCapability& capability); - virtual ~CaptureVideoDecoder(); // Filter implementation. virtual void Play(const base::Closure& callback) OVERRIDE; @@ -61,6 +60,9 @@ class CONTENT_EXPORT CaptureVideoDecoder media::VideoCapture* capture, const media::VideoCaptureParams& device_info) OVERRIDE; + protected: + virtual ~CaptureVideoDecoder(); + private: friend class CaptureVideoDecoderTest; diff --git a/content/renderer/media/capture_video_decoder_unittest.cc b/content/renderer/media/capture_video_decoder_unittest.cc index dbc869e..c87bd56 100644 --- a/content/renderer/media/capture_video_decoder_unittest.cc +++ b/content/renderer/media/capture_video_decoder_unittest.cc @@ -52,7 +52,6 @@ class MockVideoCaptureImpl : public VideoCaptureImpl { VideoCaptureMessageFilter* filter) : VideoCaptureImpl(id, ml_proxy, filter) { } - virtual ~MockVideoCaptureImpl() {} MOCK_METHOD2(StartCapture, void(media::VideoCapture::EventHandler* handler, @@ -67,7 +66,6 @@ class MockVideoCaptureImpl : public VideoCaptureImpl { class MockVideoCaptureImplManager : public VideoCaptureImplManager { public: MockVideoCaptureImplManager() {} - virtual ~MockVideoCaptureImplManager() {} MOCK_METHOD2(AddDevice, media::VideoCapture*(media::VideoCaptureSessionId id, @@ -76,6 +74,9 @@ class MockVideoCaptureImplManager : public VideoCaptureImplManager { void(media::VideoCaptureSessionId id, media::VideoCapture::EventHandler* handler)); + protected: + virtual ~MockVideoCaptureImplManager() {} + private: DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImplManager); }; diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc index b2502ec..4add708 100644 --- a/content/renderer/media/media_stream_impl.cc +++ b/content/renderer/media/media_stream_impl.cc @@ -75,8 +75,7 @@ static std::string ExtractManagerStreamLabel( return manager_label; } - -int MediaStreamImpl::next_request_id_ = 0; +static int g_next_request_id = 0; MediaStreamImpl::MediaStreamImpl( content::RenderView* render_view, @@ -181,7 +180,7 @@ void MediaStreamImpl::requestUserMedia( UMA_HISTOGRAM_COUNTS_100(kHistogramGetUserMedia, 1); DCHECK(CalledOnValidThread()); DCHECK(!user_media_request.isNull()); - int request_id = next_request_id_++; + int request_id = g_next_request_id++; bool audio = user_media_request.audio(); media_stream::StreamOptions::VideoOption video_option = diff --git a/content/renderer/media/media_stream_impl.h b/content/renderer/media/media_stream_impl.h index c949a64..1cd390b 100644 --- a/content/renderer/media/media_stream_impl.h +++ b/content/renderer/media/media_stream_impl.h @@ -201,7 +201,6 @@ class CONTENT_EXPORT MediaStreamImpl talk_base::Thread* worker_thread_; base::Thread chrome_worker_thread_; - static int next_request_id_; typedef std::map<int, WebKit::WebUserMediaRequest> MediaRequestMap; MediaRequestMap user_media_requests_; diff --git a/content/renderer/media/render_audiosourceprovider.cc b/content/renderer/media/render_audiosourceprovider.cc index 81f99ce..10803f8 100644 --- a/content/renderer/media/render_audiosourceprovider.cc +++ b/content/renderer/media/render_audiosourceprovider.cc @@ -27,7 +27,53 @@ RenderAudioSourceProvider::RenderAudioSourceProvider() default_sink_ = new AudioDevice(); } -RenderAudioSourceProvider::~RenderAudioSourceProvider() {} +void RenderAudioSourceProvider::setClient( + WebKit::WebAudioSourceProviderClient* client) { + // Synchronize with other uses of client_ and default_sink_. + base::AutoLock auto_lock(sink_lock_); + + if (client && client != client_) { + // Detach the audio renderer from normal playback. + default_sink_->Stop(); + + // The client will now take control by calling provideInput() periodically. + client_ = client; + + if (is_initialized_) { + // The client needs to be notified of the audio format, if available. + // If the format is not yet available, we'll be notified later + // when Initialize() is called. + + // Inform WebKit about the audio stream format. + client->setFormat(channels_, sample_rate_); + } + } else if (!client && client_) { + // Restore normal playback. + client_ = NULL; + // TODO(crogers): We should call default_sink_->Play() if we're + // in the playing state. + } +} + +void RenderAudioSourceProvider::provideInput( + const WebVector<float*>& audio_data, size_t number_of_frames) { + DCHECK(client_); + + if (renderer_ && is_initialized_ && is_running_) { + // Wrap WebVector as std::vector. + vector<float*> v(audio_data.size()); + for (size_t i = 0; i < audio_data.size(); ++i) + v[i] = audio_data[i]; + + // TODO(crogers): figure out if we should volume scale here or in common + // WebAudio code. In any case we need to take care of volume. + renderer_->Render(v, number_of_frames, 0); + } else { + // Provide silence if the source is not running. + for (size_t i = 0; i < audio_data.size(); ++i) + memset(audio_data[i], 0, sizeof(float) * number_of_frames); + } +} void RenderAudioSourceProvider::Start() { base::AutoLock auto_lock(sink_lock_); @@ -79,7 +125,8 @@ void RenderAudioSourceProvider::GetVolume(double* volume) { } void RenderAudioSourceProvider::Initialize( - const media::AudioParameters& params, RenderCallback* renderer) { + const media::AudioParameters& params, + RenderCallback* renderer) { base::AutoLock auto_lock(sink_lock_); CHECK(!is_initialized_); renderer_ = renderer; @@ -98,50 +145,4 @@ void RenderAudioSourceProvider::Initialize( is_initialized_ = true; } -void RenderAudioSourceProvider::setClient( - WebKit::WebAudioSourceProviderClient* client) { - // Synchronize with other uses of client_ and default_sink_. - base::AutoLock auto_lock(sink_lock_); - - if (client && client != client_) { - // Detach the audio renderer from normal playback. - default_sink_->Stop(); - - // The client will now take control by calling provideInput() periodically. - client_ = client; - - if (is_initialized_) { - // The client needs to be notified of the audio format, if available. - // If the format is not yet available, we'll be notified later - // when Initialize() is called. - - // Inform WebKit about the audio stream format. - client->setFormat(channels_, sample_rate_); - } - } else if (!client && client_) { - // Restore normal playback. - client_ = NULL; - // TODO(crogers): We should call default_sink_->Play() if we're - // in the playing state. - } -} - -void RenderAudioSourceProvider::provideInput( - const WebVector<float*>& audio_data, size_t number_of_frames) { - DCHECK(client_); - - if (renderer_ && is_initialized_ && is_running_) { - // Wrap WebVector as std::vector. - vector<float*> v(audio_data.size()); - for (size_t i = 0; i < audio_data.size(); ++i) - v[i] = audio_data[i]; - - // TODO(crogers): figure out if we should volume scale here or in common - // WebAudio code. In any case we need to take care of volume. - renderer_->Render(v, number_of_frames, 0); - } else { - // Provide silence if the source is not running. - for (size_t i = 0; i < audio_data.size(); ++i) - memset(audio_data[i], 0, sizeof(float) * number_of_frames); - } -} +RenderAudioSourceProvider::~RenderAudioSourceProvider() {} diff --git a/content/renderer/media/render_audiosourceprovider.h b/content/renderer/media/render_audiosourceprovider.h index f69c99d..ab4510f 100644 --- a/content/renderer/media/render_audiosourceprovider.h +++ b/content/renderer/media/render_audiosourceprovider.h @@ -38,7 +38,6 @@ class RenderAudioSourceProvider public media::AudioRendererSink { public: RenderAudioSourceProvider(); - virtual ~RenderAudioSourceProvider(); // WebKit::WebAudioSourceProvider implementation. @@ -60,8 +59,11 @@ class RenderAudioSourceProvider virtual void SetPlaybackRate(float rate) OVERRIDE; virtual bool SetVolume(double volume) OVERRIDE; virtual void GetVolume(double* volume) OVERRIDE; - virtual void Initialize( - const media::AudioParameters& params, RenderCallback* renderer) OVERRIDE; + virtual void Initialize(const media::AudioParameters& params, + RenderCallback* renderer) OVERRIDE; + + protected: + virtual ~RenderAudioSourceProvider(); private: // Set to true when Initialize() is called. diff --git a/content/renderer/media/rtc_video_decoder.cc b/content/renderer/media/rtc_video_decoder.cc index 42de408..ea15a02 100644 --- a/content/renderer/media/rtc_video_decoder.cc +++ b/content/renderer/media/rtc_video_decoder.cc @@ -36,37 +36,29 @@ RTCVideoDecoder::RTCVideoDecoder(MessageLoop* message_loop, got_first_frame_(false) { } -RTCVideoDecoder::~RTCVideoDecoder() {} - -void RTCVideoDecoder::Initialize(DemuxerStream* demuxer_stream, - const PipelineStatusCB& status_cb, - const StatisticsCB& statistics_cb) { +void RTCVideoDecoder::Play(const base::Closure& callback) { if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( - FROM_HERE, - base::Bind(&RTCVideoDecoder::Initialize, this, - make_scoped_refptr(demuxer_stream), - status_cb, statistics_cb)); + message_loop_->PostTask(FROM_HERE, + base::Bind(&RTCVideoDecoder::Play, this, callback)); return; } DCHECK_EQ(MessageLoop::current(), message_loop_); - state_ = kNormal; - status_cb.Run(PIPELINE_OK); - // TODO(acolwell): Implement stats. + callback.Run(); } -void RTCVideoDecoder::Play(const base::Closure& callback) { +void RTCVideoDecoder::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask(FROM_HERE, - base::Bind(&RTCVideoDecoder::Play, this, callback)); - return; + message_loop_->PostTask(FROM_HERE, + base::Bind(&RTCVideoDecoder::Seek, this, + time, cb)); + return; } DCHECK_EQ(MessageLoop::current(), message_loop_); - - callback.Run(); + state_ = kNormal; + cb.Run(PIPELINE_OK); } void RTCVideoDecoder::Pause(const base::Closure& callback) { @@ -127,17 +119,23 @@ void RTCVideoDecoder::Stop(const base::Closure& callback) { VideoDecoder::Stop(callback); } -void RTCVideoDecoder::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { +void RTCVideoDecoder::Initialize(DemuxerStream* demuxer_stream, + const PipelineStatusCB& status_cb, + const StatisticsCB& statistics_cb) { if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask(FROM_HERE, - base::Bind(&RTCVideoDecoder::Seek, this, - time, cb)); - return; + message_loop_->PostTask( + FROM_HERE, + base::Bind(&RTCVideoDecoder::Initialize, this, + make_scoped_refptr(demuxer_stream), + status_cb, statistics_cb)); + return; } DCHECK_EQ(MessageLoop::current(), message_loop_); state_ = kNormal; - cb.Run(PIPELINE_OK); + status_cb.Run(PIPELINE_OK); + + // TODO(acolwell): Implement stats. } void RTCVideoDecoder::Read(const ReadCB& callback) { @@ -219,3 +217,5 @@ bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) { read_cb.Run(kOk, video_frame); return true; } + +RTCVideoDecoder::~RTCVideoDecoder() {} diff --git a/content/renderer/media/rtc_video_decoder.h b/content/renderer/media/rtc_video_decoder.h index 8d1f9c0..ca615431 100644 --- a/content/renderer/media/rtc_video_decoder.h +++ b/content/renderer/media/rtc_video_decoder.h @@ -28,7 +28,6 @@ class CONTENT_EXPORT RTCVideoDecoder NON_EXPORTED_BASE(public cricket::VideoRenderer) { public: RTCVideoDecoder(MessageLoop* message_loop, const std::string& url); - virtual ~RTCVideoDecoder(); // Filter implementation. virtual void Play(const base::Closure& callback) OVERRIDE; @@ -50,6 +49,9 @@ class CONTENT_EXPORT RTCVideoDecoder virtual bool SetSize(int width, int height, int reserved) OVERRIDE; virtual bool RenderFrame(const cricket::VideoFrame* frame) OVERRIDE; + protected: + virtual ~RTCVideoDecoder(); + private: friend class RTCVideoDecoderTest; FRIEND_TEST_ALL_PREFIXES(RTCVideoDecoderTest, Initialize_Successful); diff --git a/content/renderer/media/video_capture_impl_manager.cc b/content/renderer/media/video_capture_impl_manager.cc index 5b5de3d..46ed2f5 100644 --- a/content/renderer/media/video_capture_impl_manager.cc +++ b/content/renderer/media/video_capture_impl_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,11 +16,6 @@ VideoCaptureImplManager::VideoCaptureImplManager() filter_ = new VideoCaptureMessageFilter(); } -VideoCaptureImplManager::~VideoCaptureImplManager() { - STLDeleteContainerPairSecondPointers(devices_.begin(), devices_.end()); - thread_.Stop(); -} - media::VideoCapture* VideoCaptureImplManager::AddDevice( media::VideoCaptureSessionId id, media::VideoCapture::EventHandler* handler) { @@ -66,6 +61,11 @@ void VideoCaptureImplManager::FreeDevice(VideoCaptureImpl* vc) { delete vc; } +VideoCaptureImplManager::~VideoCaptureImplManager() { + STLDeleteContainerPairSecondPointers(devices_.begin(), devices_.end()); + thread_.Stop(); +} + VideoCaptureImplManager::Device::Device( VideoCaptureImpl* device, media::VideoCapture::EventHandler* handler) diff --git a/content/renderer/media/video_capture_impl_manager.h b/content/renderer/media/video_capture_impl_manager.h index 8427957f..0d3faa5 100644 --- a/content/renderer/media/video_capture_impl_manager.h +++ b/content/renderer/media/video_capture_impl_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -26,7 +26,6 @@ class CONTENT_EXPORT VideoCaptureImplManager : public base::RefCountedThreadSafe<VideoCaptureImplManager> { public: VideoCaptureImplManager(); - virtual ~VideoCaptureImplManager(); // Called by video capture client |handler| to add device referenced // by |id| to VideoCaptureImplManager's list of opened device list. @@ -45,7 +44,12 @@ class CONTENT_EXPORT VideoCaptureImplManager return filter_; } + protected: + virtual ~VideoCaptureImplManager(); + private: + friend class base::RefCountedThreadSafe<VideoCaptureImplManager>; + struct Device { Device(VideoCaptureImpl* device, media::VideoCapture::EventHandler* handler); diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc index 47a76ad..24644e3 100644 --- a/content/renderer/media/video_capture_impl_unittest.cc +++ b/content/renderer/media/video_capture_impl_unittest.cc @@ -20,11 +20,13 @@ using ::testing::Return; class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { public: MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {} - virtual ~MockVideoCaptureMessageFilter() {} // Filter implementation. MOCK_METHOD1(Send, bool(IPC::Message* message)); + protected: + virtual ~MockVideoCaptureMessageFilter() {} + private: DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); }; diff --git a/content/renderer/media/video_capture_message_filter.cc b/content/renderer/media/video_capture_message_filter.cc index 2ec4110..dabbcae 100644 --- a/content/renderer/media/video_capture_message_filter.cc +++ b/content/renderer/media/video_capture_message_filter.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,7 +12,35 @@ VideoCaptureMessageFilter::VideoCaptureMessageFilter() channel_(NULL) { } -VideoCaptureMessageFilter::~VideoCaptureMessageFilter() { +void VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) { + if (++last_device_id_ <= 0) + last_device_id_ = 1; + while (delegates_.find(last_device_id_) != delegates_.end()) + last_device_id_++; + + if (channel_) { + delegates_[last_device_id_] = delegate; + delegate->OnDelegateAdded(last_device_id_); + } else { + pending_delegates_[last_device_id_] = delegate; + } +} + +void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) { + for (Delegates::iterator it = delegates_.begin(); + it != delegates_.end(); it++) { + if (it->second == delegate) { + delegates_.erase(it); + break; + } + } + for (Delegates::iterator it = pending_delegates_.begin(); + it != pending_delegates_.end(); it++) { + if (it->second == delegate) { + pending_delegates_.erase(it); + break; + } + } } bool VideoCaptureMessageFilter::Send(IPC::Message* message) { @@ -58,6 +86,8 @@ void VideoCaptureMessageFilter::OnChannelClosing() { channel_ = NULL; } +VideoCaptureMessageFilter::~VideoCaptureMessageFilter() {} + void VideoCaptureMessageFilter::OnBufferCreated( int device_id, base::SharedMemoryHandle handle, @@ -129,34 +159,3 @@ void VideoCaptureMessageFilter::OnDeviceInfoReceived( } delegate->OnDeviceInfoReceived(params); } - -void VideoCaptureMessageFilter::AddDelegate(Delegate* delegate) { - if (++last_device_id_ <= 0) - last_device_id_ = 1; - while (delegates_.find(last_device_id_) != delegates_.end()) - last_device_id_++; - - if (channel_) { - delegates_[last_device_id_] = delegate; - delegate->OnDelegateAdded(last_device_id_); - } else { - pending_delegates_[last_device_id_] = delegate; - } -} - -void VideoCaptureMessageFilter::RemoveDelegate(Delegate* delegate) { - for (Delegates::iterator it = delegates_.begin(); - it != delegates_.end(); it++) { - if (it->second == delegate) { - delegates_.erase(it); - break; - } - } - for (Delegates::iterator it = pending_delegates_.begin(); - it != pending_delegates_.end(); it++) { - if (it->second == delegate) { - pending_delegates_.erase(it); - break; - } - } -} diff --git a/content/renderer/media/video_capture_message_filter.h b/content/renderer/media/video_capture_message_filter.h index 9edf742..ba597c4 100644 --- a/content/renderer/media/video_capture_message_filter.h +++ b/content/renderer/media/video_capture_message_filter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -49,7 +49,6 @@ class CONTENT_EXPORT VideoCaptureMessageFilter }; VideoCaptureMessageFilter(); - virtual ~VideoCaptureMessageFilter(); // Add a delegate to the map. void AddDelegate(Delegate* delegate); @@ -60,18 +59,21 @@ class CONTENT_EXPORT VideoCaptureMessageFilter // Send a message asynchronously. virtual bool Send(IPC::Message* message); - private: - FRIEND_TEST_ALL_PREFIXES(VideoCaptureMessageFilterTest, Basic); - FRIEND_TEST_ALL_PREFIXES(VideoCaptureMessageFilterTest, Delegates); - - typedef std::map<int32, Delegate*> Delegates; - // IPC::ChannelProxy::MessageFilter override. Called on IO thread. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; virtual void OnFilterRemoved() OVERRIDE; virtual void OnChannelClosing() OVERRIDE; + protected: + virtual ~VideoCaptureMessageFilter(); + + private: + FRIEND_TEST_ALL_PREFIXES(VideoCaptureMessageFilterTest, Basic); + FRIEND_TEST_ALL_PREFIXES(VideoCaptureMessageFilterTest, Delegates); + + typedef std::map<int32, Delegate*> Delegates; + // Receive a newly created buffer from browser process. void OnBufferCreated(int device_id, base::SharedMemoryHandle handle, diff --git a/content/renderer/p2p/p2p_transport_impl_unittest.cc b/content/renderer/p2p/p2p_transport_impl_unittest.cc index 24d6ddc..0022ece 100644 --- a/content/renderer/p2p/p2p_transport_impl_unittest.cc +++ b/content/renderer/p2p/p2p_transport_impl_unittest.cc @@ -58,8 +58,6 @@ class UdpChannelTester : public base::RefCountedThreadSafe<UdpChannelTester> { broken_packets_(0) { } - virtual ~UdpChannelTester() { } - void Start() { message_loop_->PostTask( FROM_HERE, base::Bind(&UdpChannelTester::DoStart, this)); @@ -78,6 +76,9 @@ class UdpChannelTester : public base::RefCountedThreadSafe<UdpChannelTester> { } protected: + friend class base::RefCountedThreadSafe<UdpChannelTester>; + virtual ~UdpChannelTester() {} + void Done() { done_ = true; message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); @@ -199,8 +200,6 @@ class TcpChannelTester : public base::RefCountedThreadSafe<TcpChannelTester> { read_errors_(0) { } - virtual ~TcpChannelTester() { } - void Init() { // Initialize |send_buffer_|. send_buffer_ = new net::DrainableIOBuffer(new net::IOBuffer(kTcpDataSize), @@ -233,6 +232,9 @@ class TcpChannelTester : public base::RefCountedThreadSafe<TcpChannelTester> { } protected: + friend class base::RefCountedThreadSafe<TcpChannelTester>; + virtual ~TcpChannelTester() {} + void Done() { done_ = true; message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); diff --git a/content/renderer/p2p/socket_dispatcher.cc b/content/renderer/p2p/socket_dispatcher.cc index 4e90471..4317725 100644 --- a/content/renderer/p2p/socket_dispatcher.cc +++ b/content/renderer/p2p/socket_dispatcher.cc @@ -34,6 +34,9 @@ class P2PSocketDispatcher::AsyncMessageSender } private: + friend class base::RefCountedThreadSafe<AsyncMessageSender>; + ~AsyncMessageSender() {} + void DoSend(IPC::Message* msg) { DCHECK(message_loop_->BelongsToCurrentThread()); if (message_sender_) diff --git a/content/renderer/pepper/pepper_platform_audio_input_impl.cc b/content/renderer/pepper/pepper_platform_audio_input_impl.cc index c69d562..effcf2a 100644 --- a/content/renderer/pepper/pepper_platform_audio_input_impl.cc +++ b/content/renderer/pepper/pepper_platform_audio_input_impl.cc @@ -16,26 +16,6 @@ namespace content { -PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl() - : client_(NULL), - stream_id_(0), - main_message_loop_proxy_(base::MessageLoopProxy::current()), - shutdown_called_(false) { - filter_ = RenderThreadImpl::current()->audio_input_message_filter(); -} - -PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { - // Make sure we have been shut down. Warning: this may happen on the I/O - // thread! - // Although these members should be accessed on a specific thread (either the - // main thread or the I/O thread), it should be fine to examine their value - // here. - DCHECK_EQ(0, stream_id_); - DCHECK(!client_); - DCHECK(label_.empty()); - DCHECK(shutdown_called_); -} - // static PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create( const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, @@ -81,6 +61,83 @@ void PepperPlatformAudioInputImpl::ShutDown() { base::Bind(&PepperPlatformAudioInputImpl::ShutDownOnIOThread, this)); } +void PepperPlatformAudioInputImpl::OnStreamCreated( + base::SharedMemoryHandle handle, + base::SyncSocket::Handle socket_handle, + uint32 length) { +#if defined(OS_WIN) + DCHECK(handle); + DCHECK(socket_handle); +#else + DCHECK_NE(-1, handle.fd); + DCHECK_NE(-1, socket_handle); +#endif + DCHECK(length); + + if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { + // No need to check |shutdown_called_| here. If shutdown has occurred, + // |client_| will be NULL and the handles will be cleaned up on the main + // thread. + main_message_loop_proxy_->PostTask( + FROM_HERE, + base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, + handle, socket_handle, length)); + } else { + // Must dereference the client only on the main thread. Shutdown may have + // occurred while the request was in-flight, so we need to NULL check. + if (client_) { + client_->StreamCreated(handle, length, socket_handle); + } else { + // Clean up the handles. + base::SyncSocket temp_socket(socket_handle); + base::SharedMemory temp_shared_memory(handle, false); + } + } +} + +void PepperPlatformAudioInputImpl::OnVolume(double volume) {} + +void PepperPlatformAudioInputImpl::OnStateChanged(AudioStreamState state) {} + +void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) { + DCHECK(ChildProcess::current()->io_message_loop_proxy()-> + BelongsToCurrentThread()); + + if (shutdown_called_) + return; + + if (device_id.empty()) { + main_message_loop_proxy_->PostTask( + FROM_HERE, + base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, + this)); + } else { + // We will be notified by OnStreamCreated(). + filter_->Send(new AudioInputHostMsg_CreateStream(stream_id_, params_, + device_id, false)); + } +} + +PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { + // Make sure we have been shut down. Warning: this may happen on the I/O + // thread! + // Although these members should be accessed on a specific thread (either the + // main thread or the I/O thread), it should be fine to examine their value + // here. + DCHECK_EQ(0, stream_id_); + DCHECK(!client_); + DCHECK(label_.empty()); + DCHECK(shutdown_called_); +} + +PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl() + : client_(NULL), + stream_id_(0), + main_message_loop_proxy_(base::MessageLoopProxy::current()), + shutdown_called_(false) { + filter_ = RenderThreadImpl::current()->audio_input_message_filter(); +} + bool PepperPlatformAudioInputImpl::Initialize( const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, const std::string& device_id, @@ -177,65 +234,6 @@ void PepperPlatformAudioInputImpl::ShutDownOnIOThread() { // PepperPluginDelegateImpl::CreateAudioInput. } -void PepperPlatformAudioInputImpl::OnStreamCreated( - base::SharedMemoryHandle handle, - base::SyncSocket::Handle socket_handle, - uint32 length) { -#if defined(OS_WIN) - DCHECK(handle); - DCHECK(socket_handle); -#else - DCHECK_NE(-1, handle.fd); - DCHECK_NE(-1, socket_handle); -#endif - DCHECK(length); - - if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { - // No need to check |shutdown_called_| here. If shutdown has occurred, - // |client_| will be NULL and the handles will be cleaned up on the main - // thread. - main_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, - handle, socket_handle, length)); - } else { - // Must dereference the client only on the main thread. Shutdown may have - // occurred while the request was in-flight, so we need to NULL check. - if (client_) { - client_->StreamCreated(handle, length, socket_handle); - } else { - // Clean up the handles. - base::SyncSocket temp_socket(socket_handle); - base::SharedMemory temp_shared_memory(handle, false); - } - } -} - -void PepperPlatformAudioInputImpl::OnVolume(double volume) { -} - -void PepperPlatformAudioInputImpl::OnStateChanged(AudioStreamState state) { -} - -void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) { - DCHECK(ChildProcess::current()->io_message_loop_proxy()-> - BelongsToCurrentThread()); - - if (shutdown_called_) - return; - - if (device_id.empty()) { - main_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, - this)); - } else { - // We will be notified by OnStreamCreated(). - filter_->Send(new AudioInputHostMsg_CreateStream(stream_id_, params_, - device_id, false)); - } -} - void PepperPlatformAudioInputImpl::OnDeviceOpened(int request_id, bool succeeded, const std::string& label) { diff --git a/content/renderer/pepper/pepper_platform_audio_input_impl.h b/content/renderer/pepper/pepper_platform_audio_input_impl.h index 4117fe4..6b6c3b41 100644 --- a/content/renderer/pepper/pepper_platform_audio_input_impl.h +++ b/content/renderer/pepper/pepper_platform_audio_input_impl.h @@ -36,8 +36,6 @@ class PepperPlatformAudioInputImpl public AudioInputMessageFilter::Delegate, public base::RefCountedThreadSafe<PepperPlatformAudioInputImpl> { public: - virtual ~PepperPlatformAudioInputImpl(); - // Factory function, returns NULL on failure. StreamCreated() will be called // when the stream is created. static PepperPlatformAudioInputImpl* Create( @@ -52,7 +50,20 @@ class PepperPlatformAudioInputImpl virtual void StopCapture() OVERRIDE; virtual void ShutDown() OVERRIDE; + // AudioInputMessageFilter::Delegate. + virtual void OnStreamCreated(base::SharedMemoryHandle handle, + base::SyncSocket::Handle socket_handle, + uint32 length) OVERRIDE; + virtual void OnVolume(double volume) OVERRIDE; + virtual void OnStateChanged(AudioStreamState state) OVERRIDE; + virtual void OnDeviceReady(const std::string&) OVERRIDE; + + protected: + virtual ~PepperPlatformAudioInputImpl(); + private: + friend class base::RefCountedThreadSafe<PepperPlatformAudioInputImpl>; + PepperPlatformAudioInputImpl(); bool Initialize( @@ -68,14 +79,6 @@ class PepperPlatformAudioInputImpl void StopCaptureOnIOThread(); void ShutDownOnIOThread(); - // AudioInputMessageFilter::Delegate. - virtual void OnStreamCreated(base::SharedMemoryHandle handle, - base::SyncSocket::Handle socket_handle, - uint32 length) OVERRIDE; - virtual void OnVolume(double volume) OVERRIDE; - virtual void OnStateChanged(AudioStreamState state) OVERRIDE; - virtual void OnDeviceReady(const std::string&) OVERRIDE; - void OnDeviceOpened(int request_id, bool succeeded, const std::string& label); diff --git a/content/renderer/pepper/pepper_platform_audio_output_impl.cc b/content/renderer/pepper/pepper_platform_audio_output_impl.cc index 84ae082..65239e6 100644 --- a/content/renderer/pepper/pepper_platform_audio_output_impl.cc +++ b/content/renderer/pepper/pepper_platform_audio_output_impl.cc @@ -15,20 +15,6 @@ namespace content { -PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl() - : client_(NULL), - stream_id_(0), - main_message_loop_proxy_(base::MessageLoopProxy::current()) { - filter_ = RenderThreadImpl::current()->audio_message_filter(); -} - -PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() { - // Make sure we have been shut down. Warning: this will usually happen on - // the I/O thread! - DCHECK_EQ(0, stream_id_); - DCHECK(!client_); -} - // static PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( int sample_rate, @@ -75,6 +61,47 @@ void PepperPlatformAudioOutputImpl::ShutDown() { base::Bind(&PepperPlatformAudioOutputImpl::ShutDownOnIOThread, this)); } +void PepperPlatformAudioOutputImpl::OnStateChanged(AudioStreamState state) {} + +void PepperPlatformAudioOutputImpl::OnStreamCreated( + base::SharedMemoryHandle handle, + base::SyncSocket::Handle socket_handle, + uint32 length) { +#if defined(OS_WIN) + DCHECK(handle); + DCHECK(socket_handle); +#else + DCHECK_NE(-1, handle.fd); + DCHECK_NE(-1, socket_handle); +#endif + DCHECK(length); + + if (base::MessageLoopProxy::current() == main_message_loop_proxy_) { + // Must dereference the client only on the main thread. Shutdown may have + // occurred while the request was in-flight, so we need to NULL check. + if (client_) + client_->StreamCreated(handle, length, socket_handle); + } else { + main_message_loop_proxy_->PostTask(FROM_HERE, + base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, + handle, socket_handle, length)); + } +} + +PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() { + // Make sure we have been shut down. Warning: this will usually happen on + // the I/O thread! + DCHECK_EQ(0, stream_id_); + DCHECK(!client_); +} + +PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl() + : client_(NULL), + stream_id_(0), + main_message_loop_proxy_(base::MessageLoopProxy::current()) { + filter_ = RenderThreadImpl::current()->audio_message_filter(); +} + bool PepperPlatformAudioOutputImpl::Initialize( int sample_rate, int frames_per_buffer, @@ -136,32 +163,4 @@ void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() { // PepperPluginDelegateImpl::CreateAudio. } -void PepperPlatformAudioOutputImpl::OnStateChanged(AudioStreamState state) { -} - -void PepperPlatformAudioOutputImpl::OnStreamCreated( - base::SharedMemoryHandle handle, - base::SyncSocket::Handle socket_handle, - uint32 length) { -#if defined(OS_WIN) - DCHECK(handle); - DCHECK(socket_handle); -#else - DCHECK_NE(-1, handle.fd); - DCHECK_NE(-1, socket_handle); -#endif - DCHECK(length); - - if (base::MessageLoopProxy::current() == main_message_loop_proxy_) { - // Must dereference the client only on the main thread. Shutdown may have - // occurred while the request was in-flight, so we need to NULL check. - if (client_) - client_->StreamCreated(handle, length, socket_handle); - } else { - main_message_loop_proxy_->PostTask(FROM_HERE, - base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, - handle, socket_handle, length)); - } -} - } // namespace content diff --git a/content/renderer/pepper/pepper_platform_audio_output_impl.h b/content/renderer/pepper/pepper_platform_audio_output_impl.h index 6ad8b80..3b426ad 100644 --- a/content/renderer/pepper/pepper_platform_audio_output_impl.h +++ b/content/renderer/pepper/pepper_platform_audio_output_impl.h @@ -25,8 +25,6 @@ class PepperPlatformAudioOutputImpl public AudioMessageFilter::Delegate, public base::RefCountedThreadSafe<PepperPlatformAudioOutputImpl> { public: - virtual ~PepperPlatformAudioOutputImpl(); - // Factory function, returns NULL on failure. StreamCreated() will be called // when the stream is created. static PepperPlatformAudioOutputImpl* Create( @@ -39,7 +37,18 @@ class PepperPlatformAudioOutputImpl virtual bool StopPlayback() OVERRIDE; virtual void ShutDown() OVERRIDE; + // AudioMessageFilter::Delegate. + virtual void OnStateChanged(AudioStreamState state) OVERRIDE; + virtual void OnStreamCreated(base::SharedMemoryHandle handle, + base::SyncSocket::Handle socket_handle, + uint32 length) OVERRIDE; + + protected: + virtual ~PepperPlatformAudioOutputImpl(); + private: + friend class base::RefCountedThreadSafe<PepperPlatformAudioOutputImpl>; + PepperPlatformAudioOutputImpl(); bool Initialize( @@ -53,12 +62,6 @@ class PepperPlatformAudioOutputImpl void StopPlaybackOnIOThread(); void ShutDownOnIOThread(); - // AudioMessageFilter::Delegate. - virtual void OnStateChanged(AudioStreamState state) OVERRIDE; - virtual void OnStreamCreated(base::SharedMemoryHandle handle, - base::SyncSocket::Handle socket_handle, - uint32 length) OVERRIDE; - // The client to notify when the stream is created. THIS MUST ONLY BE // ACCESSED ON THE MAIN THREAD. webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client_; diff --git a/content/renderer/pepper/pepper_platform_video_capture_impl.cc b/content/renderer/pepper/pepper_platform_video_capture_impl.cc index c688d3d..35bfd58 100644 --- a/content/renderer/pepper/pepper_platform_video_capture_impl.cc +++ b/content/renderer/pepper/pepper_platform_video_capture_impl.cc @@ -42,17 +42,6 @@ PepperPlatformVideoCaptureImpl::PepperPlatformVideoCaptureImpl( } } -PepperPlatformVideoCaptureImpl::~PepperPlatformVideoCaptureImpl() { - if (video_capture_) { - VideoCaptureImplManager* manager = - RenderThreadImpl::current()->video_capture_impl_manager(); - manager->RemoveDevice(session_id_, handler_proxy_.get()); - } - - if (plugin_delegate_ && !label_.empty()) - plugin_delegate_->CloseDevice(label_); -} - void PepperPlatformVideoCaptureImpl::StartCapture( media::VideoCapture::EventHandler* handler, const media::VideoCaptureCapability& capability) { @@ -155,6 +144,17 @@ void PepperPlatformVideoCaptureImpl::OnDeviceInfoReceived( handler_->OnDeviceInfoReceived(capture, device_info); } +PepperPlatformVideoCaptureImpl::~PepperPlatformVideoCaptureImpl() { + if (video_capture_) { + VideoCaptureImplManager* manager = + RenderThreadImpl::current()->video_capture_impl_manager(); + manager->RemoveDevice(session_id_, handler_proxy_.get()); + } + + if (plugin_delegate_ && !label_.empty()) + plugin_delegate_->CloseDevice(label_); +} + void PepperPlatformVideoCaptureImpl::Initialize() { VideoCaptureImplManager* manager = RenderThreadImpl::current()->video_capture_impl_manager(); diff --git a/content/renderer/pepper/pepper_platform_video_capture_impl.h b/content/renderer/pepper/pepper_platform_video_capture_impl.h index 02fe6ab..a4fe0df 100644 --- a/content/renderer/pepper/pepper_platform_video_capture_impl.h +++ b/content/renderer/pepper/pepper_platform_video_capture_impl.h @@ -32,7 +32,6 @@ class PepperPlatformVideoCaptureImpl const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, const std::string& device_id, webkit::ppapi::PluginDelegate::PlatformVideoCaptureEventHandler* handler); - virtual ~PepperPlatformVideoCaptureImpl(); // webkit::ppapi::PluginDelegate::PlatformVideoCapture implementation. virtual void StartCapture( @@ -58,6 +57,9 @@ class PepperPlatformVideoCaptureImpl VideoCapture* capture, const media::VideoCaptureParams& device_info) OVERRIDE; + protected: + virtual ~PepperPlatformVideoCaptureImpl(); + private: void Initialize(); diff --git a/content/renderer/plugin_channel_host.cc b/content/renderer/plugin_channel_host.cc index e055852..f9f384e 100644 --- a/content/renderer/plugin_channel_host.cc +++ b/content/renderer/plugin_channel_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -29,6 +29,9 @@ class IsListeningFilter : public IPC::ChannelProxy::MessageFilter { static bool is_listening_; + protected: + virtual ~IsListeningFilter() {} + private: IPC::Channel* channel_; diff --git a/content/renderer/render_widget_fullscreen.cc b/content/renderer/render_widget_fullscreen.cc index 7916889..7030e5d 100644 --- a/content/renderer/render_widget_fullscreen.cc +++ b/content/renderer/render_widget_fullscreen.cc @@ -18,21 +18,6 @@ RenderWidgetFullscreen* RenderWidgetFullscreen::Create(int32 opener_id) { return widget.release(); } -WebWidget* RenderWidgetFullscreen::CreateWebWidget() { - // TODO(boliu): Handle full screen render widgets here. - return RenderWidget::CreateWebWidget(this); -} - -void RenderWidgetFullscreen::Init(int32 opener_id) { - DCHECK(!webwidget_); - - RenderWidget::DoInit( - opener_id, - CreateWebWidget(), - new ViewHostMsg_CreateFullscreenWidget( - opener_id, &routing_id_, &surface_id_)); -} - void RenderWidgetFullscreen::show(WebKit::WebNavigationPolicy) { DCHECK(!did_show_) << "received extraneous Show call"; DCHECK_NE(MSG_ROUTING_NONE, routing_id_); @@ -48,3 +33,20 @@ void RenderWidgetFullscreen::show(WebKit::WebNavigationPolicy) { RenderWidgetFullscreen::RenderWidgetFullscreen() : RenderWidget(WebKit::WebPopupTypeNone, WebKit::WebScreenInfo()) { } + +RenderWidgetFullscreen::~RenderWidgetFullscreen() {} + +WebWidget* RenderWidgetFullscreen::CreateWebWidget() { + // TODO(boliu): Handle full screen render widgets here. + return RenderWidget::CreateWebWidget(this); +} + +void RenderWidgetFullscreen::Init(int32 opener_id) { + DCHECK(!webwidget_); + + RenderWidget::DoInit( + opener_id, + CreateWebWidget(), + new ViewHostMsg_CreateFullscreenWidget( + opener_id, &routing_id_, &surface_id_)); +} diff --git a/content/renderer/render_widget_fullscreen.h b/content/renderer/render_widget_fullscreen.h index bfb04f7..99c6e56 100644 --- a/content/renderer/render_widget_fullscreen.h +++ b/content/renderer/render_widget_fullscreen.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,8 +19,10 @@ class RenderWidgetFullscreen : public RenderWidget { virtual void show(WebKit::WebNavigationPolicy); protected: - virtual WebKit::WebWidget* CreateWebWidget(); RenderWidgetFullscreen(); + virtual ~RenderWidgetFullscreen(); + + virtual WebKit::WebWidget* CreateWebWidget(); void Init(int32 opener_id); }; diff --git a/content/renderer/renderer_main.cc b/content/renderer/renderer_main.cc index ae7a8a4..07d5313 100644 --- a/content/renderer/renderer_main.cc +++ b/content/renderer/renderer_main.cc @@ -74,7 +74,9 @@ void InstallFrameworkHacks() { #if defined(OS_POSIX) class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { - void OnChannelError() { + public: + // IPC::ChannelProxy::MessageFilter + virtual void OnChannelError() OVERRIDE { // On POSIX, at least, one can install an unload handler which loops // forever and leave behind a renderer process which eats 100% CPU forever. // @@ -101,6 +103,9 @@ class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { #endif _exit(0); } + + protected: + virtual ~SuicideOnChannelErrorFilter() {} }; #endif // OS(POSIX) |