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