1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/scoped_temp_dir.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +// Copyright (c) 2009 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/scoped_temp_dir.h" 1.9 + 1.10 +#include "base/file_util.h" 1.11 +#include "base/logging.h" 1.12 +#include "base/string_util.h" 1.13 + 1.14 +ScopedTempDir::ScopedTempDir() { 1.15 +} 1.16 + 1.17 +ScopedTempDir::~ScopedTempDir() { 1.18 + if (!path_.empty() && !file_util::Delete(path_, true)) 1.19 + CHROMIUM_LOG(ERROR) << "ScopedTempDir unable to delete " << path_.value(); 1.20 +} 1.21 + 1.22 +bool ScopedTempDir::CreateUniqueTempDir() { 1.23 + // This "scoped_dir" prefix is only used on Windows and serves as a template 1.24 + // for the unique name. 1.25 + if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), 1.26 + &path_)) 1.27 + return false; 1.28 + 1.29 + return true; 1.30 +} 1.31 + 1.32 +bool ScopedTempDir::Set(const FilePath& path) { 1.33 + DCHECK(path_.empty()); 1.34 + if (!file_util::DirectoryExists(path) && 1.35 + !file_util::CreateDirectory(path)) { 1.36 + return false; 1.37 + } 1.38 + path_ = path; 1.39 + return true; 1.40 +} 1.41 + 1.42 +FilePath ScopedTempDir::Take() { 1.43 + FilePath ret = path_; 1.44 + path_ = FilePath(); 1.45 + return ret; 1.46 +} 1.47 + 1.48 +bool ScopedTempDir::IsValid() const { 1.49 + return !path_.empty() && file_util::DirectoryExists(path_); 1.50 +}