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