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

Side by Side Diff: base/scoped_temp_dir.cc

Issue 2838034: Move the SingletonSocket to a temporary directory (Closed)
Patch Set: Address mattm's comments Created 10 years, 4 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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() && !file_util::Delete(path_, true)) 14 Delete();
15 LOG(ERROR) << "ScopedTempDir unable to delete " << path_.value();
16 } 15 }
17 16
18 bool ScopedTempDir::CreateUniqueTempDir() { 17 bool ScopedTempDir::CreateUniqueTempDir() {
19 // This "scoped_dir" prefix is only used on Windows and serves as a template 18 // This "scoped_dir" prefix is only used on Windows and serves as a template
20 // for the unique name. 19 // for the unique name.
21 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), 20 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"),
22 &path_)) 21 &path_))
23 return false; 22 return false;
24 23
25 return true; 24 return true;
(...skipping 17 matching lines...) Expand all
43 bool ScopedTempDir::Set(const FilePath& path) { 42 bool ScopedTempDir::Set(const FilePath& path) {
44 DCHECK(path_.empty()); 43 DCHECK(path_.empty());
45 if (!file_util::DirectoryExists(path) && 44 if (!file_util::DirectoryExists(path) &&
46 !file_util::CreateDirectory(path)) { 45 !file_util::CreateDirectory(path)) {
47 return false; 46 return false;
48 } 47 }
49 path_ = path; 48 path_ = path;
50 return true; 49 return true;
51 } 50 }
52 51
52 void ScopedTempDir::Delete() {
53 if (!path_.empty() && !file_util::Delete(path_, true))
54 LOG(ERROR) << "ScopedTempDir unable to delete " << path_.value();
55 path_.clear();
56 }
57
53 FilePath ScopedTempDir::Take() { 58 FilePath ScopedTempDir::Take() {
54 FilePath ret = path_; 59 FilePath ret = path_;
55 path_ = FilePath(); 60 path_ = FilePath();
56 return ret; 61 return ret;
57 } 62 }
58 63
59 bool ScopedTempDir::IsValid() const { 64 bool ScopedTempDir::IsValid() const {
60 return !path_.empty() && file_util::DirectoryExists(path_); 65 return !path_.empty() && file_util::DirectoryExists(path_);
61 } 66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698