OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/media/chrome_webrtc_internals.h" | |
6 | |
7 #include "chrome/browser/media/webrtc_internals_ui_observer.h" | |
8 #include "content/public/browser/browser_thread.h" | |
9 | |
10 using base::DictionaryValue; | |
11 using base::ProcessId; | |
12 using content::BrowserThread; | |
13 using std::string; | |
14 | |
15 namespace media { | |
16 | |
17 ChromeWebRTCInternals::ChromeWebRTCInternals() { | |
18 } | |
19 | |
20 ChromeWebRTCInternals::~ChromeWebRTCInternals() { | |
21 } | |
22 | |
23 ChromeWebRTCInternals* ChromeWebRTCInternals::GetInstance() { | |
24 return Singleton<ChromeWebRTCInternals>::get(); | |
25 } | |
26 | |
27 void ChromeWebRTCInternals::AddPeerConnection(ProcessId pid, | |
28 int lid, | |
29 const string& url, | |
30 const string& servers, | |
31 const string& constraints) { | |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
33 if (observers_.size()) { | |
jam
2013/01/18 18:27:33
nit: here and below, better to early return when t
jiayl
2013/01/18 19:20:00
Done.
| |
34 DictionaryValue* dict = new DictionaryValue(); | |
35 if (dict != NULL) { | |
36 dict->SetInteger("pid", static_cast<int>(pid)); | |
37 dict->SetInteger("lid", lid); | |
38 dict->SetString("servers", servers); | |
39 dict->SetString("constraints", constraints); | |
40 dict->SetString("url", url); | |
41 | |
42 SendUpdate("addPeerConnection", dict); | |
43 peer_connection_data_.Append(dict); | |
44 } | |
45 } | |
46 } | |
47 | |
48 void ChromeWebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) { | |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
50 if (observers_.size()) { | |
51 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | |
52 DictionaryValue* dict = NULL; | |
53 peer_connection_data_.GetDictionary(i, &dict); | |
54 | |
55 int this_pid = 0; | |
56 int this_lid = 0; | |
57 dict->GetInteger("pid", &this_pid); | |
58 dict->GetInteger("lid", &this_lid); | |
59 if (this_pid == static_cast<int>(pid) && this_lid == lid) { | |
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 } | |
69 } | |
70 } | |
71 } | |
72 | |
73 void ChromeWebRTCInternals::AddObserver( | |
74 WebRTCInternalsUIObserver *observer) { | |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
76 observers_.AddObserver(observer); | |
77 } | |
78 | |
79 void ChromeWebRTCInternals::RemoveObserver( | |
80 WebRTCInternalsUIObserver *observer) { | |
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
82 observers_.RemoveObserver(observer); | |
83 } | |
84 | |
85 void ChromeWebRTCInternals::SendUpdate(const string& command, Value* value) { | |
86 DCHECK(observers_.size()); | |
87 | |
88 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | |
89 observers_, | |
90 OnUpdate(command, value)); | |
91 } | |
92 | |
93 } // namespace media | |
OLD | NEW |