Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: base/files/scoped_temp_dir.cc

Issue 99923002: Move temp file functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/files/important_file_writer.cc ('k') | base/files/scoped_temp_dir_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
11 11
12 ScopedTempDir::ScopedTempDir() { 12 ScopedTempDir::ScopedTempDir() {
13 } 13 }
14 14
15 ScopedTempDir::~ScopedTempDir() { 15 ScopedTempDir::~ScopedTempDir() {
16 if (!path_.empty() && !Delete()) 16 if (!path_.empty() && !Delete())
17 DLOG(WARNING) << "Could not delete temp dir in dtor."; 17 DLOG(WARNING) << "Could not delete temp dir in dtor.";
18 } 18 }
19 19
20 bool ScopedTempDir::CreateUniqueTempDir() { 20 bool ScopedTempDir::CreateUniqueTempDir() {
21 if (!path_.empty()) 21 if (!path_.empty())
22 return false; 22 return false;
23 23
24 // This "scoped_dir" prefix is only used on Windows and serves as a template 24 // This "scoped_dir" prefix is only used on Windows and serves as a template
25 // for the unique name. 25 // for the unique name.
26 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), 26 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), &path_))
27 &path_))
28 return false; 27 return false;
29 28
30 return true; 29 return true;
31 } 30 }
32 31
33 bool ScopedTempDir::CreateUniqueTempDirUnderPath(const FilePath& base_path) { 32 bool ScopedTempDir::CreateUniqueTempDirUnderPath(const FilePath& base_path) {
34 if (!path_.empty()) 33 if (!path_.empty())
35 return false; 34 return false;
36 35
37 // If |base_path| does not exist, create it. 36 // If |base_path| does not exist, create it.
38 if (!file_util::CreateDirectory(base_path)) 37 if (!file_util::CreateDirectory(base_path))
39 return false; 38 return false;
40 39
41 // Create a new, uniquely named directory under |base_path|. 40 // Create a new, uniquely named directory under |base_path|.
42 if (!file_util::CreateTemporaryDirInDir( 41 if (!base::CreateTemporaryDirInDir(base_path,
43 base_path, 42 FILE_PATH_LITERAL("scoped_dir_"),
44 FILE_PATH_LITERAL("scoped_dir_"), 43 &path_))
45 &path_))
46 return false; 44 return false;
47 45
48 return true; 46 return true;
49 } 47 }
50 48
51 bool ScopedTempDir::Set(const FilePath& path) { 49 bool ScopedTempDir::Set(const FilePath& path) {
52 if (!path_.empty()) 50 if (!path_.empty())
53 return false; 51 return false;
54 52
55 if (!DirectoryExists(path) && !file_util::CreateDirectory(path)) 53 if (!DirectoryExists(path) && !file_util::CreateDirectory(path))
(...skipping 20 matching lines...) Expand all
76 FilePath ret = path_; 74 FilePath ret = path_;
77 path_ = FilePath(); 75 path_ = FilePath();
78 return ret; 76 return ret;
79 } 77 }
80 78
81 bool ScopedTempDir::IsValid() const { 79 bool ScopedTempDir::IsValid() const {
82 return !path_.empty() && DirectoryExists(path_); 80 return !path_.empty() && DirectoryExists(path_);
83 } 81 }
84 82
85 } // namespace base 83 } // namespace base
OLDNEW
« no previous file with comments | « base/files/important_file_writer.cc ('k') | base/files/scoped_temp_dir_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698