chromium/net/log/file_net_log_observer.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/log/file_net_log_observer.h"

#include <algorithm>
#include <memory>
#include <string>
#include <string_view>
#include <utility>

#include "base/containers/queue.h"
#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/clamped_math.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/values.h"
#include "net/log/net_log_capture_mode.h"
#include "net/log/net_log_entry.h"
#include "net/log/net_log_util.h"
#include "net/url_request/url_request_context.h"

namespace {

// Number of events that can build up in |write_queue_| before a task is posted
// to the file task runner to flush them to disk.
const int kNumWriteQueueEvents =;

// TODO(eroman): Should use something other than 10 for number of files?
const int kDefaultNumFiles =;

scoped_refptr<base::SequencedTaskRunner> CreateFileTaskRunner() {}

// Truncates a file, also reseting the seek position.
void TruncateFile(base::File* file) {}

// Opens |path| in write mode.
base::File OpenFileForWrite(const base::FilePath& path) {}

// Helper that writes data to a file. |file->IsValid()| may be false,
// in which case nothing will be written. Returns the number of bytes
// successfully written (may be less than input data in case of errors).
size_t WriteToFile(base::File* file,
                   std::string_view data1,
                   std::string_view data2 = std::string_view(),
                   std::string_view data3 = std::string_view()) {}

// Copies all of the data at |source_path| and appends it to |destination_file|,
// then deletes |source_path|.
void AppendToFileThenDelete(const base::FilePath& source_path,
                            base::File* destination_file,
                            char* read_buffer,
                            size_t read_buffer_size) {}

base::FilePath SiblingInprogressDirectory(const base::FilePath& log_path) {}

}  // namespace

namespace net {

// Used to store events to be written to file.
EventQueue;

// WriteQueue receives events from FileNetLogObserver on the main thread and
// holds them in a queue until they are drained from the queue and written to
// file on the file task runner.
//
// WriteQueue contains the resources shared between the main thread and the
// file task runner. |lock_| must be acquired to read or write to |queue_| and
// |memory_|.
//
// WriteQueue is refcounted and should be destroyed once all events on the
// file task runner have finished executing.
class FileNetLogObserver::WriteQueue
    : public base::RefCountedThreadSafe<WriteQueue> {};

// FileWriter is responsible for draining events from a WriteQueue and writing
// them to disk. FileWriter can be constructed on any thread, and
// afterwards is only accessed on the file task runner.
class FileNetLogObserver::FileWriter {};

std::unique_ptr<FileNetLogObserver> FileNetLogObserver::CreateBounded(
    const base::FilePath& log_path,
    uint64_t max_total_size,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants) {}

std::unique_ptr<FileNetLogObserver> FileNetLogObserver::CreateUnbounded(
    const base::FilePath& log_path,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants) {}

std::unique_ptr<FileNetLogObserver>
FileNetLogObserver::CreateBoundedPreExisting(
    const base::FilePath& inprogress_dir_path,
    base::File output_file,
    uint64_t max_total_size,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants) {}

std::unique_ptr<FileNetLogObserver>
FileNetLogObserver::CreateUnboundedPreExisting(
    base::File output_file,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants) {}

std::unique_ptr<FileNetLogObserver> FileNetLogObserver::CreateBoundedFile(
    base::File output_file,
    uint64_t max_total_size,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants) {}

FileNetLogObserver::~FileNetLogObserver() {}

void FileNetLogObserver::StartObserving(NetLog* net_log) {}

void FileNetLogObserver::StopObserving(std::unique_ptr<base::Value> polled_data,
                                       base::OnceClosure optional_callback) {}

void FileNetLogObserver::OnAddEntry(const NetLogEntry& entry) {}

std::unique_ptr<FileNetLogObserver> FileNetLogObserver::CreateBoundedForTests(
    const base::FilePath& log_path,
    uint64_t max_total_size,
    size_t total_num_event_files,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants) {}

std::unique_ptr<FileNetLogObserver> FileNetLogObserver::CreateInternal(
    const base::FilePath& log_path,
    const base::FilePath& inprogress_dir_path,
    std::optional<base::File> pre_existing_log_file,
    uint64_t max_total_size,
    size_t total_num_event_files,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants) {}

FileNetLogObserver::FileNetLogObserver(
    scoped_refptr<base::SequencedTaskRunner> file_task_runner,
    std::unique_ptr<FileWriter> file_writer,
    scoped_refptr<WriteQueue> write_queue,
    NetLogCaptureMode capture_mode,
    std::unique_ptr<base::Value::Dict> constants)
    :{}

std::string FileNetLogObserver::CaptureModeToString(NetLogCaptureMode mode) {}

FileNetLogObserver::WriteQueue::WriteQueue(uint64_t memory_max)
    :{}

size_t FileNetLogObserver::WriteQueue::AddEntryToQueue(
    std::unique_ptr<std::string> event) {}

void FileNetLogObserver::WriteQueue::SwapQueue(EventQueue* local_queue) {}

FileNetLogObserver::WriteQueue::~WriteQueue() = default;

FileNetLogObserver::FileWriter::FileWriter(
    const base::FilePath& log_path,
    const base::FilePath& inprogress_dir_path,
    std::optional<base::File> pre_existing_log_file,
    uint64_t max_event_file_size,
    size_t total_num_event_files,
    scoped_refptr<base::SequencedTaskRunner> task_runner)
    :{}

FileNetLogObserver::FileWriter::~FileWriter() = default;

void FileNetLogObserver::FileWriter::Initialize(
    std::unique_ptr<base::Value::Dict> constants_value) {}

void FileNetLogObserver::FileWriter::Stop(
    std::unique_ptr<base::Value> polled_data) {}

void FileNetLogObserver::FileWriter::Flush(
    scoped_refptr<FileNetLogObserver::WriteQueue> write_queue) {}

void FileNetLogObserver::FileWriter::DeleteAllFiles() {}

void FileNetLogObserver::FileWriter::FlushThenStop(
    scoped_refptr<FileNetLogObserver::WriteQueue> write_queue,
    std::unique_ptr<base::Value> polled_data) {}

bool FileNetLogObserver::FileWriter::IsUnbounded() const {}

bool FileNetLogObserver::FileWriter::IsBounded() const {}

bool FileNetLogObserver::FileWriter::IsBoundedAndStitchable() const {}

void FileNetLogObserver::FileWriter::IncrementCurrentEventFile() {}

base::FilePath FileNetLogObserver::FileWriter::GetEventFilePath(
    size_t index) const {}

base::FilePath FileNetLogObserver::FileWriter::GetConstantsFilePath() const {}

base::FilePath FileNetLogObserver::FileWriter::GetClosingFilePath() const {}

size_t FileNetLogObserver::FileWriter::FileNumberToIndex(
    size_t file_number) const {}

void FileNetLogObserver::FileWriter::WriteConstantsToFile(
    std::unique_ptr<base::Value::Dict> constants_value,
    base::File* file) {}

void FileNetLogObserver::FileWriter::WritePolledDataToFile(
    std::unique_ptr<base::Value> polled_data,
    base::File* file) {}

void FileNetLogObserver::FileWriter::RewindIfWroteEventBytes(
    base::File* file) const {}

void FileNetLogObserver::FileWriter::StitchFinalLogFile() {}

void FileNetLogObserver::FileWriter::CreateInprogressDirectory() {}

std::string SerializeNetLogValueToJson(const base::ValueView& value) {}

}  // namespace net