| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_SCOPED_TEMP_DIR_H_ | 5 #ifndef BASE_SCOPED_TEMP_DIR_H_ |
| 6 #define BASE_SCOPED_TEMP_DIR_H_ | 6 #define BASE_SCOPED_TEMP_DIR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // An object representing a temporary / scratch directory that should be cleaned | 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 | 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 | 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 | 12 // if the directory fails to be deleted. As a result, deletion is not |
| 13 // guaranteed by this class. | 13 // guaranteed by this class. |
| 14 | 14 |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 | 16 |
| 17 class ScopedTempDir { | 17 class ScopedTempDir { |
| 18 public: | 18 public: |
| 19 // No directory is owned/created initially. | 19 // No directory is owned/created initially. |
| 20 ScopedTempDir(); | 20 ScopedTempDir(); |
| 21 | 21 |
| 22 // Recursively delete path_ | 22 // Recursively delete path_ |
| 23 ~ScopedTempDir(); | 23 ~ScopedTempDir(); |
| 24 | 24 |
| 25 // Creates a unique directory in TempPath, and takes ownership of it. | 25 // Creates a unique directory in TempPath, and takes ownership of it. |
| 26 // See file_util::CreateNewTemporaryDirectory. | 26 // See file_util::CreateNewTemporaryDirectory. |
| 27 bool CreateUniqueTempDir(); | 27 bool CreateUniqueTempDir(); |
| 28 | 28 |
| 29 // Creates a unique directory under a given path, and takes ownership of it. | 29 // Creates a unique directory under a given path, and takes ownership of it. |
| 30 bool CreateUniqueTempDirUnderPath(const FilePath& path, | 30 bool CreateUniqueTempDirUnderPath(const FilePath& path); |
| 31 bool loose_permissions); | |
| 32 | 31 |
| 33 // Takes ownership of directory at |path|, creating it if necessary. | 32 // Takes ownership of directory at |path|, creating it if necessary. |
| 34 // Don't call multiple times unless Take() has been called first. | 33 // Don't call multiple times unless Take() has been called first. |
| 35 bool Set(const FilePath& path); | 34 bool Set(const FilePath& path); |
| 36 | 35 |
| 37 // Caller takes ownership of the temporary directory so it won't be destroyed | 36 // Caller takes ownership of the temporary directory so it won't be destroyed |
| 38 // when this object goes out of scope. | 37 // when this object goes out of scope. |
| 39 FilePath Take(); | 38 FilePath Take(); |
| 40 | 39 |
| 41 const FilePath& path() const { return path_; } | 40 const FilePath& path() const { return path_; } |
| 42 | 41 |
| 43 // Returns true if path_ is non-empty and exists. | 42 // Returns true if path_ is non-empty and exists. |
| 44 bool IsValid() const; | 43 bool IsValid() const; |
| 45 | 44 |
| 46 private: | 45 private: |
| 47 FilePath path_; | 46 FilePath path_; |
| 48 | 47 |
| 49 DISALLOW_COPY_AND_ASSIGN(ScopedTempDir); | 48 DISALLOW_COPY_AND_ASSIGN(ScopedTempDir); |
| 50 }; | 49 }; |
| 51 | 50 |
| 52 #endif // BASE_SCOPED_TEMP_DIR_H_ | 51 #endif // BASE_SCOPED_TEMP_DIR_H_ |
| OLD | NEW |