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

Unified Diff: chromecast/base/scoped_temp_file.cc

Issue 1484713003: [Chromecast] Use ScopedTemp[File|Dir] in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Style Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromecast/base/scoped_temp_file.h ('k') | chromecast/base/serializers_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dba9aa86412238df62cc029052d056220c0013d3
--- /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());
+ std::string result;
+ ReadFileToString(path_, &result);
bcf 2015/12/08 18:56:55 How about a CHECK for this?
slan 2015/12/08 19:08:48 Done.
+ return result;
+}
+
+} // namespace chromecast
« no previous file with comments | « chromecast/base/scoped_temp_file.h ('k') | chromecast/base/serializers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698