Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1307)

Unified Diff: third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp

Issue 2363673002: Promise-based RTCPeerConnection::getStats implementation. (Closed)
Patch Set: RTCStatsReport.idl behind getStats-flag instead of updating virtual/stable/webexposed/global-interf… Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp
diff --git a/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp b/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp
index e465510c2985c62ec6a163b672afdba34354af9c..e04627b249c5b108c9705696dcfe789e3a153d1b 100644
--- a/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp
+++ b/third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp
@@ -69,6 +69,7 @@
#include "modules/peerconnection/RTCSessionDescriptionRequestImpl.h"
#include "modules/peerconnection/RTCSessionDescriptionRequestPromiseImpl.h"
#include "modules/peerconnection/RTCStatsCallback.h"
+#include "modules/peerconnection/RTCStatsReport.h"
#include "modules/peerconnection/RTCStatsRequestImpl.h"
#include "modules/peerconnection/RTCVoidRequestImpl.h"
#include "modules/peerconnection/RTCVoidRequestPromiseImpl.h"
@@ -373,6 +374,29 @@ RTCOfferOptionsPlatform* parseOfferOptions(const Dictionary& options)
return rtcOfferOptions;
}
+// Helper class for |RTCPeerConnection::getStats(ScriptState*, MediaStreamTrack*)|
+class WebRTCStatsReportCallbackResolver : public WebRTCStatsReportCallback {
+public:
+ // Takes ownership of |resolver|.
+ static std::unique_ptr<WebRTCStatsReportCallback> create(ScriptPromiseResolver* resolver)
+ {
+ return std::unique_ptr<WebRTCStatsReportCallback>(new WebRTCStatsReportCallbackResolver(resolver));
+ }
+
+ ~WebRTCStatsReportCallbackResolver() override {}
+
+private:
+ WebRTCStatsReportCallbackResolver(ScriptPromiseResolver* resolver)
+ : m_resolver(resolver) {}
+
+ void OnStatsDelivered(std::unique_ptr<WebRTCStatsReport> report) override
+ {
+ m_resolver->resolve(new RTCStatsReport(std::move(report)));
+ }
+
+ Persistent<ScriptPromiseResolver> m_resolver;
+};
+
} // namespace
RTCPeerConnection::EventWrapper::EventWrapper(
@@ -973,8 +997,12 @@ ScriptPromise RTCPeerConnection::getStats(ScriptState* scriptState, MediaStreamT
{
ExecutionContext* context = scriptState->getExecutionContext();
UseCounter::count(context, UseCounter::RTCPeerConnectionGetStats);
- // TODO(hbos): Implement new |getStats| function. crbug.com/627816
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "getStats(optional MediaStreamTrack?) has not been implemented yet."));
+
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ m_peerHandler->getStats(WebRTCStatsReportCallbackResolver::create(resolver));
+
+ return promise;
}
RTCDataChannel* RTCPeerConnection::createDataChannel(String label, const Dictionary& options, ExceptionState& exceptionState)

Powered by Google App Engine
This is Rietveld 408576698