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 "chrome/browser/media/webrtc_internals.h" |
6 | 6 |
7 #include "content/browser/media/webrtc_internals_ui_observer.h" | 7 #include "chrome/browser/media/webrtc_internals_ui_observer.h" |
8 #include "content/common/media/peer_connection_tracker_messages.h" | |
9 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
10 | 9 |
11 using base::DictionaryValue; | 10 using base::DictionaryValue; |
12 using base::ProcessId; | 11 using base::ProcessId; |
| 12 using content::BrowserThread; |
| 13 using std::string; |
13 | 14 |
14 namespace content{ | 15 namespace media { |
15 | 16 |
16 WebRTCInternals::WebRTCInternals() { | 17 WebRTCInternals::WebRTCInternals() { |
17 } | 18 } |
18 | 19 |
19 WebRTCInternals::~WebRTCInternals() { | 20 WebRTCInternals::~WebRTCInternals() { |
20 } | 21 } |
21 | 22 |
22 WebRTCInternals* WebRTCInternals::GetInstance() { | 23 WebRTCInternals* WebRTCInternals::GetInstance() { |
23 return Singleton<WebRTCInternals>::get(); | 24 return Singleton<WebRTCInternals>::get(); |
24 } | 25 } |
25 | 26 |
26 void WebRTCInternals::AddPeerConnection(ProcessId pid, | 27 void WebRTCInternals::AddPeerConnection(ProcessId pid, |
27 const PeerConnectionInfo& info) { | 28 int lid, |
| 29 const string& url, |
| 30 const string& servers, |
| 31 const string& constraints) { |
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
29 if (observers_.size()) { | 33 if (observers_.size()) { |
30 DictionaryValue* dict = new DictionaryValue(); | 34 DictionaryValue* dict = new DictionaryValue(); |
31 if (dict != NULL) { | 35 if (dict != NULL) { |
32 dict->SetInteger("pid", static_cast<int>(pid)); | 36 dict->SetInteger("pid", static_cast<int>(pid)); |
33 dict->SetInteger("lid", info.lid); | 37 dict->SetInteger("lid", lid); |
34 dict->SetString("servers", info.servers); | 38 dict->SetString("servers", servers); |
35 dict->SetString("constraints", info.constraints); | 39 dict->SetString("constraints", constraints); |
36 dict->SetString("url", info.url); | 40 dict->SetString("url", url); |
37 | 41 |
38 SendUpdate("updatePeerConnectionAdded", dict); | 42 SendUpdate("addPeerConnection", dict); |
39 peer_connection_data_.Append(dict); | 43 peer_connection_data_.Append(dict); |
40 } | 44 } |
41 } | 45 } |
42 } | 46 } |
43 | 47 |
44 void WebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) { | 48 void WebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) { |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
46 if (observers_.size()) { | 50 if (observers_.size()) { |
47 DictionaryValue dict; | |
48 dict.SetInteger("pid", static_cast<int>(pid)); | |
49 dict.SetInteger("lid", lid); | |
50 SendUpdate("updatePeerConnectionRemoved", &dict); | |
51 | |
52 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | 51 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
53 DictionaryValue* dict = NULL; | 52 DictionaryValue* dict = NULL; |
54 peer_connection_data_.GetDictionary(i, &dict); | 53 peer_connection_data_.GetDictionary(i, &dict); |
55 | 54 |
56 int this_pid = 0; | 55 int this_pid = 0; |
57 int this_lid = 0; | 56 int this_lid = 0; |
58 dict->GetInteger("pid", &this_pid); | 57 dict->GetInteger("pid", &this_pid); |
59 dict->GetInteger("lid", &this_lid); | 58 dict->GetInteger("lid", &this_lid); |
60 if (this_pid == static_cast<int>(pid) && this_lid == lid) | 59 if (this_pid == static_cast<int>(pid) && this_lid == lid) { |
61 peer_connection_data_.Remove(i, NULL); | 60 peer_connection_data_.Remove(i, NULL); |
| 61 |
| 62 DictionaryValue dict; |
| 63 dict.SetInteger("pid", static_cast<int>(pid)); |
| 64 dict.SetInteger("lid", lid); |
| 65 SendUpdate("removePeerConnection", &dict); |
| 66 |
| 67 break; |
| 68 } |
62 } | 69 } |
63 } | 70 } |
64 } | 71 } |
65 | 72 |
66 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { | 73 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
68 observers_.AddObserver(observer); | 75 observers_.AddObserver(observer); |
69 } | 76 } |
70 | 77 |
71 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { | 78 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
73 observers_.RemoveObserver(observer); | 80 observers_.RemoveObserver(observer); |
74 } | 81 } |
75 | 82 |
76 void WebRTCInternals::SendUpdate(const std::string& command, Value* value) { | 83 void WebRTCInternals::SendUpdate(const string& command, Value* value) { |
77 DCHECK(observers_.size()); | 84 DCHECK(observers_.size()); |
78 | 85 |
79 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 86 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
80 observers_, | 87 observers_, |
81 OnUpdate(command, value)); | 88 OnUpdate(command, value)); |
82 } | 89 } |
83 | 90 |
84 } // namespace content | 91 } // namespace media |
OLD | NEW |