summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 09:00:47 +0000
committerjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 09:00:47 +0000
commit94fb51044f14d5a2c97bbdebd9d8f4f6a1c05ff9 (patch)
tree780131636e430ae965b21f95caefe402e4de27ee /content
parent9b51b54bc515ea456ad38e6ed263f0fcbe970860 (diff)
downloadchromium_src-94fb51044f14d5a2c97bbdebd9d8f4f6a1c05ff9.zip
chromium_src-94fb51044f14d5a2c97bbdebd9d8f4f6a1c05ff9.tar.gz
chromium_src-94fb51044f14d5a2c97bbdebd9d8f4f6a1c05ff9.tar.bz2
Connecting webrtc-internals WebUI frontend with the backend
BUG=168232 Review URL: https://chromiumcodereview.appspot.com/11876007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178272 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/media/webrtc_internals.cc84
-rw-r--r--content/browser/media/webrtc_internals.h52
-rw-r--r--content/browser/media/webrtc_internals_ui_observer.h26
-rw-r--r--content/browser/media/webrtc_internals_unittest.cc99
-rw-r--r--content/browser/renderer_host/media/peer_connection_tracker_host.cc27
-rw-r--r--content/browser/renderer_host/media/peer_connection_tracker_host.h3
-rw-r--r--content/content_browser.gypi2
-rw-r--r--content/content_tests.gypi1
-rw-r--r--content/public/browser/content_browser_client.cc4
-rw-r--r--content/public/browser/content_browser_client.h7
-rw-r--r--content/public/browser/webrtc_internals.h33
11 files changed, 67 insertions, 271 deletions
diff --git a/content/browser/media/webrtc_internals.cc b/content/browser/media/webrtc_internals.cc
deleted file mode 100644
index afd9d12..0000000
--- a/content/browser/media/webrtc_internals.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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
diff --git a/content/browser/media/webrtc_internals.h b/content/browser/media/webrtc_internals.h
deleted file mode 100644
index 50db3da..0000000
--- a/content/browser/media/webrtc_internals.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// 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.
-
-#ifndef CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
-#define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
-
-#include "base/memory/singleton.h"
-#include "base/observer_list.h"
-#include "base/process.h"
-#include "base/values.h"
-#include "content/common/content_export.h"
-
-struct PeerConnectionInfo;
-
-namespace content {
-
-class WebRTCInternalsUIObserver;
-
-// This is a singleton class running in the browser process.
-// It collects peer connection infomation from the renderers,
-// forwards the data to WebRTCInternalsUIObserver and
-// sends data collecting commands to the renderers.
-class CONTENT_EXPORT WebRTCInternals {
- public:
- static WebRTCInternals* GetInstance();
-
- // Methods called when peer connection status changes.
- void AddPeerConnection(base::ProcessId pid, const PeerConnectionInfo& info);
- void RemovePeerConnection(base::ProcessId pid, int lid);
-
- // Methods for adding or removing WebRTCInternalsUIObserver.
- void AddObserver(WebRTCInternalsUIObserver *observer);
- void RemoveObserver(WebRTCInternalsUIObserver *observer);
-
- private:
- friend struct DefaultSingletonTraits<WebRTCInternals>;
-
- WebRTCInternals();
- virtual ~WebRTCInternals();
-
- // Send updates to observers on UI thread.
- void SendUpdate(const std::string& command, base::Value* value);
-
- // Only the IO thread should access these fields.
- ObserverList<WebRTCInternalsUIObserver> observers_;
- base::ListValue peer_connection_data_;
-};
-
-} // namespace content
-
-#endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
diff --git a/content/browser/media/webrtc_internals_ui_observer.h b/content/browser/media/webrtc_internals_ui_observer.h
deleted file mode 100644
index 44839df..0000000
--- a/content/browser/media/webrtc_internals_ui_observer.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-
-#ifndef CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_UI_OBSERVER_H_
-#define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_UI_OBSERVER_H_
-
-namespace base {
-class Value;
-} // namespace base
-
-namespace content {
-
-// Implement this interface to receive WebRTCInternals updates.
-class WebRTCInternalsUIObserver {
- public:
- virtual ~WebRTCInternalsUIObserver() {}
-
- // This is called on the browser IO thread.
- virtual void OnUpdate(const std::string& command,
- const base::Value* args) = 0;
-};
-
-} // namespace content
-
-#endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_UI_OBSERVER_H_
diff --git a/content/browser/media/webrtc_internals_unittest.cc b/content/browser/media/webrtc_internals_unittest.cc
deleted file mode 100644
index 5206443..0000000
--- a/content/browser/media/webrtc_internals_unittest.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// 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 "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
-#include "base/values.h"
-#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/test/test_browser_thread.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace content {
-class MockWebRTCInternalsProxy : public content::WebRTCInternalsUIObserver {
- public:
- void OnUpdate(const std::string& command, const Value* value) OVERRIDE {
- data_ = command;
- }
-
- std::string data() {
- return data_;
- }
-
- private:
- std::string data_;
-};
-
-class WebRTCInternalsTest : public testing::Test {
- public:
- WebRTCInternalsTest()
- : io_thread_(content::BrowserThread::IO, &io_loop_) {}
-
- protected:
- virtual void SetUp() {
- webrtc_internals_ = WebRTCInternals::GetInstance();
- }
-
- PeerConnectionInfo GetPeerConnectionInfo(uintptr_t lid) {
- PeerConnectionInfo info;
- info.lid = lid;
- info.servers = "s";
- info.constraints = "c";
- info.url = "u";
- return info;
- }
- std::string ExpectedInfo(std::string prefix,
- std::string id,
- std::string suffix) {
- static const std::string kstatic_part1 = std::string(
- "{\"constraints\":\"c\",");
- static const std::string kstatic_part2 = std::string(
- ",\"servers\":\"s\",\"url\":\"u\"}");
- return prefix + kstatic_part1 + id + kstatic_part2 + suffix;
- }
-
- MessageLoop io_loop_;
- content::TestBrowserThread io_thread_;
- WebRTCInternals *webrtc_internals_;
-};
-
-TEST_F(WebRTCInternalsTest, GetInstance) {
- EXPECT_TRUE(webrtc_internals_);
-}
-
-TEST_F(WebRTCInternalsTest, AddRemoveObserver) {
- scoped_ptr<MockWebRTCInternalsProxy> observer(
- new MockWebRTCInternalsProxy());
- webrtc_internals_->AddObserver(observer.get());
- webrtc_internals_->RemoveObserver(observer.get());
- webrtc_internals_->AddPeerConnection(3, GetPeerConnectionInfo(4));
- EXPECT_EQ("", observer->data());
-
- webrtc_internals_->RemovePeerConnection(3, 4);
-}
-
-TEST_F(WebRTCInternalsTest, SendAddPeerConnectionUpdate) {
- scoped_ptr<MockWebRTCInternalsProxy> observer(
- new MockWebRTCInternalsProxy());
- webrtc_internals_->AddObserver(observer.get());
- webrtc_internals_->AddPeerConnection(1, GetPeerConnectionInfo(2));
- EXPECT_EQ("updatePeerConnectionAdded", observer->data());
-
- webrtc_internals_->RemoveObserver(observer.get());
- webrtc_internals_->RemovePeerConnection(1, 2);
-}
-
-TEST_F(WebRTCInternalsTest, SendRemovePeerConnectionUpdate) {
- scoped_ptr<MockWebRTCInternalsProxy> observer(
- new MockWebRTCInternalsProxy());
- webrtc_internals_->AddObserver(observer.get());
- webrtc_internals_->AddPeerConnection(1, GetPeerConnectionInfo(2));
- webrtc_internals_->RemovePeerConnection(1, 2);
- EXPECT_EQ("updatePeerConnectionRemoved", observer->data());
-
- webrtc_internals_->RemoveObserver(observer.get());
-}
-
-} // namespace content
diff --git a/content/browser/renderer_host/media/peer_connection_tracker_host.cc b/content/browser/renderer_host/media/peer_connection_tracker_host.cc
index d4a8ac6..ea69271 100644
--- a/content/browser/renderer_host/media/peer_connection_tracker_host.cc
+++ b/content/browser/renderer_host/media/peer_connection_tracker_host.cc
@@ -4,9 +4,9 @@
#include "content/browser/renderer_host/media/peer_connection_tracker_host.h"
#include "base/process_util.h"
-#include "content/browser/media/webrtc_internals.h"
#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/webrtc_internals.h"
namespace content {
@@ -16,6 +16,7 @@ PeerConnectionTrackerHost::PeerConnectionTrackerHost() {
bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) {
bool handled = true;
+
IPC_BEGIN_MESSAGE_MAP_EX(PeerConnectionTrackerHost, message, *message_was_ok)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection,
OnAddPeerConnection)
@@ -26,18 +27,34 @@ bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message,
return handled;
}
+void PeerConnectionTrackerHost::OverrideThreadForMessage(
+ const IPC::Message& message, BrowserThread::ID* thread) {
+ if (IPC_MESSAGE_CLASS(message) == PeerConnectionTrackerMsgStart)
+ *thread = BrowserThread::UI;
+}
+
PeerConnectionTrackerHost::~PeerConnectionTrackerHost() {
}
void PeerConnectionTrackerHost::OnAddPeerConnection(
const PeerConnectionInfo& info) {
- WebRTCInternals::GetInstance()->AddPeerConnection(
- base::GetProcId(peer_handle()), info);
+ if (!GetContentClient()->browser()->GetWebRTCInternals())
+ return;
+
+ GetContentClient()->browser()->GetWebRTCInternals()->
+ AddPeerConnection(base::GetProcId(peer_handle()),
+ info.lid,
+ info.url,
+ info.servers,
+ info.constraints);
}
void PeerConnectionTrackerHost::OnRemovePeerConnection(int lid) {
- WebRTCInternals::GetInstance()->RemovePeerConnection(
- base::GetProcId(peer_handle()), lid);
+ if (!GetContentClient()->browser()->GetWebRTCInternals())
+ return;
+
+ GetContentClient()->browser()->GetWebRTCInternals()->
+ RemovePeerConnection(base::GetProcId(peer_handle()), lid);
}
} // namespace content
diff --git a/content/browser/renderer_host/media/peer_connection_tracker_host.h b/content/browser/renderer_host/media/peer_connection_tracker_host.h
index 58a36e0..271fc0d 100644
--- a/content/browser/renderer_host/media/peer_connection_tracker_host.h
+++ b/content/browser/renderer_host/media/peer_connection_tracker_host.h
@@ -10,7 +10,6 @@
struct PeerConnectionInfo;
namespace content {
-class WebRTCInternals;
// This class is the host for PeerConnectionTracker in the browser process
// managed by RenderProcessHostImpl. It passes IPC messages between
@@ -22,6 +21,8 @@ class PeerConnectionTrackerHost : public BrowserMessageFilter {
// content::BrowserMessageFilter override.
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) OVERRIDE;
+ virtual void OverrideThreadForMessage(const IPC::Message& message,
+ BrowserThread::ID* thread) OVERRIDE;
protected:
virtual ~PeerConnectionTrackerHost();
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 205f0cd..eb6a979 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -968,8 +968,6 @@
}],
['enable_webrtc==1', {
'sources': [
- 'browser/media/webrtc_internals.cc',
- 'browser/media/webrtc_internals.h',
'browser/renderer_host/media/peer_connection_tracker_host.cc',
'browser/renderer_host/media/peer_connection_tracker_host.h',
'browser/renderer_host/p2p/socket_host.cc',
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index 719ff2b..9b286a3 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -537,7 +537,6 @@
}],
['enable_webrtc==1', {
'sources': [
- 'browser/media/webrtc_internals_unittest.cc',
'browser/renderer_host/p2p/socket_host_test_utils.h',
'browser/renderer_host/p2p/socket_host_tcp_unittest.cc',
'browser/renderer_host/p2p/socket_host_tcp_server_unittest.cc',
diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc
index dcc127d..f377bbd 100644
--- a/content/public/browser/content_browser_client.cc
+++ b/content/public/browser/content_browser_client.cc
@@ -177,6 +177,10 @@ MediaObserver* ContentBrowserClient::GetMediaObserver() {
return NULL;
}
+WebRTCInternals* ContentBrowserClient::GetWebRTCInternals() {
+ return NULL;
+}
+
WebKit::WebNotificationPresenter::Permission
ContentBrowserClient::CheckDesktopNotificationPermission(
const GURL& source_origin,
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index 2e3b3c7..5c0dd67 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -70,6 +70,7 @@ class SpeechRecognitionManagerDelegate;
class WebContents;
class WebContentsView;
class WebContentsViewDelegate;
+class WebRTCInternals;
class WebUIControllerFactory;
struct MainFunctionParams;
struct ShowDesktopNotificationHostMsgParams;
@@ -324,10 +325,14 @@ class CONTENT_EXPORT ContentBrowserClient {
int render_process_id,
int render_view_id) {}
- // Returns a a class to get notifications about media event. The embedder can
+ // Returns a class to get notifications about media event. The embedder can
// return NULL if they're not interested.
virtual MediaObserver* GetMediaObserver();
+ // Returns a class to get WebRTC updates. The embedder can return NULL if they
+ // are not interested.
+ virtual WebRTCInternals* GetWebRTCInternals();
+
// Asks permission to show desktop notifications.
virtual void RequestDesktopNotificationPermission(
const GURL& source_origin,
diff --git a/content/public/browser/webrtc_internals.h b/content/public/browser/webrtc_internals.h
new file mode 100644
index 0000000..19eb5959
--- /dev/null
+++ b/content/public/browser/webrtc_internals.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef CONTENT_PUBLIC_BROWSER_WEBRTC_INTERNALS_H_
+#define CONTENT_PUBLIC_BROWSER_WEBRTC_INTERNALS_H_
+
+#include "base/process.h"
+
+namespace content {
+// This interface is used to receive WebRTC updates.
+// An embedder may implement it and return it from ContentBrowserClient.
+class WebRTCInternals {
+ public:
+ // This method is called when a PeerConnection is created.
+ // |pid| is the renderer process id, |lid| is the renderer local id used to
+ // identify a PeerConnection, |url| is the url of the tab owning the
+ // PeerConnection, |servers| is the servers configuration, |constraints| is
+ // the media constraints used to initialize the PeerConnection.
+ virtual void AddPeerConnection(base::ProcessId pid,
+ int lid,
+ const std::string& url,
+ const std::string& servers,
+ const std::string& constraints) = 0;
+
+ // This method is called when PeerConnection is destroyed.
+ // |pid| is the renderer process id, |lid| is the renderer local id.
+ virtual void RemovePeerConnection(base::ProcessId pid, int lid) = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_WEBRTC_INTERNALSH_