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

Unified Diff: content/browser/media/webrtc_internals.cc

Issue 448953002: Impose PowerSaveBlock while remoting content via Cast or WebRTC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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/webrtc_internals.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/webrtc_internals.cc
diff --git a/content/browser/media/webrtc_internals.cc b/content/browser/media/webrtc_internals.cc
index 09f0e5a0ed42f3d5ef16820f7c2afbf3bb612297..92ca83cc2f4b393dc81e0123d6a648cb10ddae7a 100644
--- a/content/browser/media/webrtc_internals.cc
+++ b/content/browser/media/webrtc_internals.cc
@@ -12,6 +12,7 @@
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/power_save_blocker.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
@@ -82,6 +83,7 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id,
dict->SetString("constraints", constraints);
dict->SetString("url", url);
peer_connection_data_.Append(dict);
+ CreateOrReleasePowerSaveBlocker();
if (observers_.might_have_observers())
SendUpdate("addPeerConnection", dict);
@@ -102,6 +104,7 @@ void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) {
continue;
peer_connection_data_.Remove(i, NULL);
+ CreateOrReleasePowerSaveBlocker();
if (observers_.might_have_observers()) {
base::DictionaryValue id;
@@ -263,6 +266,7 @@ void WebRTCInternals::ResetForTesting() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
observers_.Clear();
peer_connection_data_.Clear();
+ CreateOrReleasePowerSaveBlocker();
get_user_media_requests_.Clear();
aec_dump_enabled_ = false;
}
@@ -299,6 +303,8 @@ void WebRTCInternals::FileSelectionCanceled(void* params) {
}
void WebRTCInternals::OnRendererExit(int render_process_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
// Iterates from the end of the list to remove the PeerConnections created
// by the exitting renderer.
for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) {
@@ -322,6 +328,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) {
peer_connection_data_.Remove(i, NULL);
}
}
+ CreateOrReleasePowerSaveBlocker();
bool found_any = false;
// Iterates from the end of the list to remove the getUserMedia requests
@@ -357,4 +364,20 @@ void WebRTCInternals::EnableAecDumpOnAllRenderProcessHosts() {
}
#endif
+void WebRTCInternals::CreateOrReleasePowerSaveBlocker() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (peer_connection_data_.empty() && power_save_blocker_) {
+ DVLOG(1) << ("Releasing the block on application suspension since no "
+ "PeerConnections are active anymore.");
+ power_save_blocker_.reset();
+ } else if (!peer_connection_data_.empty() && !power_save_blocker_) {
+ DVLOG(1) << ("Preventing the application from being suspended while one or "
+ "more PeerConnections are active.");
+ power_save_blocker_ = content::PowerSaveBlocker::Create(
+ content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
+ "WebRTC has active PeerConnections.").Pass();
+ }
+}
+
} // namespace content
« no previous file with comments | « content/browser/media/webrtc_internals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698