OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #include "content/browser/renderer_host/media/peer_connection_tracker_host.h" | 4 #include "content/browser/renderer_host/media/peer_connection_tracker_host.h" |
5 | 5 |
| 6 #include "base/power_monitor/power_monitor.h" |
6 #include "content/browser/media/webrtc_internals.h" | 7 #include "content/browser/media/webrtc_internals.h" |
7 #include "content/common/media/peer_connection_tracker_messages.h" | 8 #include "content/common/media/peer_connection_tracker_messages.h" |
| 9 #include "content/public/browser/render_process_host.h" |
8 | 10 |
9 namespace content { | 11 namespace content { |
10 | 12 |
11 PeerConnectionTrackerHost::PeerConnectionTrackerHost(int render_process_id) | 13 PeerConnectionTrackerHost::PeerConnectionTrackerHost(int render_process_id) |
12 : BrowserMessageFilter(PeerConnectionTrackerMsgStart), | 14 : BrowserMessageFilter(PeerConnectionTrackerMsgStart), |
13 render_process_id_(render_process_id) {} | 15 render_process_id_(render_process_id) { |
| 16 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 17 if (power_monitor) |
| 18 power_monitor->AddObserver(this); |
| 19 } |
14 | 20 |
15 bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message) { | 21 bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message) { |
16 bool handled = true; | 22 bool handled = true; |
17 | 23 |
18 IPC_BEGIN_MESSAGE_MAP(PeerConnectionTrackerHost, message) | 24 IPC_BEGIN_MESSAGE_MAP(PeerConnectionTrackerHost, message) |
19 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection, | 25 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection, |
20 OnAddPeerConnection) | 26 OnAddPeerConnection) |
21 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_RemovePeerConnection, | 27 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_RemovePeerConnection, |
22 OnRemovePeerConnection) | 28 OnRemovePeerConnection) |
23 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_UpdatePeerConnection, | 29 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_UpdatePeerConnection, |
24 OnUpdatePeerConnection) | 30 OnUpdatePeerConnection) |
25 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddStats, OnAddStats) | 31 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddStats, OnAddStats) |
26 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_GetUserMedia, OnGetUserMedia) | 32 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_GetUserMedia, OnGetUserMedia) |
27 IPC_MESSAGE_UNHANDLED(handled = false) | 33 IPC_MESSAGE_UNHANDLED(handled = false) |
28 IPC_END_MESSAGE_MAP() | 34 IPC_END_MESSAGE_MAP() |
29 return handled; | 35 return handled; |
30 } | 36 } |
31 | 37 |
32 void PeerConnectionTrackerHost::OverrideThreadForMessage( | 38 void PeerConnectionTrackerHost::OverrideThreadForMessage( |
33 const IPC::Message& message, BrowserThread::ID* thread) { | 39 const IPC::Message& message, BrowserThread::ID* thread) { |
34 if (IPC_MESSAGE_CLASS(message) == PeerConnectionTrackerMsgStart) | 40 if (IPC_MESSAGE_CLASS(message) == PeerConnectionTrackerMsgStart) |
35 *thread = BrowserThread::UI; | 41 *thread = BrowserThread::UI; |
36 } | 42 } |
37 | 43 |
38 PeerConnectionTrackerHost::~PeerConnectionTrackerHost() { | 44 PeerConnectionTrackerHost::~PeerConnectionTrackerHost() { |
| 45 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 46 if (power_monitor) |
| 47 power_monitor->RemoveObserver(this); |
39 } | 48 } |
40 | 49 |
41 void PeerConnectionTrackerHost::OnAddPeerConnection( | 50 void PeerConnectionTrackerHost::OnAddPeerConnection( |
42 const PeerConnectionInfo& info) { | 51 const PeerConnectionInfo& info) { |
43 WebRTCInternals::GetInstance()->OnAddPeerConnection( | 52 WebRTCInternals::GetInstance()->OnAddPeerConnection( |
44 render_process_id_, | 53 render_process_id_, |
45 peer_pid(), | 54 peer_pid(), |
46 info.lid, | 55 info.lid, |
47 info.url, | 56 info.url, |
48 info.rtc_configuration, | 57 info.rtc_configuration, |
(...skipping 26 matching lines...) Expand all Loading... |
75 const std::string& video_constraints) { | 84 const std::string& video_constraints) { |
76 WebRTCInternals::GetInstance()->OnGetUserMedia(render_process_id_, | 85 WebRTCInternals::GetInstance()->OnGetUserMedia(render_process_id_, |
77 peer_pid(), | 86 peer_pid(), |
78 origin, | 87 origin, |
79 audio, | 88 audio, |
80 video, | 89 video, |
81 audio_constraints, | 90 audio_constraints, |
82 video_constraints); | 91 video_constraints); |
83 } | 92 } |
84 | 93 |
| 94 void PeerConnectionTrackerHost::OnSuspend() { |
| 95 content::RenderProcessHost* host = |
| 96 content::RenderProcessHost::FromID(render_process_id_); |
| 97 if (host) |
| 98 host->Send(new PeerConnectionTracker_OnSuspend()); |
| 99 } |
| 100 |
85 } // namespace content | 101 } // namespace content |
OLD | NEW |