Commit 32eadb44 authored by miu@chromium.org's avatar miu@chromium.org

Impose PowerSaveBlock while remoting content via Cast or WebRTC.

BUG=400552

Review URL: https://codereview.chromium.org/448953002

Cr-Commit-Position: refs/heads/master@{#288380}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288380 0039d316-1c4b-4281-b951-d872f2087c98
parent acb4e9e2
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_net_log.h"
#include "content/public/browser/power_save_blocker.h"
#include "media/cast/net/cast_transport_sender.h" #include "media/cast/net/cast_transport_sender.h"
namespace { namespace {
...@@ -83,6 +84,14 @@ void CastTransportHostFilter::SendCastMessage( ...@@ -83,6 +84,14 @@ void CastTransportHostFilter::SendCastMessage(
void CastTransportHostFilter::OnNew( void CastTransportHostFilter::OnNew(
int32 channel_id, int32 channel_id,
const net::IPEndPoint& remote_end_point) { const net::IPEndPoint& remote_end_point) {
if (!power_save_blocker_) {
DVLOG(1) << ("Preventing the application from being suspended while one or "
"more transports are active for Cast Streaming.");
power_save_blocker_ = content::PowerSaveBlocker::Create(
content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
"Cast is streaming content to a remote receiver.").Pass();
}
if (id_map_.Lookup(channel_id)) { if (id_map_.Lookup(channel_id)) {
id_map_.Remove(channel_id); id_map_.Remove(channel_id);
} }
...@@ -112,6 +121,13 @@ void CastTransportHostFilter::OnDelete(int32 channel_id) { ...@@ -112,6 +121,13 @@ void CastTransportHostFilter::OnDelete(int32 channel_id) {
DVLOG(1) << "CastTransportHostFilter::Delete called " DVLOG(1) << "CastTransportHostFilter::Delete called "
<< "on non-existing channel"; << "on non-existing channel";
} }
if (id_map_.IsEmpty()) {
DVLOG_IF(1, power_save_blocker_) <<
("Releasing the block on application suspension since no transports "
"are active anymore for Cast Streaming.");
power_save_blocker_.reset();
}
} }
void CastTransportHostFilter::OnInitializeAudio( void CastTransportHostFilter::OnInitializeAudio(
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_MEDIA_CAST_TRANSPORT_HOST_FILTER_H_ #define CHROME_BROWSER_MEDIA_CAST_TRANSPORT_HOST_FILTER_H_
#include "base/id_map.h" #include "base/id_map.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/default_tick_clock.h" #include "base/time/default_tick_clock.h"
#include "chrome/common/cast_messages.h" #include "chrome/common/cast_messages.h"
...@@ -14,6 +15,10 @@ ...@@ -14,6 +15,10 @@
#include "media/cast/logging/logging_defines.h" #include "media/cast/logging/logging_defines.h"
#include "media/cast/net/cast_transport_sender.h" #include "media/cast/net/cast_transport_sender.h"
namespace content {
class PowerSaveBlocker;
} // namespace content
namespace cast { namespace cast {
class CastTransportHostFilter : public content::BrowserMessageFilter { class CastTransportHostFilter : public content::BrowserMessageFilter {
...@@ -76,6 +81,11 @@ class CastTransportHostFilter : public content::BrowserMessageFilter { ...@@ -76,6 +81,11 @@ class CastTransportHostFilter : public content::BrowserMessageFilter {
// Clock used by Cast transport. // Clock used by Cast transport.
base::DefaultTickClock clock_; base::DefaultTickClock clock_;
// While |id_map_| is non-empty, hold an instance of
// content::PowerSaveBlocker. This prevents Chrome from being suspended while
// remoting content.
scoped_ptr<content::PowerSaveBlocker> power_save_blocker_;
base::WeakPtrFactory<CastTransportHostFilter> weak_factory_; base::WeakPtrFactory<CastTransportHostFilter> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(CastTransportHostFilter); DISALLOW_COPY_AND_ASSIGN(CastTransportHostFilter);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.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/render_process_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -82,6 +83,7 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id, ...@@ -82,6 +83,7 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id,
dict->SetString("constraints", constraints); dict->SetString("constraints", constraints);
dict->SetString("url", url); dict->SetString("url", url);
peer_connection_data_.Append(dict); peer_connection_data_.Append(dict);
CreateOrReleasePowerSaveBlocker();
if (observers_.might_have_observers()) if (observers_.might_have_observers())
SendUpdate("addPeerConnection", dict); SendUpdate("addPeerConnection", dict);
...@@ -102,6 +104,7 @@ void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { ...@@ -102,6 +104,7 @@ void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) {
continue; continue;
peer_connection_data_.Remove(i, NULL); peer_connection_data_.Remove(i, NULL);
CreateOrReleasePowerSaveBlocker();
if (observers_.might_have_observers()) { if (observers_.might_have_observers()) {
base::DictionaryValue id; base::DictionaryValue id;
...@@ -263,6 +266,7 @@ void WebRTCInternals::ResetForTesting() { ...@@ -263,6 +266,7 @@ void WebRTCInternals::ResetForTesting() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
observers_.Clear(); observers_.Clear();
peer_connection_data_.Clear(); peer_connection_data_.Clear();
CreateOrReleasePowerSaveBlocker();
get_user_media_requests_.Clear(); get_user_media_requests_.Clear();
aec_dump_enabled_ = false; aec_dump_enabled_ = false;
} }
...@@ -299,6 +303,8 @@ void WebRTCInternals::FileSelectionCanceled(void* params) { ...@@ -299,6 +303,8 @@ void WebRTCInternals::FileSelectionCanceled(void* params) {
} }
void WebRTCInternals::OnRendererExit(int render_process_id) { void WebRTCInternals::OnRendererExit(int render_process_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Iterates from the end of the list to remove the PeerConnections created // Iterates from the end of the list to remove the PeerConnections created
// by the exitting renderer. // by the exitting renderer.
for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) {
...@@ -322,6 +328,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) { ...@@ -322,6 +328,7 @@ void WebRTCInternals::OnRendererExit(int render_process_id) {
peer_connection_data_.Remove(i, NULL); peer_connection_data_.Remove(i, NULL);
} }
} }
CreateOrReleasePowerSaveBlocker();
bool found_any = false; bool found_any = false;
// Iterates from the end of the list to remove the getUserMedia requests // Iterates from the end of the list to remove the getUserMedia requests
...@@ -357,4 +364,20 @@ void WebRTCInternals::EnableAecDumpOnAllRenderProcessHosts() { ...@@ -357,4 +364,20 @@ void WebRTCInternals::EnableAecDumpOnAllRenderProcessHosts() {
} }
#endif #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 } // namespace content
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ #define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/process/process.h" #include "base/process/process.h"
...@@ -16,6 +17,8 @@ ...@@ -16,6 +17,8 @@
#include "ui/shell_dialogs/select_file_dialog.h" #include "ui/shell_dialogs/select_file_dialog.h"
namespace content { namespace content {
class PowerSaveBlocker;
class WebContents; class WebContents;
class WebRTCInternalsUIObserver; class WebRTCInternalsUIObserver;
...@@ -131,6 +134,11 @@ class CONTENT_EXPORT WebRTCInternals : public NotificationObserver, ...@@ -131,6 +134,11 @@ class CONTENT_EXPORT WebRTCInternals : public NotificationObserver,
void EnableAecDumpOnAllRenderProcessHosts(); void EnableAecDumpOnAllRenderProcessHosts();
#endif #endif
// Called whenever an element is added to or removed from
// |peer_connection_data_| to impose/release a block on suspending the current
// application for power-saving.
void CreateOrReleasePowerSaveBlocker();
ObserverList<WebRTCInternalsUIObserver> observers_; ObserverList<WebRTCInternalsUIObserver> observers_;
// |peer_connection_data_| is a list containing all the PeerConnection // |peer_connection_data_| is a list containing all the PeerConnection
...@@ -166,6 +174,11 @@ class CONTENT_EXPORT WebRTCInternals : public NotificationObserver, ...@@ -166,6 +174,11 @@ class CONTENT_EXPORT WebRTCInternals : public NotificationObserver,
// AEC dump (diagnostic echo canceller recording) state. // AEC dump (diagnostic echo canceller recording) state.
bool aec_dump_enabled_; bool aec_dump_enabled_;
base::FilePath aec_dump_file_path_; base::FilePath aec_dump_file_path_;
// While |peer_connection_data_| is non-empty, hold an instance of
// PowerSaveBlocker. This prevents the application from being suspended while
// remoting.
scoped_ptr<PowerSaveBlocker> power_save_blocker_;
}; };
} // namespace content } // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment