1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_LOG_BUFFER_H_ 6 #define CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_LOG_BUFFER_H_ 7 8 #include <string> 9 10 #include "base/sequence_checker.h" 11 #include "build/build_config.h" 12 #include "components/webrtc_logging/common/partial_circular_buffer.h" 13 14 #if defined(OS_ANDROID) 15 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB 16 #else 17 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB 18 #endif 19 20 class WebRtcLogBuffer { 21 public: 22 WebRtcLogBuffer(); 23 ~WebRtcLogBuffer(); 24 25 void Log(const std::string& message); 26 27 // Returns a circular buffer instance for reading the internal log buffer. 28 // Must only be called after the log has been marked as complete 29 // (see SetComplete) and the caller must ensure that the WebRtcLogBuffer 30 // instance remains in scope for the lifetime of the returned circular buffer. 31 webrtc_logging::PartialCircularBuffer Read(); 32 33 // Switches the buffer to read-only mode, where access to the internal 34 // buffer is allowed from different threads than were used to contribute 35 // to the log. Calls to Log() won't be allowed after calling 36 // SetComplete() and the call to SetComplete() must be done on the same 37 // thread as constructed the buffer and calls Log(). 38 void SetComplete(); 39 40 private: 41 SEQUENCE_CHECKER(sequence_checker_); 42 uint8_t buffer_[kWebRtcLogSize]; 43 webrtc_logging::PartialCircularBuffer circular_; 44 bool read_only_; 45 }; 46 47 #endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_LOG_BUFFER_H_ 48