Index: chrome/browser/media/chrome_webrtc_internals.cc |
diff --git a/chrome/browser/media/chrome_webrtc_internals.cc b/chrome/browser/media/chrome_webrtc_internals.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b44b5ff2619dc8706f3d5a0408a8e3b04ef0d289 |
--- /dev/null |
+++ b/chrome/browser/media/chrome_webrtc_internals.cc |
@@ -0,0 +1,93 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/media/chrome_webrtc_internals.h" |
+ |
+#include "chrome/browser/media/webrtc_internals_ui_observer.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+using base::DictionaryValue; |
+using base::ProcessId; |
+using content::BrowserThread; |
+using std::string; |
+ |
+namespace media { |
+ |
+ChromeWebRTCInternals::ChromeWebRTCInternals() { |
+} |
+ |
+ChromeWebRTCInternals::~ChromeWebRTCInternals() { |
+} |
+ |
+ChromeWebRTCInternals* ChromeWebRTCInternals::GetInstance() { |
+ return Singleton<ChromeWebRTCInternals>::get(); |
+} |
+ |
+void ChromeWebRTCInternals::AddPeerConnection(ProcessId pid, |
+ int lid, |
+ const string& url, |
+ const string& servers, |
+ const string& constraints) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ 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.
|
+ DictionaryValue* dict = new DictionaryValue(); |
+ if (dict != NULL) { |
+ dict->SetInteger("pid", static_cast<int>(pid)); |
+ dict->SetInteger("lid", lid); |
+ dict->SetString("servers", servers); |
+ dict->SetString("constraints", constraints); |
+ dict->SetString("url", url); |
+ |
+ SendUpdate("addPeerConnection", dict); |
+ peer_connection_data_.Append(dict); |
+ } |
+ } |
+} |
+ |
+void ChromeWebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (observers_.size()) { |
+ for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
+ DictionaryValue* dict = NULL; |
+ peer_connection_data_.GetDictionary(i, &dict); |
+ |
+ int this_pid = 0; |
+ int this_lid = 0; |
+ dict->GetInteger("pid", &this_pid); |
+ dict->GetInteger("lid", &this_lid); |
+ if (this_pid == static_cast<int>(pid) && this_lid == lid) { |
+ peer_connection_data_.Remove(i, NULL); |
+ |
+ DictionaryValue dict; |
+ dict.SetInteger("pid", static_cast<int>(pid)); |
+ dict.SetInteger("lid", lid); |
+ SendUpdate("removePeerConnection", &dict); |
+ |
+ break; |
+ } |
+ } |
+ } |
+} |
+ |
+void ChromeWebRTCInternals::AddObserver( |
+ WebRTCInternalsUIObserver *observer) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ observers_.AddObserver(observer); |
+} |
+ |
+void ChromeWebRTCInternals::RemoveObserver( |
+ WebRTCInternalsUIObserver *observer) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+void ChromeWebRTCInternals::SendUpdate(const string& command, Value* value) { |
+ DCHECK(observers_.size()); |
+ |
+ FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
+ observers_, |
+ OnUpdate(command, value)); |
+} |
+ |
+} // namespace media |