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

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

Issue 2886603003: Convert //content/browser/webrtc to be clients of WakeLock mojo service. (Closed)
Patch Set: Addressed chfremer@'s review comments Created 3 years, 7 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/webrtc/webrtc_internals.h ('k') | content/browser/webrtc/webrtc_internals_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/webrtc/webrtc_internals.cc
diff --git a/content/browser/webrtc/webrtc_internals.cc b/content/browser/webrtc/webrtc_internals.cc
index 376cb139d2470bc4e5041f11c375920c4536c421..933d0a39f04301b83d75910c65b00700e13c739b 100644
--- a/content/browser/webrtc/webrtc_internals.cc
+++ b/content/browser/webrtc/webrtc_internals.cc
@@ -17,10 +17,13 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/web_contents.h"
-#include "device/power_save_blocker/power_save_blocker.h"
+#include "content/public/common/service_manager_connection.h"
+#include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h"
#include "ipc/ipc_platform_file.h"
#include "media/audio/audio_manager.h"
#include "media/media_features.h"
+#include "services/device/public/interfaces/constants.mojom.h"
+#include "services/service_manager/public/cpp/connector.h"
#if defined(OS_WIN)
#define IntToStringType base::IntToString16
@@ -146,7 +149,7 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id,
peer_connection_data_.Append(std::move(dict));
++num_open_connections_;
- CreateOrReleasePowerSaveBlocker();
+ UpdateWakeLock();
if (render_process_id_set_.insert(render_process_id).second) {
RenderProcessHost* host = RenderProcessHost::FromID(render_process_id);
@@ -464,7 +467,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) {
peer_connection_data_.Remove(i, NULL);
}
}
- CreateOrReleasePowerSaveBlocker();
+ UpdateWakeLock();
bool found_any = false;
// Iterates from the end of the list to remove the getUserMedia requests
@@ -534,30 +537,49 @@ void WebRTCInternals::MaybeClosePeerConnection(base::DictionaryValue* record) {
record->SetBoolean("isOpen", false);
--num_open_connections_;
DCHECK_GE(num_open_connections_, 0);
- CreateOrReleasePowerSaveBlocker();
+ UpdateWakeLock();
}
-void WebRTCInternals::CreateOrReleasePowerSaveBlocker() {
+void WebRTCInternals::UpdateWakeLock() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!should_block_power_saving_)
return;
- 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 (num_open_connections_ != 0 && !power_save_blocker_) {
+ if (num_open_connections_ == 0) {
+ DVLOG(1)
+ << ("Cancel the wake lock on application suspension since no "
+ "PeerConnections are active anymore.");
+ GetWakeLockService()->CancelWakeLock();
+ } else if (num_open_connections_ != 0) {
DVLOG(1) << ("Preventing the application from being suspended while one or "
"more PeerConnections are active.");
- power_save_blocker_.reset(new device::PowerSaveBlocker(
- device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
- device::PowerSaveBlocker::kReasonOther,
- "WebRTC has active PeerConnections",
- BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
- BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)));
+ GetWakeLockService()->RequestWakeLock();
}
}
+device::mojom::WakeLockService* WebRTCInternals::GetWakeLockService() {
+ // Here is a lazy binding, and will not reconnect after connection error.
+ if (!wake_lock_service_) {
+ device::mojom::WakeLockServiceRequest request =
+ mojo::MakeRequest(&wake_lock_service_);
+ // In some testing contexts, the service manager connection isn't
+ // initialized.
+ if (ServiceManagerConnection::GetForProcess()) {
+ service_manager::Connector* connector =
+ ServiceManagerConnection::GetForProcess()->GetConnector();
+ DCHECK(connector);
+ device::mojom::WakeLockProviderPtr wake_lock_provider;
+ connector->BindInterface(device::mojom::kServiceName,
+ mojo::MakeRequest(&wake_lock_provider));
+ wake_lock_provider->GetWakeLockWithoutContext(
+ device::mojom::WakeLockType::PreventAppSuspension,
+ device::mojom::WakeLockReason::ReasonOther,
+ "WebRTC has active PeerConnections", std::move(request));
+ }
+ }
+ return wake_lock_service_.get();
+}
+
void WebRTCInternals::ProcessPendingUpdates() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
while (!pending_updates_.empty()) {
« no previous file with comments | « content/browser/webrtc/webrtc_internals.h ('k') | content/browser/webrtc/webrtc_internals_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698