#include "remoting/host/crash/crash_file_uploader.h"
#include <list>
#include <memory>
#include <string>
#include <utility>
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/single_thread_task_runner_thread_mode.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "build/buildflag.h"
#include "net/base/load_flags.h"
#include "net/base/mime_util.h"
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "remoting/base/breakpad_utils.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_response_head.mojom.h"
namespace remoting {
namespace {
constexpr char kProductNameKey[] = …;
constexpr char kProductVersionKey[] = …;
constexpr char kProcessUptimeKey[] = …;
constexpr char kMinidumpFileKey[] = …;
constexpr char kMinidumpFileName[] = …;
#if BUILDFLAG(IS_WIN)
constexpr char kProductNameValue[] = "Chromoting";
#elif BUILDFLAG(IS_LINUX)
constexpr char kProductNameValue[] = …;
#elif BUILDFLAG(IS_MAC)
constexpr char kProductNameValue[] = "Chromoting_Mac";
#else
#error Platform not supported
#endif
const base::FilePath::CharType kDumpExtension[] = …);
const base::FilePath::CharType kJsonExtension[] = …);
const base::FilePath::CharType kLastUploadTimeFilePath[] = …);
const base::FilePath::CharType kUploadResultFilePath[] = …);
constexpr char kCrashReportUploadUrl[] = …;
constexpr int kPostFormReservationSize = …;
constexpr size_t kMaxResponseSize = …;
constexpr base::TimeDelta kUploadRateLimitWindow = …;
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
base::FilePath GetLastUploadTimeFilePath() { … }
base::FilePath GetCrashDirectoryPath(const base::FilePath& crash_guid) { … }
base::FilePath GetCrashFileBase(const base::FilePath& crash_guid) { … }
base::FilePath GetDumpFilePath(const base::FilePath& crash_guid) { … }
base::FilePath GetMetadataFilePath(const base::FilePath& crash_guid) { … }
bool RetrieveCrashReportDetails(const base::FilePath& crash_guid,
std::string& minidump_file_contents,
base::Value::Dict& metadata,
std::string& error_reason) { … }
void DeleteDumpFileAndWriteResult(const base::FilePath& crash_file,
const std::string& result) { … }
std::unique_ptr<network::SimpleURLLoader> CreateSimpleUrlLoader() { … }
void GenerateMultiPartPostData(const base::Value::Dict& metadata,
const std::string& minidump_data,
std::string& post_data,
std::string& content_type) { … }
void DeleteFileWithLogging(const base::FilePath& file_to_delete) { … }
bool SkipUploadDueToRateLimiting() { … }
void UpdateLastUploadTimeFile() { … }
}
class CrashFileUploader::Core { … };
CrashFileUploader::Core::Core(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: … { … }
CrashFileUploader::Core::~Core() { … }
void CrashFileUploader::Core::Upload(const base::FilePath& crash_guid) { … }
void CrashFileUploader::Core::OnUploadComplete(
SimpleURLLoaderList::iterator it,
base::FilePath crash_guid,
std::unique_ptr<std::string> response_body) { … }
CrashFileUploader::CrashFileUploader(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<base::SingleThreadTaskRunner> core_task_runner)
: … { … }
CrashFileUploader::~CrashFileUploader() { … }
void CrashFileUploader::Upload(const base::FilePath& crash_guid) { … }
}