1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_CHROME_CLEANER_OS_FILE_REMOVER_API_H_
6 #define CHROME_CHROME_CLEANER_OS_FILE_REMOVER_API_H_
7 
8 #include <vector>
9 
10 #include "base/callback.h"
11 #include "base/files/file_path.h"
12 #include "chrome/chrome_cleaner/os/file_path_set.h"
13 
14 namespace chrome_cleaner {
15 
16 // This class is used as a wrapper around the OS calls to remove files. This
17 // allows test to more easily provide mock for these OS calls.
18 class FileRemoverAPI {
19  public:
20   enum class DeletionValidationStatus {
21     ALLOWED,
22     FORBIDDEN,
23 
24     // Path is unsafe (eg. a UNC path that could be a network share). Do not
25     // even call functions like SanitizePath or NormalizePath on it.
26     UNSAFE,
27   };
28   // Callback used for the asynchronous versions of RemoveNow
29   // and RegisterPostRebootRemoval.
30   typedef base::OnceCallback<void(bool)> DoneCallback;
31 
~FileRemoverAPI()32   virtual ~FileRemoverAPI() {}
33 
34   // Remove file at |path| from the user's disk. Return false on failure.
35   virtual void RemoveNow(const base::FilePath& path,
36                          DoneCallback callback) const = 0;
37 
38   // Register the file in |file_path| to be deleted after a machine reboot.
39   // Return false on failure.
40   virtual void RegisterPostRebootRemoval(const base::FilePath& file_path,
41                                          DoneCallback callback) const = 0;
42 
43   // Check if file at |path| is not whitelisted and can be deleted.
44   virtual DeletionValidationStatus CanRemove(
45       const base::FilePath& path) const = 0;
46 };
47 
48 }  // namespace chrome_cleaner
49 
50 #endif  // CHROME_CHROME_CLEANER_OS_FILE_REMOVER_API_H_
51