OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 #include "chromecast/base/scoped_temp_file.h" | |
6 #include "base/files/file_util.h" | |
7 #include "base/logging.h" | |
8 | |
9 namespace chromecast { | |
10 | |
11 ScopedTempFile::ScopedTempFile() { | |
12 CHECK(base::CreateTemporaryFile(&path_)); | |
13 } | |
14 | |
15 ScopedTempFile::~ScopedTempFile() { | |
16 if (FileExists()) { | |
17 // Since this is a file, set the -rf flag to false. | |
18 CHECK(base::DeleteFile(path_, false)); | |
19 } | |
20 } | |
21 | |
22 bool ScopedTempFile::FileExists() const { | |
23 return base::PathExists(path_); | |
24 } | |
25 | |
26 int ScopedTempFile::Write(const std::string& str) { | |
27 CHECK(FileExists()); | |
28 return base::WriteFile(path_, str.c_str(), str.size()); | |
29 } | |
30 | |
31 std::string ScopedTempFile::Read() const { | |
32 CHECK(FileExists()); | |
M-A Ruel
2015/12/08 19:12:19
You don't need this line anymore IIUC.
slan
2015/12/08 19:18:24
That's a good point, but I think I will keep this
| |
33 std::string result; | |
34 CHECK(ReadFileToString(path_, &result)); | |
35 return result; | |
36 } | |
37 | |
38 } // namespace chromecast | |
OLD | NEW |