xref: /aosp_15_r20/external/webrtc/pc/test/rtc_stats_obtainer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 PC_TEST_RTC_STATS_OBTAINER_H_
12 #define PC_TEST_RTC_STATS_OBTAINER_H_
13 
14 #include "api/make_ref_counted.h"
15 #include "api/sequence_checker.h"
16 #include "api/stats/rtc_stats_collector_callback.h"
17 #include "api/stats/rtc_stats_report.h"
18 #include "rtc_base/gunit.h"
19 
20 namespace webrtc {
21 
22 class RTCStatsObtainer : public RTCStatsCollectorCallback {
23  public:
24   static rtc::scoped_refptr<RTCStatsObtainer> Create(
25       rtc::scoped_refptr<const RTCStatsReport>* report_ptr = nullptr) {
26     return rtc::make_ref_counted<RTCStatsObtainer>(report_ptr);
27   }
28 
OnStatsDelivered(const rtc::scoped_refptr<const RTCStatsReport> & report)29   void OnStatsDelivered(
30       const rtc::scoped_refptr<const RTCStatsReport>& report) override {
31     EXPECT_TRUE(thread_checker_.IsCurrent());
32     report_ = report;
33     if (report_ptr_)
34       *report_ptr_ = report_;
35   }
36 
report()37   rtc::scoped_refptr<const RTCStatsReport> report() const {
38     EXPECT_TRUE(thread_checker_.IsCurrent());
39     return report_;
40   }
41 
42  protected:
RTCStatsObtainer(rtc::scoped_refptr<const RTCStatsReport> * report_ptr)43   explicit RTCStatsObtainer(
44       rtc::scoped_refptr<const RTCStatsReport>* report_ptr)
45       : report_ptr_(report_ptr) {}
46 
47  private:
48   SequenceChecker thread_checker_;
49   rtc::scoped_refptr<const RTCStatsReport> report_;
50   rtc::scoped_refptr<const RTCStatsReport>* report_ptr_;
51 };
52 
53 }  // namespace webrtc
54 
55 #endif  // PC_TEST_RTC_STATS_OBTAINER_H_
56