1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2016 The WebRTC Project Authors. All rights reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef PC_TEST_RTC_STATS_OBTAINER_H_ 12*d9f75844SAndroid Build Coastguard Worker #define PC_TEST_RTC_STATS_OBTAINER_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include "api/make_ref_counted.h" 15*d9f75844SAndroid Build Coastguard Worker #include "api/sequence_checker.h" 16*d9f75844SAndroid Build Coastguard Worker #include "api/stats/rtc_stats_collector_callback.h" 17*d9f75844SAndroid Build Coastguard Worker #include "api/stats/rtc_stats_report.h" 18*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/gunit.h" 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 21*d9f75844SAndroid Build Coastguard Worker 22*d9f75844SAndroid Build Coastguard Worker class RTCStatsObtainer : public RTCStatsCollectorCallback { 23*d9f75844SAndroid Build Coastguard Worker public: 24*d9f75844SAndroid Build Coastguard Worker static rtc::scoped_refptr<RTCStatsObtainer> Create( 25*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<const RTCStatsReport>* report_ptr = nullptr) { 26*d9f75844SAndroid Build Coastguard Worker return rtc::make_ref_counted<RTCStatsObtainer>(report_ptr); 27*d9f75844SAndroid Build Coastguard Worker } 28*d9f75844SAndroid Build Coastguard Worker OnStatsDelivered(const rtc::scoped_refptr<const RTCStatsReport> & report)29*d9f75844SAndroid Build Coastguard Worker void OnStatsDelivered( 30*d9f75844SAndroid Build Coastguard Worker const rtc::scoped_refptr<const RTCStatsReport>& report) override { 31*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(thread_checker_.IsCurrent()); 32*d9f75844SAndroid Build Coastguard Worker report_ = report; 33*d9f75844SAndroid Build Coastguard Worker if (report_ptr_) 34*d9f75844SAndroid Build Coastguard Worker *report_ptr_ = report_; 35*d9f75844SAndroid Build Coastguard Worker } 36*d9f75844SAndroid Build Coastguard Worker report()37*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<const RTCStatsReport> report() const { 38*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(thread_checker_.IsCurrent()); 39*d9f75844SAndroid Build Coastguard Worker return report_; 40*d9f75844SAndroid Build Coastguard Worker } 41*d9f75844SAndroid Build Coastguard Worker 42*d9f75844SAndroid Build Coastguard Worker protected: RTCStatsObtainer(rtc::scoped_refptr<const RTCStatsReport> * report_ptr)43*d9f75844SAndroid Build Coastguard Worker explicit RTCStatsObtainer( 44*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<const RTCStatsReport>* report_ptr) 45*d9f75844SAndroid Build Coastguard Worker : report_ptr_(report_ptr) {} 46*d9f75844SAndroid Build Coastguard Worker 47*d9f75844SAndroid Build Coastguard Worker private: 48*d9f75844SAndroid Build Coastguard Worker SequenceChecker thread_checker_; 49*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<const RTCStatsReport> report_; 50*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<const RTCStatsReport>* report_ptr_; 51*d9f75844SAndroid Build Coastguard Worker }; 52*d9f75844SAndroid Build Coastguard Worker 53*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 54*d9f75844SAndroid Build Coastguard Worker 55*d9f75844SAndroid Build Coastguard Worker #endif // PC_TEST_RTC_STATS_OBTAINER_H_ 56