chromium/base/files/important_file_writer_cleaner.h

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

#ifndef BASE_FILES_IMPORTANT_FILE_WRITER_CLEANER_H_
#define BASE_FILES_IMPORTANT_FILE_WRITER_CLEANER_H_

#include <atomic>
#include <vector>

#include "base/base_export.h"
#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "base/numerics/clamped_math.h"
#include "base/sequence_checker.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "base/time/time.h"

namespace base {

class SequencedTaskRunner;

// A cleaner for forgotten .tmp files left behind by ImportantFileWriter; see
// https://crbug.com/1075917.
//
// ImportantFileWriter has the potential to leak .tmp files in case of a crash
// or power failure during processing, or in case of interference by third-party
// software. This class implements a singleton that makes a single scan over
// given directories to delete any *.tmp files older than the current process.
// Processes that use ImportantFileWriter are expected to call the instance's
// Start method at some point during startup to enable the cleaner.
// ImportantFileWriter calls the AddDirectory method to provide the directory
// hosting an "important" file. Hosting processes are expected to call the Stop
// method at shutdown.
//
// The deletion scan takes place in a background task.
class BASE_EXPORT ImportantFileWriterCleaner {};

}  // namespace base

#endif  // BASE_FILES_IMPORTANT_FILE_WRITER_CLEANER_H_