tor-browser

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

rtc_event_log_output_file.h (1868B)


      1 /*
      2 *  Copyright (c) 2017 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_OUTPUT_FILE_H_
     12 #define API_RTC_EVENT_LOG_OUTPUT_FILE_H_
     13 
     14 #include <stddef.h>
     15 #include <stdio.h>
     16 
     17 #include <string>
     18 
     19 #include "absl/strings/string_view.h"
     20 #include "api/rtc_event_log_output.h"
     21 #include "rtc_base/system/file_wrapper.h"
     22 
     23 namespace webrtc {
     24 
     25 class RtcEventLogOutputFile final : public RtcEventLogOutput {
     26 public:
     27  static const size_t kMaxReasonableFileSize;  // Explanation at declaration.
     28 
     29  // Unlimited/limited-size output file (by filename).
     30  explicit RtcEventLogOutputFile(const std::string& file_name);
     31  RtcEventLogOutputFile(const std::string& file_name, size_t max_size_bytes);
     32 
     33  // Limited-size output file (by FILE*). This class takes ownership
     34  // of the FILE*, and closes it on destruction.
     35  RtcEventLogOutputFile(FILE* file, size_t max_size_bytes);
     36 
     37  ~RtcEventLogOutputFile() override = default;
     38 
     39  bool IsActive() const override;
     40 
     41  bool Write(absl::string_view output) override;
     42 
     43 private:
     44  RtcEventLogOutputFile(FileWrapper file, size_t max_size_bytes);
     45 
     46  // IsActive() can be called either from outside or from inside, but we don't
     47  // want to incur the overhead of a virtual function call if called from inside
     48  // some other function of this class.
     49  inline bool IsActiveInternal() const;
     50 
     51  // Maximum size, or zero for no limit.
     52  const size_t max_size_bytes_;
     53  size_t written_bytes_{0};
     54  FileWrapper file_;
     55 };
     56 
     57 }  // namespace webrtc
     58 
     59 #endif  // API_RTC_EVENT_LOG_OUTPUT_FILE_H_