Chromium Code Reviews| 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 ChromeWebRTCInternals::ChromeWebRTCInternals() { | |
| 16 } | |
| 17 | |
| 18 ChromeWebRTCInternals::~ChromeWebRTCInternals() { | |
| 19 } | |
| 20 | |
| 21 ChromeWebRTCInternals* ChromeWebRTCInternals::GetInstance() { | |
| 22 return Singleton<ChromeWebRTCInternals>::get(); | |
| 23 } | |
| 24 | |
| 25 void ChromeWebRTCInternals::AddPeerConnection(ProcessId pid, | |
| 26 int lid, | |
| 27 const string& url, | |
| 28 const string& servers, | |
| 29 const string& constraints) { | |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 31 if (observers_.size()) { | |
|
jam
2013/01/18 22:23:45
nit: early return here
jiayl
2013/01/18 22:39:51
I moved the check into SendUpdate and return early
jam
2013/01/18 22:52:01
why do this work when webrtc webui page isn't show
jiayl
2013/01/18 22:59:06
It's for sending the cached updates to a webrtc-in
jam
2013/01/22 07:03:13
i'm not sure i follow. what i mean is that this fu
| |
| 32 DictionaryValue* dict = new DictionaryValue(); | |
| 33 if (!dict) | |
| 34 return; | |
| 35 | |
| 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 void ChromeWebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 49 if (observers_.size()) { | |
|
jam
2013/01/18 22:23:45
ditto
jiayl
2013/01/18 22:39:51
Done.
| |
| 50 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | |
| 51 DictionaryValue* dict = NULL; | |
| 52 peer_connection_data_.GetDictionary(i, &dict); | |
| 53 | |
| 54 int this_pid = 0; | |
| 55 int this_lid = 0; | |
| 56 dict->GetInteger("pid", &this_pid); | |
| 57 dict->GetInteger("lid", &this_lid); | |
| 58 | |
| 59 if (this_pid != static_cast<int>(pid) || this_lid != lid) | |
| 60 continue; | |
| 61 | |
| 62 peer_connection_data_.Remove(i, NULL); | |
| 63 | |
| 64 DictionaryValue id; | |
| 65 id.SetInteger("pid", static_cast<int>(pid)); | |
| 66 id.SetInteger("lid", lid); | |
| 67 SendUpdate("removePeerConnection", &id); | |
| 68 | |
| 69 return; | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 void ChromeWebRTCInternals::AddObserver( | |
| 75 WebRTCInternalsUIObserver *observer) { | |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 77 observers_.AddObserver(observer); | |
| 78 } | |
| 79 | |
| 80 void ChromeWebRTCInternals::RemoveObserver( | |
| 81 WebRTCInternalsUIObserver *observer) { | |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 83 observers_.RemoveObserver(observer); | |
| 84 } | |
| 85 | |
| 86 void ChromeWebRTCInternals::SendUpdate(const string& command, Value* value) { | |
| 87 DCHECK(observers_.size()); | |
| 88 | |
| 89 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | |
| 90 observers_, | |
| 91 OnUpdate(command, value)); | |
| 92 } | |
| OLD | NEW |