Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Unified Diff: content/browser/media/session/media_session_service_impl.cc

Issue 2715723002: Fix a crash in MediaSessionServiceImpl due to life time issue (Closed)
Patch Set: addressed nits Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/media/session/media_session_service_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/media/session/media_session_service_impl.cc
diff --git a/content/browser/media/session/media_session_service_impl.cc b/content/browser/media/session/media_session_service_impl.cc
index 1d93af395a1768bfd000c226d51b0d862230ebf8..cf452e2204df634b8f8e29dc8b873006c40c9484 100644
--- a/content/browser/media/session/media_session_service_impl.cc
+++ b/content/browser/media/session/media_session_service_impl.cc
@@ -8,13 +8,15 @@
#include "content/browser/media/session/media_session_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
namespace content {
MediaSessionServiceImpl::MediaSessionServiceImpl(
RenderFrameHost* render_frame_host)
- : render_frame_host_(render_frame_host),
+ : render_frame_process_id_(render_frame_host->GetProcess()->GetID()),
+ render_frame_routing_id_(render_frame_host->GetRoutingID()),
playback_state_(blink::mojom::MediaSessionPlaybackState::NONE) {
MediaSessionImpl* session = GetMediaSession();
if (session)
@@ -36,6 +38,11 @@ void MediaSessionServiceImpl::Create(
impl->Bind(std::move(request));
}
+RenderFrameHost* MediaSessionServiceImpl::GetRenderFrameHost() {
+ return RenderFrameHost::FromID(render_frame_process_id_,
+ render_frame_routing_id_);
+}
+
void MediaSessionServiceImpl::SetClient(
blink::mojom::MediaSessionClientPtr client) {
client_ = std::move(client);
@@ -55,8 +62,11 @@ void MediaSessionServiceImpl::SetMetadata(
// coming from a known and secure source. It must be processed accordingly.
if (metadata.has_value() &&
!MediaMetadataSanitizer::CheckSanity(metadata.value())) {
- render_frame_host_->GetProcess()->ShutdownForBadMessage(
- RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP);
+ RenderFrameHost* rfh = GetRenderFrameHost();
+ if (rfh) {
+ rfh->GetProcess()->ShutdownForBadMessage(
+ RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP);
+ }
return;
}
metadata_ = metadata;
@@ -83,10 +93,15 @@ void MediaSessionServiceImpl::DisableAction(
}
MediaSessionImpl* MediaSessionServiceImpl::GetMediaSession() {
- WebContentsImpl* contents = static_cast<WebContentsImpl*>(
- WebContentsImpl::FromRenderFrameHost(render_frame_host_));
+ RenderFrameHost* rfh = GetRenderFrameHost();
+ if (!rfh)
+ return nullptr;
+
+ WebContentsImpl* contents =
+ static_cast<WebContentsImpl*>(WebContentsImpl::FromRenderFrameHost(rfh));
if (!contents)
return nullptr;
+
return MediaSessionImpl::Get(contents);
}
« no previous file with comments | « content/browser/media/session/media_session_service_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698