Changed mft_h264_decoder's API to match with video_decode_engine.h. Also changed...
[chromium-blink-merge.git] / base / scoped_temp_dir.cc
blob958dcbcb606204a48460605217b78fb7966dc796
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
3 // found in the LICENSE file.
5 #include "base/scoped_temp_dir.h"
7 #include "base/file_util.h"
8 #include "base/logging.h"
10 ScopedTempDir::ScopedTempDir() {
13 ScopedTempDir::~ScopedTempDir() {
14 if (!path_.empty() && !file_util::Delete(path_, true))
15 LOG(ERROR) << "ScopedTempDir unable to delete " << path_.value();
18 bool ScopedTempDir::CreateUniqueTempDir() {
19 // This "scoped_dir" prefix is only used on Windows and serves as a template
20 // for the unique name.
21 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"),
22 &path_))
23 return false;
25 return true;
28 bool ScopedTempDir::CreateUniqueTempDirUnderPath(const FilePath& base_path) {
29 // If |path| does not exist, create it.
30 if (!file_util::CreateDirectory(base_path))
31 return false;
33 // Create a new, uniquely named directory under |base_path|.
34 if (!file_util::CreateTemporaryDirInDir(
35 base_path,
36 FILE_PATH_LITERAL("scoped_dir_"),
37 &path_)) {
38 return false;
40 return true;
43 bool ScopedTempDir::Set(const FilePath& path) {
44 DCHECK(path_.empty());
45 if (!file_util::DirectoryExists(path) &&
46 !file_util::CreateDirectory(path)) {
47 return false;
49 path_ = path;
50 return true;
53 FilePath ScopedTempDir::Take() {
54 FilePath ret = path_;
55 path_ = FilePath();
56 return ret;
59 bool ScopedTempDir::IsValid() const {
60 return !path_.empty() && file_util::DirectoryExists(path_);