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 17 matching lines...) Expand all Loading... |
28 dict->Set("log", log); | 28 dict->Set("log", log); |
29 } | 29 } |
30 return log; | 30 return log; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 WebRTCInternals::WebRTCInternals() { | 35 WebRTCInternals::WebRTCInternals() { |
36 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 36 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
37 NotificationService::AllBrowserContextsAndSources()); | 37 NotificationService::AllBrowserContextsAndSources()); |
38 registrar_.Add(this, NOTIFICATION_CHILD_PROCESS_CRASHED, | 38 |
39 NotificationService::AllBrowserContextsAndSources()); | 39 BrowserChildProcessObserver::Add(this); |
40 } | 40 } |
41 | 41 |
42 WebRTCInternals::~WebRTCInternals() { | 42 WebRTCInternals::~WebRTCInternals() { |
| 43 BrowserChildProcessObserver::Remove(this); |
43 } | 44 } |
44 | 45 |
45 WebRTCInternals* WebRTCInternals::GetInstance() { | 46 WebRTCInternals* WebRTCInternals::GetInstance() { |
46 return Singleton<WebRTCInternals>::get(); | 47 return Singleton<WebRTCInternals>::get(); |
47 } | 48 } |
48 | 49 |
49 void WebRTCInternals::AddPeerConnection(int render_process_id, | 50 void WebRTCInternals::AddPeerConnection(int render_process_id, |
50 ProcessId pid, | 51 ProcessId pid, |
51 int lid, | 52 int lid, |
52 const string& url, | 53 const string& url, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 172 } |
172 | 173 |
173 void WebRTCInternals::SendUpdate(const string& command, Value* value) { | 174 void WebRTCInternals::SendUpdate(const string& command, Value* value) { |
174 DCHECK_GT(observers_.size(), (size_t)0); | 175 DCHECK_GT(observers_.size(), (size_t)0); |
175 | 176 |
176 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 177 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
177 observers_, | 178 observers_, |
178 OnUpdate(command, value)); | 179 OnUpdate(command, value)); |
179 } | 180 } |
180 | 181 |
| 182 void WebRTCInternals::BrowserChildProcessCrashed( |
| 183 const ChildProcessData& data) { |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 185 OnRendererExit(data.id); |
| 186 } |
| 187 |
181 void WebRTCInternals::Observe(int type, | 188 void WebRTCInternals::Observe(int type, |
182 const NotificationSource& source, | 189 const NotificationSource& source, |
183 const NotificationDetails& details) { | 190 const NotificationDetails& details) { |
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
185 int render_process_id = -1; | 192 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
| 193 OnRendererExit(Source<RenderProcessHost>(source)->GetID()); |
| 194 } |
186 | 195 |
187 switch (type) { | 196 void WebRTCInternals::OnRendererExit(int render_process_id) { |
188 case NOTIFICATION_RENDERER_PROCESS_TERMINATED: | |
189 render_process_id = Source<RenderProcessHost>(source)->GetID(); | |
190 break; | |
191 case NOTIFICATION_CHILD_PROCESS_CRASHED: | |
192 render_process_id = Details<ChildProcessData>(details).ptr()->id; | |
193 break; | |
194 default: | |
195 NOTREACHED(); | |
196 break; | |
197 } | |
198 | |
199 // Iterates from the end of the list to remove the PeerConnections created | 197 // Iterates from the end of the list to remove the PeerConnections created |
200 // by the exitting renderer. | 198 // by the exitting renderer. |
201 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { | 199 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { |
202 DictionaryValue* record = NULL; | 200 DictionaryValue* record = NULL; |
203 peer_connection_data_.GetDictionary(i, &record); | 201 peer_connection_data_.GetDictionary(i, &record); |
204 | 202 |
205 int this_rid = 0; | 203 int this_rid = 0; |
206 record->GetInteger("rid", &this_rid); | 204 record->GetInteger("rid", &this_rid); |
207 | 205 |
208 if (this_rid == render_process_id) { | 206 if (this_rid == render_process_id) { |
209 if (observers_.size() > 0) { | 207 if (observers_.size() > 0) { |
210 int lid = 0, pid = 0; | 208 int lid = 0, pid = 0; |
211 record->GetInteger("lid", &lid); | 209 record->GetInteger("lid", &lid); |
212 record->GetInteger("pid", &pid); | 210 record->GetInteger("pid", &pid); |
213 | 211 |
214 DictionaryValue update; | 212 DictionaryValue update; |
215 update.SetInteger("lid", lid); | 213 update.SetInteger("lid", lid); |
216 update.SetInteger("pid", pid); | 214 update.SetInteger("pid", pid); |
217 SendUpdate("removePeerConnection", &update); | 215 SendUpdate("removePeerConnection", &update); |
218 } | 216 } |
219 peer_connection_data_.Remove(i, NULL); | 217 peer_connection_data_.Remove(i, NULL); |
220 } | 218 } |
221 } | 219 } |
222 } | 220 } |
223 | 221 |
224 } // namespace content | 222 } // namespace content |
OLD | NEW |