summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorvrk@chromium.org <vrk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-16 08:05:21 +0000
committervrk@chromium.org <vrk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-16 08:05:21 +0000
commit90f278b66807ee818b2d74901986bd811ca5972d (patch)
treec7e104922a1f983f5b774b8c4d2dbb5eba5abf3c /content
parent15b3273671027e0ed5324eccc10688bfc9623d8b (diff)
downloadchromium_src-90f278b66807ee818b2d74901986bd811ca5972d.zip
chromium_src-90f278b66807ee818b2d74901986bd811ca5972d.tar.gz
chromium_src-90f278b66807ee818b2d74901986bd811ca5972d.tar.bz2
Close all active PeerConnections upon OS suspend
BUG=403618 Review URL: https://codereview.chromium.org/465153003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290125 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/media/peer_connection_tracker_host.cc18
-rw-r--r--content/browser/renderer_host/media/peer_connection_tracker_host.h12
-rw-r--r--content/common/media/peer_connection_tracker_messages.h1
-rw-r--r--content/renderer/media/peer_connection_tracker.cc8
-rw-r--r--content/renderer/media/peer_connection_tracker.h3
5 files changed, 38 insertions, 4 deletions
diff --git a/content/browser/renderer_host/media/peer_connection_tracker_host.cc b/content/browser/renderer_host/media/peer_connection_tracker_host.cc
index ac863e7..a88d5c4 100644
--- a/content/browser/renderer_host/media/peer_connection_tracker_host.cc
+++ b/content/browser/renderer_host/media/peer_connection_tracker_host.cc
@@ -3,14 +3,20 @@
// found in the LICENSE file.
#include "content/browser/renderer_host/media/peer_connection_tracker_host.h"
+#include "base/power_monitor/power_monitor.h"
#include "content/browser/media/webrtc_internals.h"
#include "content/common/media/peer_connection_tracker_messages.h"
+#include "content/public/browser/render_process_host.h"
namespace content {
PeerConnectionTrackerHost::PeerConnectionTrackerHost(int render_process_id)
: BrowserMessageFilter(PeerConnectionTrackerMsgStart),
- render_process_id_(render_process_id) {}
+ render_process_id_(render_process_id) {
+ base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
+ if (power_monitor)
+ power_monitor->AddObserver(this);
+}
bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
@@ -36,6 +42,9 @@ void PeerConnectionTrackerHost::OverrideThreadForMessage(
}
PeerConnectionTrackerHost::~PeerConnectionTrackerHost() {
+ base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
+ if (power_monitor)
+ power_monitor->RemoveObserver(this);
}
void PeerConnectionTrackerHost::OnAddPeerConnection(
@@ -82,4 +91,11 @@ void PeerConnectionTrackerHost::OnGetUserMedia(
video_constraints);
}
+void PeerConnectionTrackerHost::OnSuspend() {
+ content::RenderProcessHost* host =
+ content::RenderProcessHost::FromID(render_process_id_);
+ CHECK(host);
+ host->Send(new PeerConnectionTracker_OnSuspend());
+}
+
} // namespace content
diff --git a/content/browser/renderer_host/media/peer_connection_tracker_host.h b/content/browser/renderer_host/media/peer_connection_tracker_host.h
index 6a411e8..d5cfc83 100644
--- a/content/browser/renderer_host/media/peer_connection_tracker_host.h
+++ b/content/browser/renderer_host/media/peer_connection_tracker_host.h
@@ -5,6 +5,7 @@
#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_PEER_CONNECTION_TRACKER_HOST_H_
#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_PEER_CONNECTION_TRACKER_HOST_H_
+#include "base/power_monitor/power_observer.h"
#include "content/public/browser/browser_message_filter.h"
struct PeerConnectionInfo;
@@ -16,9 +17,11 @@ class ListValue;
namespace content {
// This class is the host for PeerConnectionTracker in the browser process
-// managed by RenderProcessHostImpl. It passes IPC messages between
-// WebRTCInternals and PeerConnectionTracker.
-class PeerConnectionTrackerHost : public BrowserMessageFilter {
+// managed by RenderProcessHostImpl. It receives PeerConnection events from
+// PeerConnectionTracker as IPC messages that it forwards to WebRTCInternals.
+// It also forwards browser process events to PeerConnectionTracker via IPC.
+class PeerConnectionTrackerHost : public BrowserMessageFilter,
+ public base::PowerObserver {
public:
PeerConnectionTrackerHost(int render_process_id);
@@ -27,6 +30,9 @@ class PeerConnectionTrackerHost : public BrowserMessageFilter {
virtual void OverrideThreadForMessage(const IPC::Message& message,
BrowserThread::ID* thread) OVERRIDE;
+ // base::PowerObserver override.
+ virtual void OnSuspend() OVERRIDE;
+
protected:
virtual ~PeerConnectionTrackerHost();
diff --git a/content/common/media/peer_connection_tracker_messages.h b/content/common/media/peer_connection_tracker_messages.h
index dd2051c..e476ee1 100644
--- a/content/common/media/peer_connection_tracker_messages.h
+++ b/content/common/media/peer_connection_tracker_messages.h
@@ -40,3 +40,4 @@ IPC_MESSAGE_CONTROL5(PeerConnectionTrackerHost_GetUserMedia,
// Messages sent to PeerConnectionTracker.
IPC_MESSAGE_CONTROL0(PeerConnectionTracker_GetAllStats)
+IPC_MESSAGE_CONTROL0(PeerConnectionTracker_OnSuspend);
diff --git a/content/renderer/media/peer_connection_tracker.cc b/content/renderer/media/peer_connection_tracker.cc
index 5aac78c..5476f11 100644
--- a/content/renderer/media/peer_connection_tracker.cc
+++ b/content/renderer/media/peer_connection_tracker.cc
@@ -278,6 +278,7 @@ bool PeerConnectionTracker::OnControlMessageReceived(
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PeerConnectionTracker, message)
IPC_MESSAGE_HANDLER(PeerConnectionTracker_GetAllStats, OnGetAllStats)
+ IPC_MESSAGE_HANDLER(PeerConnectionTracker_OnSuspend, OnSuspend)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -297,6 +298,13 @@ void PeerConnectionTracker::OnGetAllStats() {
}
}
+void PeerConnectionTracker::OnSuspend() {
+ for (PeerConnectionIdMap::iterator it = peer_connection_id_map_.begin();
+ it != peer_connection_id_map_.end(); ++it) {
+ it->first->stop();
+ }
+}
+
void PeerConnectionTracker::RegisterPeerConnection(
RTCPeerConnectionHandler* pc_handler,
const webrtc::PeerConnectionInterface::RTCConfiguration& config,
diff --git a/content/renderer/media/peer_connection_tracker.h b/content/renderer/media/peer_connection_tracker.h
index 76607d7..9d5129d 100644
--- a/content/renderer/media/peer_connection_tracker.h
+++ b/content/renderer/media/peer_connection_tracker.h
@@ -161,6 +161,9 @@ class CONTENT_EXPORT PeerConnectionTracker : public RenderProcessObserver {
// IPC Message handler for getting all stats.
void OnGetAllStats();
+ // Called when the browser process reports a suspend event from the OS.
+ void OnSuspend();
+
void SendPeerConnectionUpdate(RTCPeerConnectionHandler* pc_handler,
const std::string& callback_type,
const std::string& value);