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 } |
14 | 17 |
15 bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message) { | 18 bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message) { |
16 bool handled = true; | 19 bool handled = true; |
17 | 20 |
18 IPC_BEGIN_MESSAGE_MAP(PeerConnectionTrackerHost, message) | 21 IPC_BEGIN_MESSAGE_MAP(PeerConnectionTrackerHost, message) |
19 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection, | 22 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection, |
20 OnAddPeerConnection) | 23 OnAddPeerConnection) |
21 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_RemovePeerConnection, | 24 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_RemovePeerConnection, |
22 OnRemovePeerConnection) | 25 OnRemovePeerConnection) |
23 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_UpdatePeerConnection, | 26 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_UpdatePeerConnection, |
24 OnUpdatePeerConnection) | 27 OnUpdatePeerConnection) |
25 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddStats, OnAddStats) | 28 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddStats, OnAddStats) |
26 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_GetUserMedia, OnGetUserMedia) | 29 IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_GetUserMedia, OnGetUserMedia) |
27 IPC_MESSAGE_UNHANDLED(handled = false) | 30 IPC_MESSAGE_UNHANDLED(handled = false) |
28 IPC_END_MESSAGE_MAP() | 31 IPC_END_MESSAGE_MAP() |
29 return handled; | 32 return handled; |
30 } | 33 } |
31 | 34 |
32 void PeerConnectionTrackerHost::OverrideThreadForMessage( | 35 void PeerConnectionTrackerHost::OverrideThreadForMessage( |
33 const IPC::Message& message, BrowserThread::ID* thread) { | 36 const IPC::Message& message, BrowserThread::ID* thread) { |
34 if (IPC_MESSAGE_CLASS(message) == PeerConnectionTrackerMsgStart) | 37 if (IPC_MESSAGE_CLASS(message) == PeerConnectionTrackerMsgStart) |
35 *thread = BrowserThread::UI; | 38 *thread = BrowserThread::UI; |
36 } | 39 } |
37 | 40 |
38 PeerConnectionTrackerHost::~PeerConnectionTrackerHost() { | 41 PeerConnectionTrackerHost::~PeerConnectionTrackerHost() { |
39 } | 42 } |
40 | 43 |
| 44 void PeerConnectionTrackerHost::OnChannelConnected(int32 peer_pid) { |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 46 // Add PowerMonitor when connected to channel rather than in constructor due |
| 47 // to thread safety concerns. Observers of PowerMonitor must be added and |
| 48 // removed on the same thread. BrowserMessageFilter is created on the UI |
| 49 // thread but can be destructed on the UI or IO thread because they are |
| 50 // referenced by RenderProcessHostImpl on the UI thread and ChannelProxy on |
| 51 // the IO thread. Using OnChannelConnected and OnChannelClosing guarantees |
| 52 // execution on the IO thread. |
| 53 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 54 if (power_monitor) |
| 55 power_monitor->AddObserver(this); |
| 56 } |
| 57 |
| 58 void PeerConnectionTrackerHost::OnChannelClosing() { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 60 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 61 if (power_monitor) |
| 62 power_monitor->RemoveObserver(this); |
| 63 } |
| 64 |
41 void PeerConnectionTrackerHost::OnAddPeerConnection( | 65 void PeerConnectionTrackerHost::OnAddPeerConnection( |
42 const PeerConnectionInfo& info) { | 66 const PeerConnectionInfo& info) { |
43 WebRTCInternals::GetInstance()->OnAddPeerConnection( | 67 WebRTCInternals::GetInstance()->OnAddPeerConnection( |
44 render_process_id_, | 68 render_process_id_, |
45 peer_pid(), | 69 peer_pid(), |
46 info.lid, | 70 info.lid, |
47 info.url, | 71 info.url, |
48 info.rtc_configuration, | 72 info.rtc_configuration, |
49 info.constraints); | 73 info.constraints); |
50 } | 74 } |
(...skipping 24 matching lines...) Expand all Loading... |
75 const std::string& video_constraints) { | 99 const std::string& video_constraints) { |
76 WebRTCInternals::GetInstance()->OnGetUserMedia(render_process_id_, | 100 WebRTCInternals::GetInstance()->OnGetUserMedia(render_process_id_, |
77 peer_pid(), | 101 peer_pid(), |
78 origin, | 102 origin, |
79 audio, | 103 audio, |
80 video, | 104 video, |
81 audio_constraints, | 105 audio_constraints, |
82 video_constraints); | 106 video_constraints); |
83 } | 107 } |
84 | 108 |
| 109 void PeerConnectionTrackerHost::OnSuspend() { |
| 110 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 111 base::Bind(&PeerConnectionTrackerHost::SendOnSuspendOnUIThread, this)); |
| 112 } |
| 113 |
| 114 void PeerConnectionTrackerHost::SendOnSuspendOnUIThread() { |
| 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 116 content::RenderProcessHost* host = |
| 117 content::RenderProcessHost::FromID(render_process_id_); |
| 118 if (host) |
| 119 host->Send(new PeerConnectionTracker_OnSuspend()); |
| 120 } |
| 121 |
85 } // namespace content | 122 } // namespace content |
OLD | NEW |