Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / base / files / scoped_temp_dir.h
blob5f63e09cff8fe0b915e23eeb28dd758a5acc3a88
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_FILES_SCOPED_TEMP_DIR_H_
6 #define BASE_FILES_SCOPED_TEMP_DIR_H_
8 // An object representing a temporary / scratch directory that should be cleaned
9 // up (recursively) when this object goes out of scope. Note that since
10 // deletion occurs during the destructor, no further error handling is possible
11 // if the directory fails to be deleted. As a result, deletion is not
12 // guaranteed by this class.
14 // Multiple calls to the methods which establish a temporary directory
15 // (CreateUniqueTempDir, CreateUniqueTempDirUnderPath, and Set) must have
16 // intervening calls to Delete or Take, or the calls will fail.
18 #include "base/base_export.h"
19 #include "base/files/file_path.h"
21 namespace base {
23 class BASE_EXPORT ScopedTempDir {
24 public:
25 // No directory is owned/created initially.
26 ScopedTempDir();
28 // Recursively delete path.
29 ~ScopedTempDir();
31 // Creates a unique directory in TempPath, and takes ownership of it.
32 // See file_util::CreateNewTemporaryDirectory.
33 bool CreateUniqueTempDir() WARN_UNUSED_RESULT;
35 // Creates a unique directory under a given path, and takes ownership of it.
36 bool CreateUniqueTempDirUnderPath(const FilePath& path) WARN_UNUSED_RESULT;
38 // Takes ownership of directory at |path|, creating it if necessary.
39 // Don't call multiple times unless Take() has been called first.
40 bool Set(const FilePath& path) WARN_UNUSED_RESULT;
42 // Deletes the temporary directory wrapped by this object.
43 bool Delete() WARN_UNUSED_RESULT;
45 // Caller takes ownership of the temporary directory so it won't be destroyed
46 // when this object goes out of scope.
47 FilePath Take();
49 const FilePath& path() const { return path_; }
51 // Returns true if path_ is non-empty and exists.
52 bool IsValid() const;
54 private:
55 FilePath path_;
57 DISALLOW_COPY_AND_ASSIGN(ScopedTempDir);
60 } // namespace base
62 #endif // BASE_FILES_SCOPED_TEMP_DIR_H_