summaryrefslogtreecommitdiffstats
path: root/content/browser/media/webrtc_internals.cc
diff options
context:
space:
mode:
authorjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-10 04:04:40 +0000
committerjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-10 04:04:40 +0000
commitaf0899738a7350f81d306a8a5104fd275f327a7c (patch)
treed06a05666991cce0d3f45fb2e1b7d5441a982072 /content/browser/media/webrtc_internals.cc
parent4596925304b6f4dfe4e0daf2c34118fcffe62f08 (diff)
downloadchromium_src-af0899738a7350f81d306a8a5104fd275f327a7c.zip
chromium_src-af0899738a7350f81d306a8a5104fd275f327a7c.tar.gz
chromium_src-af0899738a7350f81d306a8a5104fd275f327a7c.tar.bz2
Data collection part of webrtc-internals implementation
This change implements the data collection part of webrtc-internals. RTCPeerConnectionHandler is an existing class living in the main renderer thread and knows about the status of a peer connection. With this CL, it reports every peer connection creation to PeerConnectionTracker. PeerConnectionTracker is also running in the renderer process. It assigns an integer ID to each peer connectionstore and sends the basic peer connection info to PeerConnectionTrackerHost along with the ID. PeerConnectionTrackerHost is running in the browser process in the IO thread. It simply passes anything it receives from PeerConnectionTracker to WebRTCInternals. WebRTCInternals is a singlton running in the browser process. It sends the data received from PeerConnectionTrackerHost to every observer, i.e. webrtc-internals page. WebRTCInternalsUIObserver will be implemented in another change list. BUG=168232 Review URL: https://chromiumcodereview.appspot.com/11753020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176012 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/media/webrtc_internals.cc')
-rw-r--r--content/browser/media/webrtc_internals.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/content/browser/media/webrtc_internals.cc b/content/browser/media/webrtc_internals.cc
new file mode 100644
index 0000000..afd9d12
--- /dev/null
+++ b/content/browser/media/webrtc_internals.cc
@@ -0,0 +1,84 @@
+// 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 "content/browser/media/webrtc_internals.h"
+
+#include "content/browser/media/webrtc_internals_ui_observer.h"
+#include "content/common/media/peer_connection_tracker_messages.h"
+#include "content/public/browser/browser_thread.h"
+
+using base::DictionaryValue;
+using base::ProcessId;
+
+namespace content{
+
+WebRTCInternals::WebRTCInternals() {
+}
+
+WebRTCInternals::~WebRTCInternals() {
+}
+
+WebRTCInternals* WebRTCInternals::GetInstance() {
+ return Singleton<WebRTCInternals>::get();
+}
+
+void WebRTCInternals::AddPeerConnection(ProcessId pid,
+ const PeerConnectionInfo& info) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (observers_.size()) {
+ DictionaryValue* dict = new DictionaryValue();
+ if (dict != NULL) {
+ dict->SetInteger("pid", static_cast<int>(pid));
+ dict->SetInteger("lid", info.lid);
+ dict->SetString("servers", info.servers);
+ dict->SetString("constraints", info.constraints);
+ dict->SetString("url", info.url);
+
+ SendUpdate("updatePeerConnectionAdded", dict);
+ peer_connection_data_.Append(dict);
+ }
+ }
+}
+
+void WebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (observers_.size()) {
+ DictionaryValue dict;
+ dict.SetInteger("pid", static_cast<int>(pid));
+ dict.SetInteger("lid", lid);
+ SendUpdate("updatePeerConnectionRemoved", &dict);
+
+ 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);
+ }
+ }
+}
+
+void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ observers_.AddObserver(observer);
+}
+
+void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ observers_.RemoveObserver(observer);
+}
+
+void WebRTCInternals::SendUpdate(const std::string& command, Value* value) {
+ DCHECK(observers_.size());
+
+ FOR_EACH_OBSERVER(WebRTCInternalsUIObserver,
+ observers_,
+ OnUpdate(command, value));
+}
+
+} // namespace content