1 // Copyright (c) 2011 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.
5 #ifndef BASE_SCOPED_TEMP_DIR_H_
6 #define BASE_SCOPED_TEMP_DIR_H_
9 // An object representing a temporary / scratch directory that should be cleaned
10 // up (recursively) when this object goes out of scope. Note that since
11 // deletion occurs during the destructor, no further error handling is possible
12 // if the directory fails to be deleted. As a result, deletion is not
13 // guaranteed by this class.
15 // Multiple calls to the methods which establish a temporary directory
16 // (CreateUniqueTempDir, CreateUniqueTempDirUnderPath, and Set) must have
17 // intervening calls to Delete or Take, or the calls will fail.
19 #include "base/base_export.h"
20 #include "base/file_path.h"
22 class BASE_EXPORT ScopedTempDir
{
24 // No directory is owned/created initially.
27 // Recursively delete path.
30 // Creates a unique directory in TempPath, and takes ownership of it.
31 // See file_util::CreateNewTemporaryDirectory.
32 bool CreateUniqueTempDir() WARN_UNUSED_RESULT
;
34 // Creates a unique directory under a given path, and takes ownership of it.
35 bool CreateUniqueTempDirUnderPath(const FilePath
& path
) WARN_UNUSED_RESULT
;
37 // Takes ownership of directory at |path|, creating it if necessary.
38 // Don't call multiple times unless Take() has been called first.
39 bool Set(const FilePath
& path
) WARN_UNUSED_RESULT
;
41 // Deletes the temporary directory wrapped by this object.
42 bool Delete() WARN_UNUSED_RESULT
;
44 // Caller takes ownership of the temporary directory so it won't be destroyed
45 // when this object goes out of scope.
48 const FilePath
& path() const { return path_
; }
50 // Returns true if path_ is non-empty and exists.
56 DISALLOW_COPY_AND_ASSIGN(ScopedTempDir
);
59 #endif // BASE_SCOPED_TEMP_DIR_H_