#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/media/webrtc/webrtc_log_uploader.h"
#include <stddef.h>
#include <cstdlib>
#include <utility>
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/pickle.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "components/version_info/version_info.h"
#include "components/webrtc_logging/browser/log_cleanup.h"
#include "components/webrtc_logging/browser/text_log_list.h"
#include "components/webrtc_logging/common/partial_circular_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/mime_util.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/zlib/zlib.h"
namespace {
const int kLogCountLimit = …;
const uint32_t kIntermediateCompressionBufferBytes = …;
const int kLogListLimitLines = …;
const char kWebrtcLogUploadContentType[] = …;
const char kWebrtcLogMultipartBoundary[] = …;
void AddMultipartFileContentHeader(std::string* post_data,
const std::string& content_name) { … }
void AddLogData(std::string* post_data, const std::string& compressed_log) { … }
void AddRtpDumpData(std::string* post_data,
const std::string& name,
const std::string& dump_data) { … }
void ResizeForNextOutput(std::string* compressed_log, z_stream* stream) { … }
}
BASE_FEATURE(…);
std::string GetLogUploadProduct() { … }
std::string GetLogUploadVersion() { … }
WebRtcLogUploader::UploadDoneData::UploadDoneData() = default;
WebRtcLogUploader::UploadDoneData::UploadDoneData(
WebRtcLogUploader::UploadDoneData&& other) = default;
WebRtcLogUploader::UploadDoneData::~UploadDoneData() = default;
WebRtcLogUploader* WebRtcLogUploader::GetInstance() { … }
WebRtcLogUploader::WebRtcLogUploader()
: … { … }
WebRtcLogUploader::~WebRtcLogUploader() { … }
bool WebRtcLogUploader::ApplyForStartLogging() { … }
void WebRtcLogUploader::LoggingStoppedDontUpload() { … }
void WebRtcLogUploader::OnLoggingStopped(
std::unique_ptr<WebRtcLogBuffer> log_buffer,
std::unique_ptr<WebRtcLogMetaDataMap> meta_data,
WebRtcLogUploader::UploadDoneData upload_done_data,
bool is_text_log_upload_allowed) { … }
void WebRtcLogUploader::PrepareMultipartPostData(
const std::string& compressed_log,
std::unique_ptr<WebRtcLogMetaDataMap> meta_data,
WebRtcLogUploader::UploadDoneData upload_done_data) { … }
void WebRtcLogUploader::UploadStoredLog(
WebRtcLogUploader::UploadDoneData upload_data) { … }
void WebRtcLogUploader::LoggingStoppedDoStore(
const WebRtcLogPaths& log_paths,
const std::string& log_id,
std::unique_ptr<WebRtcLogBuffer> log_buffer,
std::unique_ptr<WebRtcLogMetaDataMap> meta_data,
GenericDoneCallback done_callback) { … }
void WebRtcLogUploader::Shutdown() { … }
void WebRtcLogUploader::OnSimpleLoaderComplete(
SimpleURLLoaderList::iterator it,
WebRtcLogUploader::UploadDoneData upload_done_data,
std::unique_ptr<std::string> response_body) { … }
void WebRtcLogUploader::SetupMultipart(
std::string* post_data,
const std::string& compressed_log,
const base::FilePath& incoming_rtp_dump,
const base::FilePath& outgoing_rtp_dump,
const std::map<std::string, std::string>& meta_data) { … }
std::string WebRtcLogUploader::CompressLog(WebRtcLogBuffer* buffer) { … }
void WebRtcLogUploader::UploadCompressedLog(
WebRtcLogUploader::UploadDoneData upload_done_data,
std::unique_ptr<std::string> post_data) { … }
void WebRtcLogUploader::DecreaseLogCount() { … }
void WebRtcLogUploader::WriteCompressedLogToFile(
const std::string& compressed_log,
const base::FilePath& log_file_path) { … }
void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile(
const base::FilePath& upload_list_path,
const std::string& local_log_id) { … }
void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile(
const base::FilePath& upload_list_path,
const std::string& local_log_id,
const std::string& report_id) { … }
void WebRtcLogUploader::NotifyUploadDoneAndLogStats(
std::optional<int> response_code,
int network_error_code,
const std::string& report_id,
WebRtcLogUploader::UploadDoneData upload_done_data) { … }
void WebRtcLogUploader::NotifyUploadDisabled(UploadDoneData upload_done_data) { … }