| 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/files/scoped_temp_dir.h" | 5 #include "base/files/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 namespace base { | 10 namespace base { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 &path_)) | 45 &path_)) |
| 46 return false; | 46 return false; |
| 47 | 47 |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool ScopedTempDir::Set(const FilePath& path) { | 51 bool ScopedTempDir::Set(const FilePath& path) { |
| 52 if (!path_.empty()) | 52 if (!path_.empty()) |
| 53 return false; | 53 return false; |
| 54 | 54 |
| 55 if (!file_util::DirectoryExists(path) && | 55 if (!DirectoryExists(path) && !file_util::CreateDirectory(path)) |
| 56 !file_util::CreateDirectory(path)) | |
| 57 return false; | 56 return false; |
| 58 | 57 |
| 59 path_ = path; | 58 path_ = path; |
| 60 return true; | 59 return true; |
| 61 } | 60 } |
| 62 | 61 |
| 63 bool ScopedTempDir::Delete() { | 62 bool ScopedTempDir::Delete() { |
| 64 if (path_.empty()) | 63 if (path_.empty()) |
| 65 return false; | 64 return false; |
| 66 | 65 |
| 67 bool ret = base::Delete(path_, true); | 66 bool ret = base::Delete(path_, true); |
| 68 if (ret) { | 67 if (ret) { |
| 69 // We only clear the path if deleted the directory. | 68 // We only clear the path if deleted the directory. |
| 70 path_.clear(); | 69 path_.clear(); |
| 71 } | 70 } |
| 72 | 71 |
| 73 return ret; | 72 return ret; |
| 74 } | 73 } |
| 75 | 74 |
| 76 FilePath ScopedTempDir::Take() { | 75 FilePath ScopedTempDir::Take() { |
| 77 FilePath ret = path_; | 76 FilePath ret = path_; |
| 78 path_ = FilePath(); | 77 path_ = FilePath(); |
| 79 return ret; | 78 return ret; |
| 80 } | 79 } |
| 81 | 80 |
| 82 bool ScopedTempDir::IsValid() const { | 81 bool ScopedTempDir::IsValid() const { |
| 83 return !path_.empty() && file_util::DirectoryExists(path_); | 82 return !path_.empty() && DirectoryExists(path_); |
| 84 } | 83 } |
| 85 | 84 |
| 86 } // namespace base | 85 } // namespace base |
| OLD | NEW |