Commit 22c91cc2 authored by braveyao's avatar braveyao Committed by Commit bot

Android: move peerconnection out of power observer.

Currently when screen is off (or Chrome goes to background) for more than 1 min,
peerconnection will be stoppted by PowerMonitor to save battery power. This is
not necesary now since we'll suspend video call when the tab is background. And
users prefer that audio call can continue while they are doing something else.

BUG=513633

Review-Url: https://codereview.chromium.org/2263373003
Cr-Commit-Position: refs/heads/master@{#415372}
parent 41dca1f3
...@@ -376,10 +376,15 @@ RenderThread* PeerConnectionTracker::SendTarget() { ...@@ -376,10 +376,15 @@ RenderThread* PeerConnectionTracker::SendTarget() {
void PeerConnectionTracker::OnSuspend() { void PeerConnectionTracker::OnSuspend() {
DCHECK(main_thread_.CalledOnValidThread()); DCHECK(main_thread_.CalledOnValidThread());
// On Android 'Suspend' means more of the activity state. So it's better to
// keep the webrtc call session when user is doing something else or screen
// is off.
#if !defined(OS_ANDROID)
for (PeerConnectionIdMap::iterator it = peer_connection_id_map_.begin(); for (PeerConnectionIdMap::iterator it = peer_connection_id_map_.begin();
it != peer_connection_id_map_.end(); ++it) { it != peer_connection_id_map_.end(); ++it) {
it->first->CloseClientPeerConnection(); it->first->CloseClientPeerConnection();
} }
#endif
} }
void PeerConnectionTracker::OnStartEventLog(int peer_connection_id, void PeerConnectionTracker::OnStartEventLog(int peer_connection_id,
......
...@@ -44,6 +44,7 @@ bool MockSendTargetThread::OnMessageReceived(const IPC::Message& msg) { ...@@ -44,6 +44,7 @@ bool MockSendTargetThread::OnMessageReceived(const IPC::Message& msg) {
class MockPeerConnectionHandler : public RTCPeerConnectionHandler { class MockPeerConnectionHandler : public RTCPeerConnectionHandler {
public: public:
MockPeerConnectionHandler() : RTCPeerConnectionHandler(&client_, nullptr) {} MockPeerConnectionHandler() : RTCPeerConnectionHandler(&client_, nullptr) {}
MOCK_METHOD0(CloseClientPeerConnection, void());
private: private:
MockWebRTCPeerConnectionHandlerClient client_; MockWebRTCPeerConnectionHandlerClient client_;
...@@ -77,6 +78,26 @@ TEST(PeerConnectionTrackerTest, TrackCreateOffer) { ...@@ -77,6 +78,26 @@ TEST(PeerConnectionTrackerTest, TrackCreateOffer) {
tracker.TrackCreateOffer(&pc_handler, options); tracker.TrackCreateOffer(&pc_handler, options);
} }
TEST(PeerConnectionTrackerTest, OnSuspend) {
PeerConnectionTracker tracker;
// Initialization stuff.
MockPeerConnectionHandler pc_handler;
MockSendTargetThread target_thread;
webrtc::PeerConnectionInterface::RTCConfiguration config;
blink::WebMediaConstraints constraints;
tracker.OverrideSendTargetForTesting(&target_thread);
EXPECT_CALL(target_thread, OnAddPeerConnection(_));
tracker.RegisterPeerConnection(&pc_handler, config, constraints, nullptr);
// Back to the test.
#if defined(OS_ANDROID)
EXPECT_CALL(pc_handler, CloseClientPeerConnection()).Times(0);
#else
EXPECT_CALL(pc_handler, CloseClientPeerConnection());
#endif
std::unique_ptr<IPC::Message> message(new PeerConnectionTracker_OnSuspend());
tracker.OnControlMessageReceived(*message.get());
}
// TODO(hta): Write tests for the other tracking functions. // TODO(hta): Write tests for the other tracking functions.
} // namespace } // namespace
...@@ -165,7 +165,8 @@ class CONTENT_EXPORT RTCPeerConnectionHandler ...@@ -165,7 +165,8 @@ class CONTENT_EXPORT RTCPeerConnectionHandler
blink::WebMediaStreamSource::Type track_type); blink::WebMediaStreamSource::Type track_type);
// Tells the |client_| to close RTCPeerConnection. // Tells the |client_| to close RTCPeerConnection.
void CloseClientPeerConnection(); // Make it virtual for testing purpose.
virtual void CloseClientPeerConnection();
// Start recording an event log. // Start recording an event log.
void StartEventLog(IPC::PlatformFileForTransit file, void StartEventLog(IPC::PlatformFileForTransit file,
......
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