1 // Copyright 2020 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_INSTALLER_MINI_INSTALLER_DELETE_WITH_RETRY_H_
6 #define CHROME_INSTALLER_MINI_INSTALLER_DELETE_WITH_RETRY_H_
7 
8 namespace mini_installer {
9 
10 // Deletes the file or directory at |path|, retrying for up to ten seconds.
11 // Returns false if |path| indicates a directory that is not empty or if the
12 // item could not be deleted after ten seconds of effort. Otherwise, returns
13 // true once the item has been deleted. |attempts| is populated with the number
14 // of attempts needed to reach the result (e.g., a value of 1 means that the
15 // item was deleted on the first attempt and no sleeping was required).
16 bool DeleteWithRetry(const wchar_t* path, int& attempts);
17 
18 // Sets a function with accompanying context that will be called by
19 // DeleteWithRetry when it sleeps before a retry. Returns the previous sleep
20 // function.
21 using SleepFunction = void (*)(void*);
22 SleepFunction SetRetrySleepHookForTesting(SleepFunction hook_fn,
23                                           void* hook_context);
24 
25 }  // namespace mini_installer
26 
27 #endif  // CHROME_INSTALLER_MINI_INSTALLER_DELETE_WITH_RETRY_H_
28