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