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 | |
| 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 peer_connection_data_.Append(dict); | |
| 42 | |
| 43 if (observers_.size() > 0) | |
| 44 SendUpdate("addPeerConnection", dict); | |
| 45 } | |
| 46 | |
| 47 void ChromeWebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 49 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | |
| 50 DictionaryValue* dict = NULL; | |
| 51 peer_connection_data_.GetDictionary(i, &dict); | |
| 52 | |
| 53 int this_pid = 0; | |
| 54 int this_lid = 0; | |
| 55 dict->GetInteger("pid", &this_pid); | |
| 56 dict->GetInteger("lid", &this_lid); | |
| 57 | |
| 58 if (this_pid != static_cast<int>(pid) || this_lid != lid) | |
| 59 continue; | |
| 60 | |
| 61 peer_connection_data_.Remove(i, NULL); | |
| 62 | |
| 63 if (observers_.size() > 0) { | |
| 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 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() > 0); | |
|
jam
2013/01/22 17:19:12
nit: convention is to use empty() instead of size(
| |
| 87 | |
| 88 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | |
| 89 observers_, | |
| 90 OnUpdate(command, value)); | |
| 91 } | |
| OLD | NEW |