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

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

Issue 2502413002: Release PowerSaveBlock on PeerConnection stop instead of removal (Closed)
Patch Set: Created 4 years, 1 month 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
Index: content/browser/webrtc/webrtc_internals.cc
diff --git a/content/browser/webrtc/webrtc_internals.cc b/content/browser/webrtc/webrtc_internals.cc
index 3d3250ec96537a0d0a8eb17162c6534a38d878ce..ec73946549cda033402aee228c7ddb1b8d796a04 100644
--- a/content/browser/webrtc/webrtc_internals.cc
+++ b/content/browser/webrtc/webrtc_internals.cc
@@ -79,6 +79,7 @@ WebRTCInternals::WebRTCInternals(int aggregate_updates_ms,
: audio_debug_recordings_(false),
event_log_recordings_(false),
selecting_event_log_(false),
+ num_open_connections_(0),
should_block_power_saving_(should_block_power_saving),
aggregate_updates_ms_(aggregate_updates_ms),
weak_factory_(this) {
@@ -127,11 +128,13 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id,
dict->SetString("rtcConfiguration", rtc_configuration);
dict->SetString("constraints", constraints);
dict->SetString("url", url);
+ dict->SetBoolean("isOpen", true);
if (observers_.might_have_observers())
SendUpdate("addPeerConnection", dict->CreateDeepCopy());
peer_connection_data_.Append(std::move(dict));
+ ++num_open_connections_;
CreateOrReleasePowerSaveBlocker();
if (render_process_id_set_.insert(render_process_id).second) {
@@ -155,8 +158,8 @@ void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) {
if (this_pid != static_cast<int>(pid) || this_lid != lid)
continue;
+ MaybeClosePeerConnection(dict);
peer_connection_data_.Remove(i, NULL);
- CreateOrReleasePowerSaveBlocker();
if (observers_.might_have_observers()) {
std::unique_ptr<base::DictionaryValue> id(new base::DictionaryValue());
@@ -183,6 +186,10 @@ void WebRTCInternals::OnUpdatePeerConnection(
if (this_pid != static_cast<int>(pid) || this_lid != lid)
continue;
+ if (type == "stop") {
+ MaybeClosePeerConnection(record);
+ }
+
// Append the update to the end of the log.
base::ListValue* log = EnsureLogList(record);
if (!log)
@@ -502,16 +509,29 @@ void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() {
}
#endif
+void WebRTCInternals::MaybeClosePeerConnection(base::DictionaryValue* record) {
+ bool is_open;
+ bool did_read = record->GetBoolean("isOpen", &is_open);
+ DCHECK(did_read);
+ if (!is_open)
+ return;
+
+ record->SetBoolean("isOpen", false);
+ --num_open_connections_;
+ DCHECK_GE(num_open_connections_, 0);
+ CreateOrReleasePowerSaveBlocker();
+}
+
void WebRTCInternals::CreateOrReleasePowerSaveBlocker() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!should_block_power_saving_)
return;
- if (peer_connection_data_.empty() && power_save_blocker_) {
+ if (num_open_connections_ == 0 && 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_) {
+ } else if (num_open_connections_ != 0 && !power_save_blocker_) {
DVLOG(1) << ("Preventing the application from being suspended while one or "
"more PeerConnections are active.");
power_save_blocker_.reset(new device::PowerSaveBlocker(

Powered by Google App Engine
This is Rietveld 408576698