summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/peerconnection/test_webrtc_stats_report_obtainer.h
blob: 9d376e05f27fe58efa6f69f6e57c85c68b86ae2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_TEST_WEBRTC_STATS_REPORT_OBTAINER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_TEST_WEBRTC_STATS_REPORT_OBTAINER_H_

#include <memory>

#include "base/run_loop.h"
#include "third_party/blink/public/platform/web_rtc_stats.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"

namespace blink {

// The obtainer is a test-only helper class capable of waiting for a GetStats()
// callback to be called. It takes ownership of and exposes the resulting
// RTCStatsReportPlatform.
// While WaitForReport() is waiting for the report, tasks posted on the current
// thread are executed (see base::RunLoop::Run()) making it safe to wait on the
// same thread that the stats report callback occurs on without blocking the
// callback.
class TestWebRTCStatsReportObtainer
    : public WTF::ThreadSafeRefCounted<TestWebRTCStatsReportObtainer> {
 public:
  TestWebRTCStatsReportObtainer();

  blink::WebRTCStatsReportCallback GetStatsCallbackWrapper();

  RTCStatsReportPlatform* report() const;
  RTCStatsReportPlatform* WaitForReport();

 private:
  friend class WTF::ThreadSafeRefCounted<TestWebRTCStatsReportObtainer>;
  friend class CallbackWrapper;
  virtual ~TestWebRTCStatsReportObtainer();

  void OnStatsDelivered(std::unique_ptr<RTCStatsReportPlatform> report);

  base::RunLoop run_loop_;
  std::unique_ptr<RTCStatsReportPlatform> report_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_TEST_WEBRTC_STATS_REPORT_OBTAINER_H_