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

Side by Side Diff: webrtc/base/file.cc

Issue 2533213005: Add File::Open / Create functions to take an rtc::Pathname (Closed)
Patch Set: Resolve review comments Created 4 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 | « webrtc/base/file.h ('k') | webrtc/base/file_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
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/file.h" 11 #include "webrtc/base/file.h"
12 12
13 #include <utility>
14
13 namespace rtc { 15 namespace rtc {
14 16
17 namespace {
18
19 std::string NormalizePathname(Pathname&& path) {
20 path.Normalize();
21 return path.pathname();
22 }
23
24 } // namespace
25
15 File::File(PlatformFile file) : file_(file) {} 26 File::File(PlatformFile file) : file_(file) {}
16 27
17 File::File() : file_(kInvalidPlatformFileValue) {} 28 File::File() : file_(kInvalidPlatformFileValue) {}
18 29
19 File::~File() { 30 File::~File() {
20 Close(); 31 Close();
21 } 32 }
22 33
34 // static
23 File File::Open(const std::string& path) { 35 File File::Open(const std::string& path) {
24 return File(OpenPlatformFile(path)); 36 return File(OpenPlatformFile(path));
25 } 37 }
26 38
39 // static
40 File File::Open(Pathname&& path) {
41 return Open(NormalizePathname(std::move(path)));
42 }
43
44 // static
45 File File::Open(const Pathname& path) {
46 return Open(Pathname(path));
47 }
48
49 // static
27 File File::Create(const std::string& path) { 50 File File::Create(const std::string& path) {
28 return File(CreatePlatformFile(path)); 51 return File(CreatePlatformFile(path));
29 } 52 }
30 53
54 // static
55 File File::Create(Pathname&& path) {
56 return Create(NormalizePathname(std::move(path)));
57 }
58
59 // static
60 File File::Create(const Pathname& path) {
61 return Create(Pathname(path));
62 }
63
31 File::File(File&& other) : file_(other.file_) { 64 File::File(File&& other) : file_(other.file_) {
32 other.file_ = kInvalidPlatformFileValue; 65 other.file_ = kInvalidPlatformFileValue;
33 } 66 }
34 67
35 File& File::operator=(File&& other) { 68 File& File::operator=(File&& other) {
36 Close(); 69 Close();
37 file_ = other.file_; 70 file_ = other.file_;
38 other.file_ = kInvalidPlatformFileValue; 71 other.file_ = kInvalidPlatformFileValue;
39 return *this; 72 return *this;
40 } 73 }
41 74
42 bool File::IsOpen() { 75 bool File::IsOpen() {
43 return file_ != kInvalidPlatformFileValue; 76 return file_ != kInvalidPlatformFileValue;
44 } 77 }
45 78
46 } // namespace rtc 79 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/file.h ('k') | webrtc/base/file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698