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 | 4 |
5 #include "content/browser/media/webrtc_internals.h" | 5 #include "content/browser/media/webrtc_internals.h" |
6 | 6 |
7 #include "content/browser/media/webrtc_internals_ui_observer.h" | 7 #include "content/browser/media/webrtc_internals_ui_observer.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/browser/child_process_data.h" | 9 #include "content/public/browser/child_process_data.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 return; | 58 return; |
59 | 59 |
60 dict->SetInteger("rid", render_process_id); | 60 dict->SetInteger("rid", render_process_id); |
61 dict->SetInteger("pid", static_cast<int>(pid)); | 61 dict->SetInteger("pid", static_cast<int>(pid)); |
62 dict->SetInteger("lid", lid); | 62 dict->SetInteger("lid", lid); |
63 dict->SetString("servers", servers); | 63 dict->SetString("servers", servers); |
64 dict->SetString("constraints", constraints); | 64 dict->SetString("constraints", constraints); |
65 dict->SetString("url", url); | 65 dict->SetString("url", url); |
66 peer_connection_data_.Append(dict); | 66 peer_connection_data_.Append(dict); |
67 | 67 |
68 if (observers_.size() > 0) | 68 if (observers_.might_have_observers()) |
69 SendUpdate("addPeerConnection", dict); | 69 SendUpdate("addPeerConnection", dict); |
70 } | 70 } |
71 | 71 |
72 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { | 72 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
74 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | 74 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
75 base::DictionaryValue* dict = NULL; | 75 base::DictionaryValue* dict = NULL; |
76 peer_connection_data_.GetDictionary(i, &dict); | 76 peer_connection_data_.GetDictionary(i, &dict); |
77 | 77 |
78 int this_pid = 0; | 78 int this_pid = 0; |
79 int this_lid = 0; | 79 int this_lid = 0; |
80 dict->GetInteger("pid", &this_pid); | 80 dict->GetInteger("pid", &this_pid); |
81 dict->GetInteger("lid", &this_lid); | 81 dict->GetInteger("lid", &this_lid); |
82 | 82 |
83 if (this_pid != static_cast<int>(pid) || this_lid != lid) | 83 if (this_pid != static_cast<int>(pid) || this_lid != lid) |
84 continue; | 84 continue; |
85 | 85 |
86 peer_connection_data_.Remove(i, NULL); | 86 peer_connection_data_.Remove(i, NULL); |
87 | 87 |
88 if (observers_.size() > 0) { | 88 if (observers_.might_have_observers()) { |
89 base::DictionaryValue id; | 89 base::DictionaryValue id; |
90 id.SetInteger("pid", static_cast<int>(pid)); | 90 id.SetInteger("pid", static_cast<int>(pid)); |
91 id.SetInteger("lid", lid); | 91 id.SetInteger("lid", lid); |
92 SendUpdate("removePeerConnection", &id); | 92 SendUpdate("removePeerConnection", &id); |
93 } | 93 } |
94 break; | 94 break; |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 void WebRTCInternals::OnUpdatePeerConnection( | 98 void WebRTCInternals::OnUpdatePeerConnection( |
(...skipping 17 matching lines...) Expand all Loading... |
116 return; | 116 return; |
117 | 117 |
118 base::DictionaryValue* log_entry = new base::DictionaryValue(); | 118 base::DictionaryValue* log_entry = new base::DictionaryValue(); |
119 if (!log_entry) | 119 if (!log_entry) |
120 return; | 120 return; |
121 | 121 |
122 log_entry->SetString("type", type); | 122 log_entry->SetString("type", type); |
123 log_entry->SetString("value", value); | 123 log_entry->SetString("value", value); |
124 log->Append(log_entry); | 124 log->Append(log_entry); |
125 | 125 |
126 if (observers_.size() > 0) { | 126 if (observers_.might_have_observers()) { |
127 base::DictionaryValue update; | 127 base::DictionaryValue update; |
128 update.SetInteger("pid", static_cast<int>(pid)); | 128 update.SetInteger("pid", static_cast<int>(pid)); |
129 update.SetInteger("lid", lid); | 129 update.SetInteger("lid", lid); |
130 update.SetString("type", type); | 130 update.SetString("type", type); |
131 update.SetString("value", value); | 131 update.SetString("value", value); |
132 | 132 |
133 SendUpdate("updatePeerConnection", &update); | 133 SendUpdate("updatePeerConnection", &update); |
134 } | 134 } |
135 return; | 135 return; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, | 139 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, |
140 const base::ListValue& value) { | 140 const base::ListValue& value) { |
141 if (observers_.size() == 0) | 141 if (!observers_.might_have_observers()) |
142 return; | 142 return; |
143 | 143 |
144 base::DictionaryValue dict; | 144 base::DictionaryValue dict; |
145 dict.SetInteger("pid", static_cast<int>(pid)); | 145 dict.SetInteger("pid", static_cast<int>(pid)); |
146 dict.SetInteger("lid", lid); | 146 dict.SetInteger("lid", lid); |
147 | 147 |
148 base::ListValue* list = value.DeepCopy(); | 148 base::ListValue* list = value.DeepCopy(); |
149 if (!list) | 149 if (!list) |
150 return; | 150 return; |
151 | 151 |
152 dict.Set("reports", list); | 152 dict.Set("reports", list); |
153 | 153 |
154 SendUpdate("addStats", &dict); | 154 SendUpdate("addStats", &dict); |
155 } | 155 } |
156 | 156 |
157 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { | 157 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { |
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
159 observers_.AddObserver(observer); | 159 observers_.AddObserver(observer); |
160 } | 160 } |
161 | 161 |
162 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { | 162 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 observers_.RemoveObserver(observer); | 164 observers_.RemoveObserver(observer); |
165 } | 165 } |
166 | 166 |
167 void WebRTCInternals::SendAllUpdates() { | 167 void WebRTCInternals::SendAllUpdates() { |
168 if (observers_.size() > 0) | 168 if (observers_.might_have_observers()) |
169 SendUpdate("updateAllPeerConnections", &peer_connection_data_); | 169 SendUpdate("updateAllPeerConnections", &peer_connection_data_); |
170 } | 170 } |
171 | 171 |
172 void WebRTCInternals::StartRtpRecording() { | 172 void WebRTCInternals::StartRtpRecording() { |
173 if (!is_recording_rtp_) { | 173 if (!is_recording_rtp_) { |
174 is_recording_rtp_ = true; | 174 is_recording_rtp_ = true; |
175 // TODO(justinlin): start RTP recording. | 175 // TODO(justinlin): start RTP recording. |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 void WebRTCInternals::StopRtpRecording() { | 179 void WebRTCInternals::StopRtpRecording() { |
180 if (is_recording_rtp_) { | 180 if (is_recording_rtp_) { |
181 is_recording_rtp_ = false; | 181 is_recording_rtp_ = false; |
182 // TODO(justinlin): stop RTP recording. | 182 // TODO(justinlin): stop RTP recording. |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { | 186 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { |
187 DCHECK_GT(observers_.size(), (size_t)0); | 187 DCHECK(observers_.might_have_observers()); |
188 | 188 |
189 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 189 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
190 observers_, | 190 observers_, |
191 OnUpdate(command, value)); | 191 OnUpdate(command, value)); |
192 } | 192 } |
193 | 193 |
194 void WebRTCInternals::BrowserChildProcessCrashed( | 194 void WebRTCInternals::BrowserChildProcessCrashed( |
195 const ChildProcessData& data) { | 195 const ChildProcessData& data) { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
197 OnRendererExit(data.id); | 197 OnRendererExit(data.id); |
(...skipping 11 matching lines...) Expand all Loading... |
209 // Iterates from the end of the list to remove the PeerConnections created | 209 // Iterates from the end of the list to remove the PeerConnections created |
210 // by the exitting renderer. | 210 // by the exitting renderer. |
211 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { | 211 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { |
212 base::DictionaryValue* record = NULL; | 212 base::DictionaryValue* record = NULL; |
213 peer_connection_data_.GetDictionary(i, &record); | 213 peer_connection_data_.GetDictionary(i, &record); |
214 | 214 |
215 int this_rid = 0; | 215 int this_rid = 0; |
216 record->GetInteger("rid", &this_rid); | 216 record->GetInteger("rid", &this_rid); |
217 | 217 |
218 if (this_rid == render_process_id) { | 218 if (this_rid == render_process_id) { |
219 if (observers_.size() > 0) { | 219 if (observers_.might_have_observers()) { |
220 int lid = 0, pid = 0; | 220 int lid = 0, pid = 0; |
221 record->GetInteger("lid", &lid); | 221 record->GetInteger("lid", &lid); |
222 record->GetInteger("pid", &pid); | 222 record->GetInteger("pid", &pid); |
223 | 223 |
224 base::DictionaryValue update; | 224 base::DictionaryValue update; |
225 update.SetInteger("lid", lid); | 225 update.SetInteger("lid", lid); |
226 update.SetInteger("pid", pid); | 226 update.SetInteger("pid", pid); |
227 SendUpdate("removePeerConnection", &update); | 227 SendUpdate("removePeerConnection", &update); |
228 } | 228 } |
229 peer_connection_data_.Remove(i, NULL); | 229 peer_connection_data_.Remove(i, NULL); |
230 } | 230 } |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 // TODO(justlin): Calls this method as necessary to update the recording status | 234 // TODO(justlin): Calls this method as necessary to update the recording status |
235 // UI. | 235 // UI. |
236 void WebRTCInternals::SendRtpRecordingUpdate() { | 236 void WebRTCInternals::SendRtpRecordingUpdate() { |
237 DCHECK(is_recording_rtp_); | 237 DCHECK(is_recording_rtp_); |
238 base::DictionaryValue update; | 238 base::DictionaryValue update; |
239 // TODO(justinlin): Fill in |update| with values as appropriate. | 239 // TODO(justinlin): Fill in |update| with values as appropriate. |
240 SendUpdate("updateDumpStatus", &update); | 240 SendUpdate("updateDumpStatus", &update); |
241 } | 241 } |
242 | 242 |
243 } // namespace content | 243 } // namespace content |
OLD | NEW |