Index: chromecast/base/scoped_temp_file.cc |
diff --git a/chromecast/base/scoped_temp_file.cc b/chromecast/base/scoped_temp_file.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..44309e4d61991a8ae618789154d3561fdfebad9f |
--- /dev/null |
+++ b/chromecast/base/scoped_temp_file.cc |
@@ -0,0 +1,38 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromecast/base/scoped_temp_file.h" |
+#include "base/files/file_util.h" |
+#include "base/logging.h" |
+ |
+namespace chromecast { |
+ |
+ScopedTempFile::ScopedTempFile() { |
+ CHECK(base::CreateTemporaryFile(&path_)); |
+} |
+ |
+ScopedTempFile::~ScopedTempFile() { |
+ if (FileExists()) { |
+ // Since this is a file, set the -rf flag to false. |
+ CHECK(base::DeleteFile(path_, false)); |
+ } |
+} |
+ |
+bool ScopedTempFile::FileExists() const { |
+ return base::PathExists(path_); |
+} |
+ |
+int ScopedTempFile::Write(const std::string& str) { |
+ CHECK(FileExists()); |
+ return base::WriteFile(path_, str.c_str(), str.size()); |
+} |
+ |
+std::string ScopedTempFile::Read() const { |
+ 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
|
+ std::string result; |
+ CHECK(ReadFileToString(path_, &result)); |
+ return result; |
+} |
+ |
+} // namespace chromecast |