Commit af089973 authored by jiayl@chromium.org's avatar jiayl@chromium.org

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
parent 45969253
// 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
// 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_
// 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_
// 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
// 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/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"
namespace content {
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)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_RemovePeerConnection,
OnRemovePeerConnection)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
}
PeerConnectionTrackerHost::~PeerConnectionTrackerHost() {
}
void PeerConnectionTrackerHost::OnAddPeerConnection(
const PeerConnectionInfo& info) {
WebRTCInternals::GetInstance()->AddPeerConnection(
base::GetProcId(peer_handle()), info);
}
void PeerConnectionTrackerHost::OnRemovePeerConnection(int lid) {
WebRTCInternals::GetInstance()->RemovePeerConnection(
base::GetProcId(peer_handle()), lid);
}
} // namespace content
// 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_RENDERER_HOST_MEDIA_PEER_CONNECTION_TRACKER_HOST_H_
#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_PEER_CONNECTION_TRACKER_HOST_H_
#include "content/public/browser/browser_message_filter.h"
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
// WebRTCInternals and PeerConnectionTracker.
class PeerConnectionTrackerHost : public BrowserMessageFilter {
public:
PeerConnectionTrackerHost();
// content::BrowserMessageFilter override.
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) OVERRIDE;
protected:
virtual ~PeerConnectionTrackerHost();
private:
// Handlers for peer connection messages coming from the renderer.
void OnAddPeerConnection(const PeerConnectionInfo& info);
void OnRemovePeerConnection(int lid);
DISALLOW_COPY_AND_ASSIGN(PeerConnectionTrackerHost);
};
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_PEER_CONNECTION_TRACKER_HOST_H_
......@@ -68,6 +68,7 @@
#include "content/browser/renderer_host/media/audio_input_renderer_host.h"
#include "content/browser/renderer_host/media/audio_renderer_host.h"
#include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
#include "content/browser/renderer_host/media/peer_connection_tracker_host.h"
#include "content/browser/renderer_host/media/video_capture_host.h"
#include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
#include "content/browser/renderer_host/pepper/pepper_message_filter.h"
......@@ -539,6 +540,8 @@ void RenderProcessHostImpl::CreateMessageFilters() {
gpu_message_filter_ = new GpuMessageFilter(GetID(), widget_helper_.get());
channel_->AddFilter(gpu_message_filter_);
#if defined(ENABLE_WEBRTC)
peer_connection_tracker_host_ = new PeerConnectionTrackerHost();
channel_->AddFilter(peer_connection_tracker_host_);
channel_->AddFilter(new MediaStreamDispatcherHost(GetID()));
#endif
#if defined(ENABLE_PLUGINS)
......
......@@ -27,6 +27,7 @@ class Size;
namespace content {
class GpuMessageFilter;
class PeerConnectionTrackerHost;
class RendererMainThread;
class RenderWidgetHelper;
class RenderWidgetHost;
......@@ -308,6 +309,10 @@ class CONTENT_EXPORT RenderProcessHostImpl
// renderer.
bool is_guest_;
// Forwards messages between WebRTCInternals in the browser process
// and PeerConnectionTracker in the renderer process.
scoped_refptr<PeerConnectionTrackerHost> peer_connection_tracker_host_;
DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl);
};
......
......@@ -33,6 +33,7 @@
#include "content/common/media/audio_messages.h"
#include "content/common/media/media_player_messages.h"
#include "content/common/media/media_stream_messages.h"
#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/common/media/video_capture_messages.h"
#include "content/common/mime_registry_messages.h"
#include "content/common/p2p_messages.h"
......
// 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/common/content_export.h"
#include "ipc/ipc_message_macros.h"
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
#define IPC_MESSAGE_START PeerConnectionTrackerMsgStart
IPC_STRUCT_BEGIN(PeerConnectionInfo)
IPC_STRUCT_MEMBER(int, lid)
IPC_STRUCT_MEMBER(std::string, servers)
IPC_STRUCT_MEMBER(std::string, constraints)
IPC_STRUCT_MEMBER(std::string, url)
IPC_STRUCT_END()
// Messages sent from PeerConnectionTracker to PeerConnectionTrackerHost.
IPC_MESSAGE_CONTROL1(PeerConnectionTrackerHost_AddPeerConnection,
PeerConnectionInfo /* info */)
IPC_MESSAGE_CONTROL1(PeerConnectionTrackerHost_RemovePeerConnection,
int /* lid */)
......@@ -953,6 +953,10 @@
}],
['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',
'browser/renderer_host/p2p/socket_host.h',
'browser/renderer_host/p2p/socket_host_tcp.cc',
......
......@@ -344,6 +344,8 @@
'renderer/media/media_stream_impl.cc',
'renderer/media/peer_connection_handler_base.cc',
'renderer/media/peer_connection_handler_base.h',
'renderer/media/peer_connection_tracker.cc',
'renderer/media/peer_connection_tracker.h',
'renderer/media/rtc_data_channel_handler.cc',
'renderer/media/rtc_data_channel_handler.h',
'renderer/media/rtc_media_constraints.cc',
......
......@@ -524,6 +524,7 @@
}],
['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',
......
// 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/renderer/media/peer_connection_tracker.h"
#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/renderer/media/rtc_media_constraints.h"
#include "content/renderer/media/rtc_peer_connection_handler.h"
#include "content/renderer/render_thread_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
using webrtc::MediaConstraintsInterface;
namespace content {
PeerConnectionTracker::PeerConnectionTracker() : next_lid_(1) {
}
PeerConnectionTracker::~PeerConnectionTracker() {
}
void PeerConnectionTracker::RegisterPeerConnection(
RTCPeerConnectionHandler* pc_handler,
const std::vector<webrtc::JsepInterface::IceServer>& servers,
const RTCMediaConstraints& constraints,
const WebKit::WebFrame* frame) {
DVLOG(1) << "PeerConnectionTracker::RegisterPeerConnection()";
PeerConnectionInfo info;
info.lid = GetNextLocalID();
for (size_t i = 0; i < servers.size(); ++i) {
info.servers += servers[i].uri + ";";
}
MediaConstraintsInterface::Constraints mandatory = constraints.GetMandatory();
if (!mandatory.empty()) {
info.constraints = "mandatory: ";
for (size_t i = 0; i < mandatory.size(); ++i) {
info.constraints += "[" + mandatory[i].key + ":"
+ mandatory[i].value + "]";
}
}
MediaConstraintsInterface::Constraints optional = constraints.GetOptional();
if (!optional.empty()) {
info.constraints += "optional: ";
for (size_t i = 0; i < optional.size(); ++i) {
info.constraints += "[" + optional[i].key + ":"
+ optional[i].value + "]";
}
}
info.url = frame->document().url().spec();
RenderThreadImpl::current()->Send(
new PeerConnectionTrackerHost_AddPeerConnection(info));
DCHECK(peer_connection_id_map_.find(pc_handler) ==
peer_connection_id_map_.end());
peer_connection_id_map_[pc_handler] = info.lid;
}
void PeerConnectionTracker::UnregisterPeerConnection(
RTCPeerConnectionHandler* pc_handler) {
DVLOG(1) << "PeerConnectionTracker::UnregisterPeerConnection()";
std::map<RTCPeerConnectionHandler*, int>::iterator it =
peer_connection_id_map_.find(pc_handler);
DCHECK(it != peer_connection_id_map_.end());
RenderThreadImpl::current()->Send(
new PeerConnectionTrackerHost_RemovePeerConnection(it->second));
peer_connection_id_map_.erase(it);
}
int PeerConnectionTracker::GetNextLocalID() {
return next_lid_++;
}
} // namespace content
// 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_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_
#define CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_
#include <map>
#include "content/public/renderer/render_process_observer.h"
#include "third_party/libjingle/source/talk/app/webrtc/jsep.h"
namespace WebKit {
class WebFrame;
} // namespace WebKit
namespace content {
class RTCMediaConstraints;
class RTCPeerConnectionHandler;
// This class collects data about each peer connection,
// sends it to the browser process, and handles messages
// from the browser process.
class PeerConnectionTracker : public RenderProcessObserver{
public:
PeerConnectionTracker();
virtual ~PeerConnectionTracker();
// Sends an update to the browser process when a PeerConnection has been
// created in Javascript. The |pc_handler| is the handler object associated
// with the PeerConnection, the |servers| are the server configurations used
// to establish the connection, the |constraints| are the media constraints
// used to initialize the PeerConnection, the |frame| is the WebFrame object
// representing the page in which the PeerConnection is created.
void RegisterPeerConnection(
RTCPeerConnectionHandler* pc_handler,
const std::vector<webrtc::JsepInterface::IceServer>& servers,
const RTCMediaConstraints& constraints,
const WebKit::WebFrame* frame);
// Sends an update to the browser process when a PeerConnection has been
// destroyed. The |pc_handler| is the handler object associated with the
// PeerConnection.
void UnregisterPeerConnection(RTCPeerConnectionHandler* pc_handler);
private:
// Assign a local ID to a peer connection so that the browser process can
// uniquely identify a peer connection in the renderer process.
int GetNextLocalID();
// This map stores the local ID assigned to each RTCPeerConnectionHandler.
std::map<RTCPeerConnectionHandler*, int> peer_connection_id_map_;
// This keeps track of the next available local ID.
int next_lid_;
DISALLOW_COPY_AND_ASSIGN(PeerConnectionTracker);
};
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_
\ No newline at end of file
......@@ -13,8 +13,10 @@
#include "base/utf_string_conversions.h"
#include "content/public/common/content_switches.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "content/renderer/media/peer_connection_tracker.h"
#include "content/renderer/media/rtc_data_channel_handler.h"
#include "content/renderer/media/rtc_media_constraints.h"
#include "content/renderer/render_thread_impl.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints.h"
// TODO(hta): Move the following include to WebRTCStatsRequest.h file.
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamComponent.h"
......@@ -210,7 +212,7 @@ class StatsResponse : public webrtc::StatsObserver {
talk_base::scoped_refptr<LocalRTCStatsResponse> response_;
};
// Implementation of LocalRTCStatsRequest
// Implementation of LocalRTCStatsRequest.
LocalRTCStatsRequest::LocalRTCStatsRequest(WebKit::WebRTCStatsRequest impl)
: impl_(impl),
response_(NULL) {
......@@ -243,7 +245,7 @@ void LocalRTCStatsRequest::requestSucceeded(
impl_.requestSucceeded(response->webKitStatsResponse());
}
// Implementation of LocalRTCStatsResponse
// Implementation of LocalRTCStatsResponse.
WebKit::WebRTCStatsResponse LocalRTCStatsResponse::webKitStatsResponse() const {
return impl_;
}
......@@ -265,6 +267,13 @@ void LocalRTCStatsResponse::addStatistic(size_t report,
impl_.addStatistic(report, is_local, name, value);
}
static PeerConnectionTracker* GetPeerConnectionTracker() {
RenderThreadImpl* render_thread = RenderThreadImpl::current();
if (render_thread)
return render_thread->peer_connection_tracker();
return NULL;
}
RTCPeerConnectionHandler::RTCPeerConnectionHandler(
WebKit::WebRTCPeerConnectionHandlerClient* client,
MediaStreamDependencyFactory* dependency_factory)
......@@ -274,6 +283,8 @@ RTCPeerConnectionHandler::RTCPeerConnectionHandler(
}
RTCPeerConnectionHandler::~RTCPeerConnectionHandler() {
if (GetPeerConnectionTracker())
GetPeerConnectionTracker()->UnregisterPeerConnection(this);
}
void RTCPeerConnectionHandler::associateWithFrame(WebKit::WebFrame* frame) {
......@@ -296,6 +307,11 @@ bool RTCPeerConnectionHandler::initialize(
LOG(ERROR) << "Failed to initialize native PeerConnection.";
return false;
}
if (GetPeerConnectionTracker()) {
GetPeerConnectionTracker()->RegisterPeerConnection(
this, servers, constraints, frame_);
}
return true;
}
......
......@@ -61,6 +61,7 @@
#include "content/renderer/media/audio_renderer_mixer_manager.h"
#include "content/renderer/media/media_stream_center.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "content/renderer/media/peer_connection_tracker.h"
#include "content/renderer/media/video_capture_impl_manager.h"
#include "content/renderer/media/video_capture_message_filter.h"
#include "content/renderer/p2p/socket_dispatcher.h"
......@@ -332,6 +333,10 @@ void RenderThreadImpl::Init() {
#if defined(ENABLE_WEBRTC)
webrtc::SetupEventTracer(&GetCategoryEnabled, &AddTraceEvent);
peer_connection_tracker_.reset(new PeerConnectionTracker());
AddObserver(peer_connection_tracker_.get());
p2p_socket_dispatcher_ = new P2PSocketDispatcher(GetIOMessageLoopProxy());
AddFilter(p2p_socket_dispatcher_);
#endif // defined(ENABLE_WEBRTC)
......
......@@ -64,6 +64,7 @@ class IndexedDBDispatcher;
class MediaStreamCenter;
class MediaStreamDependencyFactory;
class P2PSocketDispatcher;
class PeerConnectionTracker;
class RendererWebKitPlatformSupportImpl;
class RenderProcessObserver;
class VideoCaptureImplManager;
......@@ -203,6 +204,10 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread,
// Returns a factory used for creating RTC PeerConnection objects.
MediaStreamDependencyFactory* GetMediaStreamDependencyFactory();
PeerConnectionTracker* peer_connection_tracker() {
return peer_connection_tracker_.get();
}
// Current P2PSocketDispatcher. Set to NULL if P2P API is disabled.
P2PSocketDispatcher* p2p_socket_dispatcher() {
return p2p_socket_dispatcher_.get();
......@@ -323,6 +328,10 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread,
scoped_ptr<MediaStreamDependencyFactory> media_stream_factory_;
// This is used to communicate to the browser process the status
// of all the peer connections created in the renderer.
scoped_ptr<PeerConnectionTracker> peer_connection_tracker_;
// Dispatches all P2P sockets.
scoped_refptr<P2PSocketDispatcher> p2p_socket_dispatcher_;
......
......@@ -72,6 +72,7 @@ enum IPCMessageStart {
CCMsgStart,
MediaPlayerMsgStart,
TracingMsgStart,
PeerConnectionTrackerMsgStart,
LastIPCMsgStart // Must come last.
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment