Implemented new API for RTCStatsReport object.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Mar 2013 23:45:57 +0000 (23:45 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Mar 2013 23:45:57 +0000 (23:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=110333

Source/Platform:

Patch by Harald Alvestrand <hta@chromium.org> on 2013-03-08
Reviewed by Adam Barth.

* chromium/public/WebRTCStatsResponse.h:
(WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
(WebRTCStatsResponse):

Source/WebCore:

Removed RTCStatsElement object, moved its interface to
RTCStatsReport. Preserved some interfaces for
backwards compatibility; will be removed in a later patch.

Patch by Harald Alvestrand <hta@chromium.org> on 2013-03-08
Reviewed by Adam Barth.

Tested by extensions to RTCPeerConnection-stats test.

* Modules/mediastream/RTCStatsElement.cpp: Removed.
* Modules/mediastream/RTCStatsElement.h: Removed.
* Modules/mediastream/RTCStatsElement.idl: Removed.
* Modules/mediastream/RTCStatsReport.cpp:
(WebCore::RTCStatsReport::create):
(WebCore::RTCStatsReport::RTCStatsReport):
(WebCore):
(WebCore::RTCStatsReport::names):
(WebCore::RTCStatsReport::local):
(WebCore::RTCStatsReport::remote):
(WebCore::RTCStatsReport::addStatistic):
(WebCore::RTCStatsReport::addElement):
* Modules/mediastream/RTCStatsReport.h:
(RTCStatsReport):
(WebCore::RTCStatsReport::timestamp):
(WebCore::RTCStatsReport::id):
(WebCore::RTCStatsReport::stat):
* Modules/mediastream/RTCStatsReport.idl:
* Modules/mediastream/RTCStatsResponse.cpp:
(WebCore::RTCStatsResponse::namedItem):
(WebCore):
(WebCore::RTCStatsResponse::addReport):
(WebCore::RTCStatsResponse::addStatistic):
* Modules/mediastream/RTCStatsResponse.h:
(RTCStatsResponse):
* Modules/mediastream/RTCStatsResponse.idl:
* WebCore.gypi:
* platform/chromium/support/WebRTCStatsResponse.cpp:
(WebKit::WebRTCStatsResponse::addReport):
(WebKit):
(WebKit::WebRTCStatsResponse::addStatistic):
(WebKit::WebRTCStatsResponse::addElement):
* platform/mediastream/RTCStatsResponseBase.h:
(RTCStatsResponseBase):

Tools:

Patch by Harald Alvestrand <hta@chromium.org> on 2013-03-08
Reviewed by Adam Barth.

* DumpRenderTree/chromium/TestRunner/src/MockWebRTCPeerConnectionHandler.cpp:
(WebTestRunner::MockWebRTCPeerConnectionHandler::getStats):

LayoutTests:

Patch by Harald Alvestrand <hta@chromium.org> on 2013-03-08
Reviewed by Adam Barth.

* fast/mediastream/RTCPeerConnection-stats-expected.txt:
* fast/mediastream/RTCPeerConnection-stats.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145279 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/RTCPeerConnection-stats-expected.txt
LayoutTests/fast/mediastream/RTCPeerConnection-stats.html
Source/Platform/ChangeLog
Source/Platform/chromium/public/WebRTCStatsResponse.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/mediastream/RTCStatsElement.cpp [deleted file]
Source/WebCore/Modules/mediastream/RTCStatsElement.h [deleted file]
Source/WebCore/Modules/mediastream/RTCStatsElement.idl [deleted file]
Source/WebCore/Modules/mediastream/RTCStatsReport.cpp
Source/WebCore/Modules/mediastream/RTCStatsReport.h
Source/WebCore/Modules/mediastream/RTCStatsReport.idl
Source/WebCore/Modules/mediastream/RTCStatsResponse.cpp
Source/WebCore/Modules/mediastream/RTCStatsResponse.h
Source/WebCore/Modules/mediastream/RTCStatsResponse.idl
Source/WebCore/WebCore.gypi
Source/WebCore/platform/chromium/support/WebRTCStatsResponse.cpp
Source/WebCore/platform/mediastream/RTCStatsResponseBase.h
Tools/ChangeLog
Tools/DumpRenderTree/chromium/TestRunner/src/MockWebRTCPeerConnectionHandler.cpp

index 32cc565..1a5a895 100644 (file)
@@ -1,3 +1,13 @@
+2013-03-08  Harald Alvestrand  <hta@chromium.org>
+
+        Implemented new API for RTCStatsReport object.
+        https://bugs.webkit.org/show_bug.cgi?id=110333
+
+        Reviewed by Adam Barth.
+
+        * fast/mediastream/RTCPeerConnection-stats-expected.txt:
+        * fast/mediastream/RTCPeerConnection-stats.html:
+
 2013-03-08  James Robinson  <jamesr@chromium.org>
 
         Chromium rebaselines and expectations updates.
index a6d7522..6bec6e7 100644 (file)
@@ -17,6 +17,13 @@ PASS timestamp is >= startTime
 PASS local.names().length is >= 1
 PASS local.names().indexOf("type") is >= 0
 PASS local.stat("type") is "audio"
+PASS res.timestamp is >= startTime
+PASS res.id is non-null.
+PASS res.names().length is >= 1
+PASS res.names().indexOf("type") is >= 0
+PASS res.stat("type") is "audio"
+PASS status_g.namedItem(res.id) is non-null.
+PASS status_g[res.id] is non-null.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 29d5814..6228efb 100644 (file)
@@ -47,14 +47,27 @@ function gotStream(s) {
 function statsHandler2(status)
 {
     testPassed("statsHandler2 was called");
+    // Status must be a global variable to be used in test statements.
+    status_g = status;
     result = status.result();
     shouldBeGreaterThanOrEqual('result.length', '2');
+    // The "local" interface is deprecated. Keep test until interface deleted.
     local = result[0].local;
     timestamp = local.timestamp;
     shouldBeGreaterThanOrEqual('timestamp', 'startTime');
     shouldBeGreaterThanOrEqual('local.names().length', '1');
     shouldBeGreaterThanOrEqual('local.names().indexOf("type")', '0');
     shouldBe('local.stat("type")', '"audio"');
+    // Newer interface.
+    res = result[0];
+    shouldBeGreaterThanOrEqual('res.timestamp', 'startTime');
+    shouldBeNonNull('res.id');
+    shouldBeGreaterThanOrEqual('res.names().length', '1');
+    shouldBeGreaterThanOrEqual('res.names().indexOf("type")', '0');
+    shouldBe('res.stat("type")', '"audio"');
+    // Named getter: Can access results by their ID values.
+    shouldBeNonNull('status_g.namedItem(res.id)');
+    shouldBeNonNull('status_g[res.id]');
     finishJSTest();
 }
 
index f0100a5..1cac9cd 100644 (file)
@@ -1,3 +1,14 @@
+2013-03-08  Harald Alvestrand  <hta@chromium.org>
+
+        Implemented new API for RTCStatsReport object.
+        https://bugs.webkit.org/show_bug.cgi?id=110333
+
+        Reviewed by Adam Barth.
+
+        * chromium/public/WebRTCStatsResponse.h:
+        (WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
+        (WebRTCStatsResponse):
+
 2013-03-08  James Robinson  <jamesr@chromium.org>
 
         [chromium] Remove WebLayerTreeViewClient and WebLayerTreeView::Settings
index cc6f38e..dc36412 100644 (file)
@@ -37,8 +37,8 @@ namespace WebKit {
 
 class WebRTCStatsResponse {
 public:
-    WebRTCStatsResponse() { }
     WebRTCStatsResponse(const WebRTCStatsResponse& other) { assign(other); }
+    WebRTCStatsResponse() { }
     ~WebRTCStatsResponse() { reset(); }
 
     WebRTCStatsResponse& operator=(const WebRTCStatsResponse& other)
@@ -51,8 +51,13 @@ public:
 
     WEBKIT_EXPORT void reset();
 
+    WEBKIT_EXPORT size_t addReport(WebString id, WebString type, double timestamp);
+    WEBKIT_EXPORT void addStatistic(size_t report, WebString name, WebString value);
+    // DEPRECATED
     WEBKIT_EXPORT size_t addReport();
+    // DEPRECATED
     WEBKIT_EXPORT void addElement(size_t report, bool isLocal, double timestamp);
+    // DEPRECATED
     WEBKIT_EXPORT void addStatistic(size_t report, bool isLocal, WebString name, WebString value);
 
 #if WEBKIT_IMPLEMENTATION
index de58a2a..f3bdb7c 100644 (file)
@@ -226,7 +226,6 @@ set(WebCore_IDL_FILES
     Modules/mediastream/RTCSessionDescription.idl
     Modules/mediastream/RTCSessionDescriptionCallback.idl
     Modules/mediastream/RTCStatsCallback.idl
-    Modules/mediastream/RTCStatsElement.idl
     Modules/mediastream/RTCStatsReport.idl
     Modules/mediastream/RTCStatsResponse.idl
 
@@ -865,7 +864,6 @@ set(WebCore_SOURCES
     Modules/mediastream/RTCPeerConnection.cpp
     Modules/mediastream/RTCSessionDescription.cpp
     Modules/mediastream/RTCSessionDescriptionRequestImpl.cpp
-    Modules/mediastream/RTCStatsElement.cpp
     Modules/mediastream/RTCStatsReport.cpp
     Modules/mediastream/RTCStatsRequestImpl.cpp
     Modules/mediastream/RTCStatsResponse.cpp
index 666d8b9..e7f0f90 100644 (file)
@@ -1,3 +1,51 @@
+2013-03-08  Harald Alvestrand  <hta@chromium.org>
+
+        Implemented new API for RTCStatsReport object.
+        https://bugs.webkit.org/show_bug.cgi?id=110333
+
+        Removed RTCStatsElement object, moved its interface to
+        RTCStatsReport. Preserved some interfaces for
+        backwards compatibility; will be removed in a later patch.
+
+        Reviewed by Adam Barth.
+
+        Tested by extensions to RTCPeerConnection-stats test.
+
+        * Modules/mediastream/RTCStatsElement.cpp: Removed.
+        * Modules/mediastream/RTCStatsElement.h: Removed.
+        * Modules/mediastream/RTCStatsElement.idl: Removed.
+        * Modules/mediastream/RTCStatsReport.cpp:
+        (WebCore::RTCStatsReport::create):
+        (WebCore::RTCStatsReport::RTCStatsReport):
+        (WebCore):
+        (WebCore::RTCStatsReport::names):
+        (WebCore::RTCStatsReport::local):
+        (WebCore::RTCStatsReport::remote):
+        (WebCore::RTCStatsReport::addStatistic):
+        (WebCore::RTCStatsReport::addElement):
+        * Modules/mediastream/RTCStatsReport.h:
+        (RTCStatsReport):
+        (WebCore::RTCStatsReport::timestamp):
+        (WebCore::RTCStatsReport::id):
+        (WebCore::RTCStatsReport::stat):
+        * Modules/mediastream/RTCStatsReport.idl:
+        * Modules/mediastream/RTCStatsResponse.cpp:
+        (WebCore::RTCStatsResponse::namedItem):
+        (WebCore):
+        (WebCore::RTCStatsResponse::addReport):
+        (WebCore::RTCStatsResponse::addStatistic):
+        * Modules/mediastream/RTCStatsResponse.h:
+        (RTCStatsResponse):
+        * Modules/mediastream/RTCStatsResponse.idl:
+        * WebCore.gypi:
+        * platform/chromium/support/WebRTCStatsResponse.cpp:
+        (WebKit::WebRTCStatsResponse::addReport):
+        (WebKit):
+        (WebKit::WebRTCStatsResponse::addStatistic):
+        (WebKit::WebRTCStatsResponse::addElement):
+        * platform/mediastream/RTCStatsResponseBase.h:
+        (RTCStatsResponseBase):
+
 2013-03-08  Eric Seidel  <eric@webkit.org>
 
         Free up background parser's checkpoints when speculation succeeds
index 9f456fd..f569fd1 100644 (file)
@@ -661,8 +661,6 @@ webcore_built_sources += \
        DerivedSources/WebCore/JSRTCSessionDescriptionCallback.h \
        DerivedSources/WebCore/JSRTCStatsCallback.cpp \
        DerivedSources/WebCore/JSRTCStatsCallback.h \
-       DerivedSources/WebCore/JSRTCStatsElement.cpp \
-       DerivedSources/WebCore/JSRTCStatsElement.h \
        DerivedSources/WebCore/JSRTCStatsReport.cpp \
        DerivedSources/WebCore/JSRTCStatsReport.h \
        DerivedSources/WebCore/JSRTCStatsResponse.cpp \
@@ -1267,7 +1265,6 @@ dom_binding_idls += \
        $(WebCore)/Modules/mediastream/RTCSessionDescription.idl \
        $(WebCore)/Modules/mediastream/RTCSessionDescriptionCallback.idl \
        $(WebCore)/Modules/mediastream/RTCStatsCallback.idl \
-       $(WebCore)/Modules/mediastream/RTCStatsElement.idl \
        $(WebCore)/Modules/mediastream/RTCStatsReport.idl \
        $(WebCore)/Modules/mediastream/RTCStatsResponse.idl \
        $(WebCore)/Modules/navigatorcontentutils/NavigatorContentUtils.idl \
@@ -1979,8 +1976,6 @@ webcore_modules_sources += \
        Source/WebCore/Modules/mediastream/RTCSessionDescriptionRequestImpl.cpp \
        Source/WebCore/Modules/mediastream/RTCSessionDescriptionRequestImpl.h \
        Source/WebCore/Modules/mediastream/RTCStatsCallback.h \
-       Source/WebCore/Modules/mediastream/RTCStatsElement.cpp \
-       Source/WebCore/Modules/mediastream/RTCStatsElement.h \
        Source/WebCore/Modules/mediastream/RTCStatsReport.cpp \
        Source/WebCore/Modules/mediastream/RTCStatsReport.h \
        Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.cpp \
diff --git a/Source/WebCore/Modules/mediastream/RTCStatsElement.cpp b/Source/WebCore/Modules/mediastream/RTCStatsElement.cpp
deleted file mode 100644 (file)
index 6241673..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS CONTRIBUTORS 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.
- */
-
-#include "config.h"
-
-#if ENABLE(MEDIA_STREAM)
-
-#include "RTCStatsElement.h"
-
-#include <wtf/text/StringHash.h>
-
-namespace WebCore {
-
-PassRefPtr<RTCStatsElement> RTCStatsElement::create(double timestamp)
-{
-    return adoptRef(new RTCStatsElement(timestamp));
-}
-
-RTCStatsElement::RTCStatsElement(double timestamp)
-    : m_timestamp(timestamp)
-{
-}
-
-String RTCStatsElement::stat(const String& name) const
-{
-    return m_stats.get(name);
-}
-
-Vector<String> RTCStatsElement::names() const
-{
-    Vector<String> result;
-    for (HashMap<String, String>::const_iterator it = m_stats.begin();
-        it != m_stats.end(); ++it) {
-        result.append(it->key);
-    }
-    return result;
-}
-
-void RTCStatsElement::addStatistic(const String& name, const String& value)
-{
-    m_stats.add(name, value);
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/Modules/mediastream/RTCStatsElement.h b/Source/WebCore/Modules/mediastream/RTCStatsElement.h
deleted file mode 100644 (file)
index 22d4acf..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS CONTRIBUTORS 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.
- */
-
-#ifndef RTCStatsElement_h
-#define RTCStatsElement_h
-
-#include <wtf/HashMap.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-class RTCStatsElement : public RefCounted<RTCStatsElement> {
-public:
-    static PassRefPtr<RTCStatsElement> create(double timestamp);
-    double timestamp() const { return m_timestamp; }
-    String stat(const String& name) const;
-    Vector<String> names() const;
-    void addStatistic(const String& name, const String& value);
-
-private:
-    explicit RTCStatsElement(double timestamp);
-
-    double m_timestamp;
-    HashMap<String, String> m_stats;
-};
-
-} // namespace WebCore
-
-#endif // RTCStatsElement_h
diff --git a/Source/WebCore/Modules/mediastream/RTCStatsElement.idl b/Source/WebCore/Modules/mediastream/RTCStatsElement.idl
deleted file mode 100644 (file)
index 3bd4332..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS CONTRIBUTORS 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.
- */
-
-[
-    Conditional=MEDIA_STREAM,
-    ImplementationLacksVTable
-] interface RTCStatsElement {
-    readonly attribute Date timestamp;
-    DOMString stat(in DOMString name);
-    sequence<DOMString> names();
-};
index a5616d5..6afea20 100644 (file)
 
 #include "RTCStatsReport.h"
 
+#include <wtf/text/StringHash.h>
+
 namespace WebCore {
 
 PassRefPtr<RTCStatsReport> RTCStatsReport::create()
 {
-    return adoptRef(new RTCStatsReport());
+    return adoptRef(new RTCStatsReport("inner fake ID", "inner fake type", 0));
 }
 
-RTCStatsReport::RTCStatsReport()
+PassRefPtr<RTCStatsReport> RTCStatsReport::create(const String& id, const String& type, double timestamp)
 {
+    return adoptRef(new RTCStatsReport(id, type, timestamp));
 }
 
-void RTCStatsReport::addElement(bool isLocal, double timestamp)
+RTCStatsReport::RTCStatsReport(const String& id, const String& type, double timestamp)
+    : m_id(id)
+    , m_type(type)
+    , m_timestamp(timestamp)
 {
-    if (isLocal) {
-        ASSERT(!m_local);
-        m_local = RTCStatsElement::create(timestamp);
-        return;
-    }
-    ASSERT(!m_remote);
-    m_remote = RTCStatsElement::create(timestamp);
 }
 
-void RTCStatsReport::addStatistic(bool isLocal, String name, String value)
+Vector<String> RTCStatsReport::names() const
 {
-    if (isLocal) {
-        ASSERT(m_local);
-        m_local->addStatistic(name, value);
-    } else {
-        ASSERT(m_remote);
-        m_remote->addStatistic(name, value);
+    Vector<String> result;
+    for (HashMap<String, String>::const_iterator it = m_stats.begin(); it != m_stats.end(); ++it) {
+        result.append(it->key);
     }
+    return result;
+}
+
+const PassRefPtr<RTCStatsReport> RTCStatsReport::local()
+{
+    return this;
+}
+
+const PassRefPtr<RTCStatsReport> RTCStatsReport::remote()
+{
+    return this;
+}
+
+void RTCStatsReport::addStatistic(const String& name, const String& value)
+{
+    m_stats.add(name, value);
+}
+
+void RTCStatsReport::addElement(bool isLocal, double timestamp)
+{
+    // We ignore isLocal.
+    m_timestamp = timestamp;
+}
+
+void RTCStatsReport::addStatistic(bool isLocal, const String& name, const String& value)
+{
+    // We ignore isLocal.
+    addStatistic(name, value);
 }
 
 } // namespace WebCore
index 3d0cccf..928f9c5 100644 (file)
@@ -25,7 +25,7 @@
 #ifndef RTCStatsReport_h
 #define RTCStatsReport_h
 
-#include "RTCStatsElement.h"
+#include <wtf/HashMap.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
@@ -35,19 +35,33 @@ namespace WebCore {
 
 class RTCStatsReport : public RefCounted<RTCStatsReport> {
 public:
+    static PassRefPtr<RTCStatsReport> create(const String& id, const String& type, double timestamp);
+    // DEPRECATED
     static PassRefPtr<RTCStatsReport> create();
 
-    const PassRefPtr<RTCStatsElement> local() const { return m_local.get(); }
-    const PassRefPtr<RTCStatsElement> remote() const { return m_remote.get(); }
+    double timestamp() const { return m_timestamp; }
+    String id() { return m_id; }
+    String stat(const String& name) { return m_stats.get(name); }
+    Vector<String> names() const;
 
+    // DEPRECATED
+    const PassRefPtr<RTCStatsReport> local();
+    // DEPRECATED
+    const PassRefPtr<RTCStatsReport> remote();
+
+    void addStatistic(const String& name, const String& value);
+    // DEPRECATED
     void addElement(bool isLocal, double timestamp);
-    void addStatistic(bool isLocal, String name, String value);
+    // DEPRECATED
+    void addStatistic(bool isLocal, const String& name, const String& value);
 
 private:
-    RTCStatsReport();
+    RTCStatsReport(const String& id, const String& type, double timestamp);
 
-    RefPtr<RTCStatsElement> m_local;
-    RefPtr<RTCStatsElement> m_remote;
+    String m_id;
+    String m_type;
+    double m_timestamp;
+    HashMap<String, String> m_stats;
 };
 
 } // namespace WebCore
index fe6f7f3..1d6d7b2 100644 (file)
     Conditional=MEDIA_STREAM,
     ImplementationLacksVTable
 ] interface RTCStatsReport {
-    readonly attribute RTCStatsElement local;
-    readonly attribute RTCStatsElement remote;
+    readonly attribute Date timestamp;
+    readonly attribute DOMString id;
+    DOMString stat(in DOMString name);
+    sequence<DOMString> names();
+    // DEPRECATED - fake for old RTCStatsElement object.
+    readonly attribute RTCStatsReport local;
+    readonly attribute RTCStatsReport remote;
 };
index e375cbe..49b652e 100644 (file)
@@ -39,12 +39,33 @@ RTCStatsResponse::RTCStatsResponse()
 {
 }
 
-size_t RTCStatsResponse::addReport()
+PassRefPtr<RTCStatsReport> RTCStatsResponse::namedItem(const AtomicString& name)
+{
+    if (m_idmap.find(name) != m_idmap.end())
+        return m_result[m_idmap.get(name)];
+    return 0;
+}
+
+size_t RTCStatsResponse::addReport(String id, String type, double timestamp)
 {
-    m_result.append(RTCStatsReport::create());
+    m_result.append(RTCStatsReport::create(id, type, timestamp));
+    m_idmap.add(id, m_result.size() - 1);
     return m_result.size() - 1;
 }
 
+void RTCStatsResponse::addStatistic(size_t report, String name, String value)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(report >= 0 && report < m_result.size());
+    m_result[report]->addStatistic(name, value);
+}
+
+// DEPRECATED
+size_t RTCStatsResponse::addReport()
+{
+    String fakeId = String::format("Fake ID %lu", (unsigned long) m_result.size());
+    return addReport(fakeId, "no type", 0);
+}
+
 void RTCStatsResponse::addElement(size_t report, bool isLocal, double timestamp)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(report >= 0 && report < m_result.size());
index d1bccc3..5668a4e 100644 (file)
@@ -35,6 +35,7 @@
 #include "MediaStreamTrack.h"
 #include "RTCStatsReport.h"
 #include "RTCStatsResponseBase.h"
+#include <wtf/HashMap.h>
 
 namespace WebCore {
 
@@ -44,13 +45,21 @@ public:
 
     const Vector<RefPtr<RTCStatsReport> >& result() const { return m_result; };
 
+    PassRefPtr<RTCStatsReport> namedItem(const AtomicString& name);
+
+    virtual size_t addReport(String id, String type, double timestamp) OVERRIDE;
+    virtual void addStatistic(size_t report, String name, String value) OVERRIDE;
+    // DEPRECATED
     virtual size_t addReport() OVERRIDE;
+    // DEPRECATED
     virtual void addElement(size_t report, bool isLocal, double timestamp) OVERRIDE;
+    // DEPRECATED
     virtual void addStatistic(size_t report, bool isLocal, String name, String value) OVERRIDE;
 
 private:
     RTCStatsResponse();
     Vector<RefPtr<RTCStatsReport> > m_result;
+    HashMap<String, int> m_idmap;
 };
 
 } // namespace WebCore
index abcd198..f6e8bb9 100644 (file)
@@ -23,7 +23,9 @@
  */
 
 [
-    Conditional=MEDIA_STREAM
+    Conditional=MEDIA_STREAM,
+    NamedGetter
 ] interface RTCStatsResponse {
     sequence<RTCStatsReport> result();
+    RTCStatsReport namedItem(in [Optional=DefaultIsUndefined] DOMString name);
 };
index fcc1dbe..e80aaf4 100644 (file)
             'Modules/mediastream/RTCSessionDescription.idl',
             'Modules/mediastream/RTCSessionDescriptionCallback.idl',
             'Modules/mediastream/RTCStatsCallback.idl',
-            'Modules/mediastream/RTCStatsElement.idl',
             'Modules/mediastream/RTCStatsReport.idl',
             'Modules/mediastream/RTCStatsResponse.idl',
             'Modules/navigatorcontentutils/NavigatorContentUtils.idl',
             'Modules/mediastream/RTCSessionDescriptionCallback.h',
             'Modules/mediastream/RTCSessionDescriptionRequestImpl.cpp',
             'Modules/mediastream/RTCSessionDescriptionRequestImpl.h',
-            'Modules/mediastream/RTCStatsElement.cpp',
-            'Modules/mediastream/RTCStatsElement.h',
             'Modules/mediastream/RTCStatsReport.cpp',
             'Modules/mediastream/RTCStatsReport.h',
             'Modules/mediastream/RTCStatsRequestImpl.cpp',
index e69c759..f081071 100644 (file)
@@ -55,18 +55,33 @@ WebRTCStatsResponse::operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>() c
     return m_private.get();
 }
 
+size_t WebRTCStatsResponse::addReport(WebString id, WebString type, double timestamp)
+{
+    ASSERT(!m_private.isNull());
+    return m_private->addReport(id, type, timestamp);
+}
+
+void WebRTCStatsResponse::addStatistic(size_t report, WebString name, WebString value)
+{
+    ASSERT(!m_private.isNull());
+    m_private->addStatistic(report, name, value);
+}
+
 size_t WebRTCStatsResponse::addReport()
 {
+    ASSERT(!m_private.isNull());
     return m_private->addReport();
 }
 
 void WebRTCStatsResponse::addElement(size_t report, bool isLocal, double timestamp)
 {
+    ASSERT(!m_private.isNull());
     m_private->addElement(report, isLocal, timestamp);
 }
 
 void WebRTCStatsResponse::addStatistic(size_t report, bool isLocal, WebString name, WebString value)
 {
+    ASSERT(!m_private.isNull());
     m_private->addStatistic(report, isLocal, name, value);
 }
 
index 91cbfa6..c7fa68e 100644 (file)
@@ -37,8 +37,13 @@ class RTCStatsResponseBase : public RefCounted<RTCStatsResponseBase> {
 public:
     virtual ~RTCStatsResponseBase() { }
 
+    virtual size_t addReport(String id, String type, double timestamp) = 0;
+    virtual void addStatistic(size_t report, String name, String value) = 0;
+    // DEPRECATED - use addReport(id, type, timestamp)
     virtual size_t addReport() = 0;
+    // DEPRECATED - use addReport(id, type, timestamp)
     virtual void addElement(size_t report, bool isLocal, double timestamp) = 0;
+    // DEPRECATED - use addStatistic(report, name, value)
     virtual void addStatistic(size_t report, bool isLocal, String name, String value) = 0;
 };
 
index b31277a..799c697 100644 (file)
@@ -1,3 +1,13 @@
+2013-03-08  Harald Alvestrand  <hta@chromium.org>
+
+        Implemented new API for RTCStatsReport object.
+        https://bugs.webkit.org/show_bug.cgi?id=110333
+
+        Reviewed by Adam Barth.
+
+        * DumpRenderTree/chromium/TestRunner/src/MockWebRTCPeerConnectionHandler.cpp:
+        (WebTestRunner::MockWebRTCPeerConnectionHandler::getStats):
+
 2013-03-08  Dirk Pranke  <dpranke@chromium.org>
 
         [chromium] use custom freetype on linux asan builds again
index c0f6366..084ead6 100644 (file)
@@ -273,19 +273,14 @@ void MockWebRTCPeerConnectionHandler::getStats(const WebRTCStatsRequest& request
     if (request.hasSelector()) {
         WebMediaStream stream = request.stream();
         // FIXME: There is no check that the fetched values are valid.
-        size_t reportIndex = response.addReport();
-        response.addElement(reportIndex, true, currentDate);
-        response.addStatistic(reportIndex, true, "type", "video");
+        size_t reportIndex = response.addReport("Mock video", "ssrc", currentDate);
+        response.addStatistic(reportIndex, "type", "video");
     } else {
         for (int i = 0; i < m_streamCount; ++i) {
-            size_t reportIndex = response.addReport();
-            response.addElement(reportIndex, true, currentDate);
-            response.addStatistic(reportIndex, true, "type", "audio");
-            reportIndex = response.addReport();
-            response.addElement(reportIndex, true, currentDate);
-            response.addStatistic(reportIndex, true, "type", "video");
-            // We add an empty remote report element.
-            response.addElement(reportIndex, false, currentDate);
+            size_t reportIndex = response.addReport("Mock audio", "ssrc", currentDate);
+            response.addStatistic(reportIndex, "type", "audio");
+            reportIndex = response.addReport("Mock video", "ssrc", currentDate);
+            response.addStatistic(reportIndex, "type", "video");
         }
     }
     m_interfaces->delegate()->postTask(new RTCStatsRequestSucceededTask(this, request, response));