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

Side by Side Diff: webrtc/api/rtcstatsreport.h

Issue 2241093002: RTCStats and RTCStatsReport added (webrtc/stats) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_API_RTCSTATSREPORT_H_
12 #define WEBRTC_API_RTCSTATSREPORT_H_
13
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <vector>
18
19 #include "webrtc/api/rtcstats.h"
20 #include "webrtc/base/refcount.h"
21 #include "webrtc/base/scoped_ref_ptr.h"
22
23 namespace webrtc {
24
25 // A collection of stats, maps from |RTCStats::id| to |RTCStats|.
26 class RTCStatsReport : public rtc::RefCountInterface {
27 public:
28 typedef std::map<std::string, std::unique_ptr<const RTCStats>> StatsMap;
29
30 class ConstIterator {
31 public:
32 ConstIterator& operator++();
33 ConstIterator& operator++(int);
34 const RTCStats& operator*() const;
35 bool operator==(const ConstIterator& other) const;
36 bool operator!=(const ConstIterator& other) const;
37
38 private:
39 friend class RTCStatsReport;
40 ConstIterator(const rtc::scoped_refptr<const RTCStatsReport>& report,
41 StatsMap::const_iterator it)
42 : report_(report), it_(it) {}
43
44 // Reference report to make sure it is kept alive.
45 rtc::scoped_refptr<const RTCStatsReport> report_;
46 StatsMap::const_iterator it_;
47 };
48
49 static rtc::scoped_refptr<RTCStatsReport> Create();
50
51 bool AddStats(std::unique_ptr<const RTCStats> stats);
52 const RTCStats* operator[](const std::string& id) const;
53 size_t size() const { return stats_.size(); }
54
55 ConstIterator begin() const;
56 ConstIterator end() const;
57
58 // Gets the subset of stats that are of type |T|, where |T| is any class
59 // descending from |RTCStats|.
60 template<typename T>
61 std::vector<const T*> GetStatsOfType() const {
62 std::vector<const T*> stats_of_type;
63 for (const RTCStats& stats : *this) {
64 if (stats.type() == &T::kType)
65 stats_of_type.push_back(&stats.to<const T>());
66 }
67 return stats_of_type;
68 }
69
70 friend class rtc::RefCountedObject<RTCStatsReport>;
71
72 private:
73 StatsMap stats_;
74 };
75
76 } // namespace webrtc
77
78 #endif // WEBRTC_API_RTCSTATSREPORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698