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

Side by Side Diff: chromecast/base/scoped_temp_file.h

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 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
(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 #ifndef CHROMECAST_BASE_SCOPED_TEMP_FILE_H_
6 #define CHROMECAST_BASE_SCOPED_TEMP_FILE_H_
7
8 #include <string>
9
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12
13 namespace chromecast {
14
15 // Creates a temporary file that is deleted when this object is destroyed,
16 // unless the underlying file has been moved or deleted.
17 // Warning: This class uses CHECKs, and should only be used for testing.
18 class ScopedTempFile {
19 public:
20 ScopedTempFile();
21 ~ScopedTempFile();
22
23 // Return the path to the temporary file. Note that if the underlying file has
24 // been moved or deleted, this will still return the original path.
25 base::FilePath path() const { return path_; }
26
27 // Returns true if the underlying file exists, false otherwise. This will
28 // return false, for example, if the file has been moved or deleted.
29 bool FileExists() const;
30
31 // Write the contents of |str| to the file. Return the number of characters
32 // written, or -1 on error. CHECKs that FileExists() returns true.
33 int Write(const std::string& str);
34
35 // Read the file and return the contents. CHECKs that FileExists() returns
36 // true.
37 std::string Read() const;
38
39 private:
40 base::FilePath path_;
41
42 DISALLOW_COPY_AND_ASSIGN(ScopedTempFile);
43 };
44
45 } // namespace chromecast
46
47 #endif // CHROMECAST_BASE_SCOPED_TEMP_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698