Commit 3a2cf7d1 authored by dmichael's avatar dmichael Committed by Commit bot

Pepper: Access PepperMediaDeviceManager through a WeakPtr

Its lifetime is scoped to the RenderFrame, and it might go away before the
hosts that refer to it.

BUG=423030

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

Cr-Commit-Position: refs/heads/master@{#299897}
parent 20f2492c
...@@ -46,6 +46,7 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest ...@@ -46,6 +46,7 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest
// EnumerateDevicesCallbackBody() to ensure that we always call |callback| // EnumerateDevicesCallbackBody() to ensure that we always call |callback|
// asynchronously. // asynchronously.
sync_call_ = true; sync_call_ = true;
DCHECK(owner_->delegate_);
request_id_ = owner_->delegate_->EnumerateDevices( request_id_ = owner_->delegate_->EnumerateDevices(
owner_->device_type_, owner_->device_type_,
owner_->document_url_, owner_->document_url_,
...@@ -54,7 +55,7 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest ...@@ -54,7 +55,7 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest
} }
~ScopedRequest() { ~ScopedRequest() {
if (requested_) { if (requested_ && owner_->delegate_) {
owner_->delegate_->StopEnumerateDevices(request_id_); owner_->delegate_->StopEnumerateDevices(request_id_);
} }
} }
...@@ -91,7 +92,7 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest ...@@ -91,7 +92,7 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest
PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper(
ppapi::host::ResourceHost* resource_host, ppapi::host::ResourceHost* resource_host,
Delegate* delegate, base::WeakPtr<Delegate> delegate,
PP_DeviceType_Dev device_type, PP_DeviceType_Dev device_type,
const GURL& document_url) const GURL& document_url)
: resource_host_(resource_host), : resource_host_(resource_host),
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "ppapi/c/dev/ppb_device_ref_dev.h" #include "ppapi/c/dev/ppb_device_ref_dev.h"
#include "ppapi/host/host_message_context.h" #include "ppapi/host/host_message_context.h"
...@@ -58,7 +59,7 @@ class CONTENT_EXPORT PepperDeviceEnumerationHostHelper { ...@@ -58,7 +59,7 @@ class CONTENT_EXPORT PepperDeviceEnumerationHostHelper {
// |resource_host| and |delegate| must outlive this object. // |resource_host| and |delegate| must outlive this object.
PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost* resource_host, PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost* resource_host,
Delegate* delegate, base::WeakPtr<Delegate> delegate,
PP_DeviceType_Dev device_type, PP_DeviceType_Dev device_type,
const GURL& document_url); const GURL& document_url);
~PepperDeviceEnumerationHostHelper(); ~PepperDeviceEnumerationHostHelper();
...@@ -93,7 +94,7 @@ class CONTENT_EXPORT PepperDeviceEnumerationHostHelper { ...@@ -93,7 +94,7 @@ class CONTENT_EXPORT PepperDeviceEnumerationHostHelper {
// Non-owning pointers. // Non-owning pointers.
ppapi::host::ResourceHost* resource_host_; ppapi::host::ResourceHost* resource_host_;
Delegate* delegate_; base::WeakPtr<Delegate> delegate_;
PP_DeviceType_Dev device_type_; PP_DeviceType_Dev device_type_;
GURL document_url_; GURL document_url_;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/host/host_message_context.h" #include "ppapi/host/host_message_context.h"
...@@ -24,7 +25,8 @@ namespace content { ...@@ -24,7 +25,8 @@ namespace content {
namespace { namespace {
class TestDelegate : public PepperDeviceEnumerationHostHelper::Delegate { class TestDelegate : public PepperDeviceEnumerationHostHelper::Delegate,
public base::SupportsWeakPtr<TestDelegate> {
public: public:
TestDelegate() : last_used_id_(0) {} TestDelegate() : last_used_id_(0) {}
...@@ -76,7 +78,7 @@ class PepperDeviceEnumerationHostHelperTest : public testing::Test { ...@@ -76,7 +78,7 @@ class PepperDeviceEnumerationHostHelperTest : public testing::Test {
: ppapi_host_(&sink_, ppapi::PpapiPermissions()), : ppapi_host_(&sink_, ppapi::PpapiPermissions()),
resource_host_(&ppapi_host_, 12345, 67890), resource_host_(&ppapi_host_, 12345, 67890),
device_enumeration_(&resource_host_, device_enumeration_(&resource_host_,
&delegate_, delegate_.AsWeakPtr(),
PP_DEVICETYPE_DEV_AUDIOCAPTURE, PP_DEVICETYPE_DEV_AUDIOCAPTURE,
GURL("http://example.com")) {} GURL("http://example.com")) {}
......
...@@ -25,13 +25,14 @@ ppapi::DeviceRefData FromStreamDeviceInfo(const StreamDeviceInfo& info) { ...@@ -25,13 +25,14 @@ ppapi::DeviceRefData FromStreamDeviceInfo(const StreamDeviceInfo& info) {
} // namespace } // namespace
PepperMediaDeviceManager* PepperMediaDeviceManager::GetForRenderFrame( base::WeakPtr<PepperMediaDeviceManager>
PepperMediaDeviceManager::GetForRenderFrame(
RenderFrame* render_frame) { RenderFrame* render_frame) {
PepperMediaDeviceManager* handler = PepperMediaDeviceManager* handler =
PepperMediaDeviceManager::Get(render_frame); PepperMediaDeviceManager::Get(render_frame);
if (!handler) if (!handler)
handler = new PepperMediaDeviceManager(render_frame); handler = new PepperMediaDeviceManager(render_frame);
return handler; return handler->AsWeakPtr();
} }
PepperMediaDeviceManager::PepperMediaDeviceManager(RenderFrame* render_frame) PepperMediaDeviceManager::PepperMediaDeviceManager(RenderFrame* render_frame)
......
...@@ -23,7 +23,8 @@ class PepperMediaDeviceManager ...@@ -23,7 +23,8 @@ class PepperMediaDeviceManager
public RenderFrameObserverTracker<PepperMediaDeviceManager>, public RenderFrameObserverTracker<PepperMediaDeviceManager>,
public base::SupportsWeakPtr<PepperMediaDeviceManager> { public base::SupportsWeakPtr<PepperMediaDeviceManager> {
public: public:
static PepperMediaDeviceManager* GetForRenderFrame(RenderFrame* render_frame); static base::WeakPtr<PepperMediaDeviceManager> GetForRenderFrame(
RenderFrame* render_frame);
virtual ~PepperMediaDeviceManager(); virtual ~PepperMediaDeviceManager();
// PepperDeviceEnumerationHostHelper::Delegate implementation: // PepperDeviceEnumerationHostHelper::Delegate implementation:
......
...@@ -289,7 +289,7 @@ PepperMediaDeviceManager* PepperPlatformAudioInput::GetMediaDeviceManager() { ...@@ -289,7 +289,7 @@ PepperMediaDeviceManager* PepperPlatformAudioInput::GetMediaDeviceManager() {
RenderFrameImpl* const render_frame = RenderFrameImpl* const render_frame =
RenderFrameImpl::FromRoutingID(render_frame_id_); RenderFrameImpl::FromRoutingID(render_frame_id_);
return render_frame ? return render_frame ?
PepperMediaDeviceManager::GetForRenderFrame(render_frame) : NULL; PepperMediaDeviceManager::GetForRenderFrame(render_frame).get() : NULL;
} }
} // namespace content } // namespace content
...@@ -152,7 +152,7 @@ PepperMediaDeviceManager* PepperPlatformVideoCapture::GetMediaDeviceManager() { ...@@ -152,7 +152,7 @@ PepperMediaDeviceManager* PepperPlatformVideoCapture::GetMediaDeviceManager() {
RenderFrameImpl* const render_frame = RenderFrameImpl* const render_frame =
RenderFrameImpl::FromRoutingID(render_frame_id_); RenderFrameImpl::FromRoutingID(render_frame_id_);
return render_frame ? return render_frame ?
PepperMediaDeviceManager::GetForRenderFrame(render_frame) : NULL; PepperMediaDeviceManager::GetForRenderFrame(render_frame).get() : NULL;
} }
} // namespace content } // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment