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

Side by Side 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: Fix bug in test fixture, add CHECK to ScopedTempFile::Read Created 5 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
« no previous file with comments | « chromecast/base/scoped_temp_file.h ('k') | chromecast/base/serializers_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
(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
OLDNEW
« 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