rtc_stats_obtainer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #ifndef PC_TEST_RTC_STATS_OBTAINER_H_
  11. #define PC_TEST_RTC_STATS_OBTAINER_H_
  12. #include "api/stats/rtc_stats_report.h"
  13. #include "rtc_base/gunit.h"
  14. namespace webrtc {
  15. class RTCStatsObtainer : public RTCStatsCollectorCallback {
  16. public:
  17. static rtc::scoped_refptr<RTCStatsObtainer> Create(
  18. rtc::scoped_refptr<const RTCStatsReport>* report_ptr = nullptr) {
  19. return rtc::scoped_refptr<RTCStatsObtainer>(
  20. new rtc::RefCountedObject<RTCStatsObtainer>(report_ptr));
  21. }
  22. void OnStatsDelivered(
  23. const rtc::scoped_refptr<const RTCStatsReport>& report) override {
  24. EXPECT_TRUE(thread_checker_.IsCurrent());
  25. report_ = report;
  26. if (report_ptr_)
  27. *report_ptr_ = report_;
  28. }
  29. rtc::scoped_refptr<const RTCStatsReport> report() const {
  30. EXPECT_TRUE(thread_checker_.IsCurrent());
  31. return report_;
  32. }
  33. protected:
  34. explicit RTCStatsObtainer(
  35. rtc::scoped_refptr<const RTCStatsReport>* report_ptr)
  36. : report_ptr_(report_ptr) {}
  37. private:
  38. rtc::ThreadChecker thread_checker_;
  39. rtc::scoped_refptr<const RTCStatsReport> report_;
  40. rtc::scoped_refptr<const RTCStatsReport>* report_ptr_;
  41. };
  42. } // namespace webrtc
  43. #endif // PC_TEST_RTC_STATS_OBTAINER_H_