OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/scoped_temp_dir.h" | 5 #include "base/scoped_temp_dir.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 ScopedTempDir::ScopedTempDir() { | 10 ScopedTempDir::ScopedTempDir() { |
11 } | 11 } |
12 | 12 |
13 ScopedTempDir::~ScopedTempDir() { | 13 ScopedTempDir::~ScopedTempDir() { |
14 if (!path_.empty() && !Delete()) | 14 if (!path_.empty() && !Delete()) |
15 LOG(WARNING) << "Could not delete temp dir in dtor."; | 15 DLOG(WARNING) << "Could not delete temp dir in dtor."; |
16 } | 16 } |
17 | 17 |
18 bool ScopedTempDir::CreateUniqueTempDir() { | 18 bool ScopedTempDir::CreateUniqueTempDir() { |
19 if (!path_.empty()) | 19 if (!path_.empty()) |
20 return false; | 20 return false; |
21 | 21 |
22 // This "scoped_dir" prefix is only used on Windows and serves as a template | 22 // This "scoped_dir" prefix is only used on Windows and serves as a template |
23 // for the unique name. | 23 // for the unique name. |
24 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), | 24 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), |
25 &path_)) | 25 &path_)) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 bool ScopedTempDir::Delete() { | 61 bool ScopedTempDir::Delete() { |
62 if (path_.empty()) | 62 if (path_.empty()) |
63 return false; | 63 return false; |
64 | 64 |
65 bool ret = file_util::Delete(path_, true); | 65 bool ret = file_util::Delete(path_, true); |
66 if (ret) { | 66 if (ret) { |
67 // We only clear the path if deleted the directory. | 67 // We only clear the path if deleted the directory. |
68 path_.clear(); | 68 path_.clear(); |
69 } else { | 69 } else { |
70 LOG(ERROR) << "ScopedTempDir unable to delete " << path_.value(); | 70 DLOG(ERROR) << "ScopedTempDir unable to delete " << path_.value(); |
71 } | 71 } |
72 | 72 |
73 return ret; | 73 return ret; |
74 } | 74 } |
75 | 75 |
76 FilePath ScopedTempDir::Take() { | 76 FilePath ScopedTempDir::Take() { |
77 FilePath ret = path_; | 77 FilePath ret = path_; |
78 path_ = FilePath(); | 78 path_ = FilePath(); |
79 return ret; | 79 return ret; |
80 } | 80 } |
81 | 81 |
82 bool ScopedTempDir::IsValid() const { | 82 bool ScopedTempDir::IsValid() const { |
83 return !path_.empty() && file_util::DirectoryExists(path_); | 83 return !path_.empty() && file_util::DirectoryExists(path_); |
84 } | 84 } |
OLD | NEW |