tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rtc_event_log.h (2380B)


      1 /*
      2 *  Copyright (c) 2015 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 API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
     12 #define API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <functional>
     17 #include <memory>
     18 
     19 #include "api/rtc_event_log/rtc_event.h"
     20 #include "api/rtc_event_log_output.h"
     21 
     22 namespace webrtc {
     23 
     24 class RtcEventLog {
     25 public:
     26  enum : size_t { kUnlimitedOutput = 0 };
     27  enum : int64_t { kImmediateOutput = 0 };
     28 
     29  // TODO(eladalon):  Get rid of the legacy encoding and this enum once all
     30  // clients have migrated to the new format.
     31  enum class EncodingType { Legacy, NewFormat, ProtoFree };
     32 
     33  virtual ~RtcEventLog() = default;
     34 
     35  // Starts logging to a given output. The output might be limited in size,
     36  // and may close itself once it has reached the maximum size.
     37  virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
     38                            int64_t output_period_ms) = 0;
     39 
     40  // Stops logging to file and waits until the file has been closed, after
     41  // which it would be permissible to read and/or modify it.
     42  virtual void StopLogging() = 0;
     43 
     44  // Stops logging to file and calls `callback` when the file has been closed.
     45  // Note that it is not safe to call any other members, including the
     46  // destructor, until the callback has been called.
     47  // TODO(srte): Remove default implementation when it's safe to do so.
     48  virtual void StopLogging(std::function<void()> callback) {
     49    StopLogging();
     50    callback();
     51  }
     52 
     53  // Log an RTC event (the type of event is determined by the subclass).
     54  virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
     55 };
     56 
     57 // No-op implementation is used if flag is not set, or in tests.
     58 class RtcEventLogNull final : public RtcEventLog {
     59 public:
     60  bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
     61                    int64_t output_period_ms) override;
     62  void StopLogging() override {}
     63  void Log(std::unique_ptr<RtcEvent> /* event */) override {}
     64 };
     65 
     66 }  // namespace webrtc
     67 
     68 #endif  // API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_