michael@0: // Copyright (c) 2009 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_SCOPED_TEMP_DIR_H_ michael@0: #define BASE_SCOPED_TEMP_DIR_H_ michael@0: michael@0: // An object representing a temporary / scratch directory that should be cleaned michael@0: // up (recursively) when this object goes out of scope. Note that since michael@0: // deletion occurs during the destructor, no further error handling is possible michael@0: // if the directory fails to be deleted. As a result, deletion is not michael@0: // guaranteed by this class. michael@0: michael@0: #include "base/file_path.h" michael@0: michael@0: class ScopedTempDir { michael@0: public: michael@0: // No directory is owned/created initially. michael@0: ScopedTempDir(); michael@0: michael@0: // Recursively delete path_ michael@0: ~ScopedTempDir(); michael@0: michael@0: // Creates a unique directory in TempPath, and takes ownership of it. michael@0: // See file_util::CreateNewTemporaryDirectory. michael@0: bool CreateUniqueTempDir(); michael@0: michael@0: // Takes ownership of directory at |path|, creating it if necessary. michael@0: // Don't call multiple times unless Take() has been called first. michael@0: bool Set(const FilePath& path); michael@0: michael@0: // Caller takes ownership of the temporary directory so it won't be destroyed michael@0: // when this object goes out of scope. michael@0: FilePath Take(); michael@0: michael@0: const FilePath& path() const { return path_; } michael@0: michael@0: // Returns true if path_ is non-empty and exists. michael@0: bool IsValid() const; michael@0: michael@0: private: michael@0: FilePath path_; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(ScopedTempDir); michael@0: }; michael@0: michael@0: #endif // BASE_SCOPED_TEMP_DIR_H_