#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/files/important_file_writer.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <string_view>
#include <utility>
#include "base/check.h"
#include "base/critical_closure.h"
#include "base/debug/alias.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/important_file_writer_cleaner.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_runner.h"
#include "base/threading/platform_thread.h"
#include "base/threading/scoped_thread_priority.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
namespace base {
namespace {
constexpr auto kDefaultCommitInterval = …;
#if BUILDFLAG(IS_WIN)
constexpr int kReplaceRetries = 5;
constexpr int kReplaceRetryFailure = 10;
static_assert(kReplaceRetryFailure > kReplaceRetries, "No overlap allowed");
constexpr auto kReplacePauseInterval = Milliseconds(100);
#endif
void UmaHistogramTimesWithSuffix(const char* histogram_name,
std::string_view histogram_suffix,
base::TimeDelta sample) { … }
void DeleteTmpFileWithRetry(File tmp_file,
const FilePath& tmp_file_path,
int attempt = 0) { … }
}
bool ImportantFileWriter::WriteFileAtomically(
const FilePath& path,
std::string_view data,
std::string_view histogram_suffix) { … }
void ImportantFileWriter::ProduceAndWriteStringToFileAtomically(
const FilePath& path,
BackgroundDataProducerCallback data_producer_for_background_sequence,
OnceClosure before_write_callback,
OnceCallback<void(bool success)> after_write_callback,
const std::string& histogram_suffix) { … }
bool ImportantFileWriter::WriteFileAtomicallyImpl(
const FilePath& path,
std::string_view data,
std::string_view histogram_suffix,
bool from_instance) { … }
ImportantFileWriter::ImportantFileWriter(
const FilePath& path,
scoped_refptr<SequencedTaskRunner> task_runner,
std::string_view histogram_suffix)
: … { … }
ImportantFileWriter::ImportantFileWriter(
const FilePath& path,
scoped_refptr<SequencedTaskRunner> task_runner,
TimeDelta interval,
std::string_view histogram_suffix)
: … { … }
ImportantFileWriter::~ImportantFileWriter() { … }
bool ImportantFileWriter::HasPendingWrite() const { … }
void ImportantFileWriter::WriteNow(std::string data) { … }
void ImportantFileWriter::WriteNowWithBackgroundDataProducer(
BackgroundDataProducerCallback background_data_producer) { … }
void ImportantFileWriter::ScheduleWrite(DataSerializer* serializer) { … }
void ImportantFileWriter::ScheduleWriteWithBackgroundDataSerializer(
BackgroundDataSerializer* serializer) { … }
void ImportantFileWriter::DoScheduledWrite() { … }
void ImportantFileWriter::RegisterOnNextWriteCallbacks(
OnceClosure before_next_write_callback,
OnceCallback<void(bool success)> after_next_write_callback) { … }
void ImportantFileWriter::ClearPendingWrite() { … }
void ImportantFileWriter::SetTimerForTesting(OneShotTimer* timer_override) { … }
}