diff --git a/talk/app/webrtc/peerconnection.cc b/talk/app/webrtc/peerconnection.cc index 7e9c9fc7e..4376cb382 100644 --- a/talk/app/webrtc/peerconnection.cc +++ b/talk/app/webrtc/peerconnection.cc @@ -301,6 +301,7 @@ namespace webrtc { PeerConnection::PeerConnection(PeerConnectionFactory* factory) : factory_(factory), observer_(NULL), + uma_observer_(NULL), signaling_state_(kStable), ice_state_(kIceNew), ice_connection_state_(kIceConnectionNew), @@ -358,6 +359,12 @@ bool PeerConnection::DoInitialize( portallocator_flags |= cricket::PORTALLOCATOR_ENABLE_IPV6; } + if (value && uma_observer_) { + uma_observer_->IncrementCounter(kPeerConnection_IPv6); + } else if (!value && uma_observer_) { + uma_observer_->IncrementCounter(kPeerConnection_IPv4); + } + port_allocator_->set_flags(portallocator_flags); // No step delay is used while allocating ports. port_allocator_->set_step_delay(cricket::kMinimumStepDelay); @@ -619,6 +626,10 @@ bool PeerConnection::AddIceCandidate( return session_->ProcessIceMessage(ice_candidate); } +void PeerConnection::RegisterUMAObserver(UMAObserver* observer) { + uma_observer_ = observer; +} + const SessionDescriptionInterface* PeerConnection::local_description() const { return session_->local_description(); } diff --git a/talk/app/webrtc/peerconnection.h b/talk/app/webrtc/peerconnection.h index 1cd26652a..4a428efee 100644 --- a/talk/app/webrtc/peerconnection.h +++ b/talk/app/webrtc/peerconnection.h @@ -105,6 +105,8 @@ class PeerConnection : public PeerConnectionInterface, const PeerConnectionInterface::RTCConfiguration& config); virtual bool AddIceCandidate(const IceCandidateInterface* candidate); + virtual void RegisterUMAObserver(UMAObserver* observer); + virtual void Close(); protected: @@ -183,6 +185,7 @@ class PeerConnection : public PeerConnectionInterface, // will refer to the same reference count. talk_base::scoped_refptr factory_; PeerConnectionObserver* observer_; + UMAObserver* uma_observer_; SignalingState signaling_state_; // TODO(bemasc): Remove ice_state_. IceState ice_state_; diff --git a/talk/app/webrtc/peerconnectioninterface.h b/talk/app/webrtc/peerconnectioninterface.h index a21c48dfa..54d341753 100644 --- a/talk/app/webrtc/peerconnectioninterface.h +++ b/talk/app/webrtc/peerconnectioninterface.h @@ -76,6 +76,7 @@ #include "talk/app/webrtc/jsep.h" #include "talk/app/webrtc/mediastreaminterface.h" #include "talk/app/webrtc/statstypes.h" +#include "talk/app/webrtc/umametrics.h" #include "talk/base/fileutils.h" #include "talk/base/socketaddress.h" @@ -118,6 +119,15 @@ class StatsObserver : public talk_base::RefCountInterface { virtual ~StatsObserver() {} }; +class UMAObserver : public talk_base::RefCountInterface { + public: + virtual void IncrementCounter(UMAMetricsCounter type) = 0; + virtual void AddHistogramSample(UMAMetricsName type, int value) = 0; + + protected: + virtual ~UMAObserver() {} +}; + class PeerConnectionInterface : public talk_base::RefCountInterface { public: // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions . @@ -255,6 +265,8 @@ class PeerConnectionInterface : public talk_base::RefCountInterface { // take the ownership of the |candidate|. virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0; + virtual void RegisterUMAObserver(UMAObserver* observer) = 0; + // Returns the current SignalingState. virtual SignalingState signaling_state() = 0; diff --git a/talk/app/webrtc/peerconnectionproxy.h b/talk/app/webrtc/peerconnectionproxy.h index a57110584..74e5012bb 100644 --- a/talk/app/webrtc/peerconnectionproxy.h +++ b/talk/app/webrtc/peerconnectionproxy.h @@ -62,6 +62,7 @@ BEGIN_PROXY_MAP(PeerConnection) PROXY_METHOD2(bool, UpdateIce, const IceServers&, const MediaConstraintsInterface*) PROXY_METHOD1(bool, AddIceCandidate, const IceCandidateInterface*) + PROXY_METHOD1(void, RegisterUMAObserver, UMAObserver*) PROXY_METHOD0(SignalingState, signaling_state) PROXY_METHOD0(IceState, ice_state) PROXY_METHOD0(IceConnectionState, ice_connection_state) diff --git a/talk/app/webrtc/umametrics.h b/talk/app/webrtc/umametrics.h new file mode 100755 index 000000000..e6414c3c1 --- /dev/null +++ b/talk/app/webrtc/umametrics.h @@ -0,0 +1,59 @@ +/* + * libjingle + * Copyright 2014, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This file contains enums related to IPv4/IPv6 metrics. + +#ifndef TALK_APP_WEBRTC_UMAMETRICS_H_ +#define TALK_APP_WEBRTC_UMAMETRICS_H_ + +namespace webrtc { + +// Currently this contains information related to WebRTC network/transport +// information. + +// This enum is backed by Chromium's histograms.xml, +// chromium/src/tools/metrics/histograms/histograms.xml +// Existing values cannot be re-ordered and new enums must be added +// before kBoundary. +enum UMAMetricsCounter { + kPeerConnection_IPv4, + kPeerConnection_IPv6, + kBestConnections_IPv4, + kBestConnections_IPv6, + kBoundary, +}; + +// This enum defines types for UMA samples, which will have a range. +enum UMAMetricsName { + kNetworkInterfaces_IPv4, + kNetworkInterfaces_IPv6, + kTimeToConnect, // In milliseconds. +}; + +} // namespace webrtc + +#endif // TALK_APP_WEBRTC_UMA6METRICS_H_