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

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

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 months 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file.h" 5 #include "base/files/file.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 7 #include "base/metrics/histogram.h"
8 #if defined(OS_POSIX) 8 #include "base/timer/elapsed_timer.h"
9 #include "base/files/file_posix_hooks_internal.h"
10 #endif
11 9
12 namespace base { 10 namespace base {
13 11
14 File::Info::Info() 12 File::Info::Info()
15 : size(0), 13 : size(0),
16 is_directory(false), 14 is_directory(false),
17 is_symbolic_link(false) { 15 is_symbolic_link(false) {
18 } 16 }
19 17
20 File::Info::~Info() { 18 File::Info::~Info() {
(...skipping 14 matching lines...) Expand all
35 } 33 }
36 #endif 34 #endif
37 35
38 File::File(PlatformFile platform_file) 36 File::File(PlatformFile platform_file)
39 : file_(platform_file), 37 : file_(platform_file),
40 error_details_(FILE_OK), 38 error_details_(FILE_OK),
41 created_(false), 39 created_(false),
42 async_(false) { 40 async_(false) {
43 #if defined(OS_POSIX) 41 #if defined(OS_POSIX)
44 DCHECK_GE(platform_file, -1); 42 DCHECK_GE(platform_file, -1);
45 if (IsValid())
46 ProtectFileDescriptor(platform_file);
47 #endif 43 #endif
48 } 44 }
49 45
50 File::File(Error error_details) 46 File::File(Error error_details)
51 : error_details_(error_details), 47 : error_details_(error_details),
52 created_(false), 48 created_(false),
53 async_(false) { 49 async_(false) {
54 } 50 }
55 51
56 File::File(RValue other) 52 File::File(RValue other)
57 : file_(other.object->TakePlatformFile()), 53 : file_(other.object->TakePlatformFile()),
58 error_details_(other.object->error_details()), 54 error_details_(other.object->error_details()),
59 created_(other.object->created()), 55 created_(other.object->created()),
60 async_(other.object->async_) { 56 async_(other.object->async_) {
61 #if defined(OS_POSIX)
62 if (IsValid())
63 ProtectFileDescriptor(GetPlatformFile());
64 #endif
65 } 57 }
66 58
67 File::~File() { 59 File::~File() {
68 // Go through the AssertIOAllowed logic. 60 // Go through the AssertIOAllowed logic.
69 Close(); 61 Close();
70 } 62 }
71 63
72 File& File::operator=(RValue other) { 64 File& File::operator=(RValue other) {
73 if (this != other.object) { 65 if (this != other.object) {
74 Close(); 66 Close();
75 SetPlatformFile(other.object->TakePlatformFile()); 67 SetPlatformFile(other.object->TakePlatformFile());
76 error_details_ = other.object->error_details(); 68 error_details_ = other.object->error_details();
77 created_ = other.object->created(); 69 created_ = other.object->created();
78 async_ = other.object->async_; 70 async_ = other.object->async_;
79 } 71 }
80 return *this; 72 return *this;
81 } 73 }
82 74
83 #if !defined(OS_NACL) 75 #if !defined(OS_NACL)
84 void File::Initialize(const FilePath& name, uint32 flags) { 76 void File::Initialize(const FilePath& name, uint32 flags) {
85 if (name.ReferencesParent()) { 77 if (name.ReferencesParent()) {
86 error_details_ = FILE_ERROR_ACCESS_DENIED; 78 error_details_ = FILE_ERROR_ACCESS_DENIED;
87 return; 79 return;
88 } 80 }
89 InitializeUnsafe(name, flags); 81 DoInitialize(name, flags);
90 } 82 }
91 #endif 83 #endif
92 84
93 std::string File::ErrorToString(Error error) { 85 std::string File::ErrorToString(Error error) {
94 switch (error) { 86 switch (error) {
95 case FILE_OK: 87 case FILE_OK:
96 return "FILE_OK"; 88 return "FILE_OK";
97 case FILE_ERROR_FAILED: 89 case FILE_ERROR_FAILED:
98 return "FILE_ERROR_FAILED"; 90 return "FILE_ERROR_FAILED";
99 case FILE_ERROR_IN_USE: 91 case FILE_ERROR_IN_USE:
(...skipping 27 matching lines...) Expand all
127 case FILE_ERROR_IO: 119 case FILE_ERROR_IO:
128 return "FILE_ERROR_IO"; 120 return "FILE_ERROR_IO";
129 case FILE_ERROR_MAX: 121 case FILE_ERROR_MAX:
130 break; 122 break;
131 } 123 }
132 124
133 NOTREACHED(); 125 NOTREACHED();
134 return ""; 126 return "";
135 } 127 }
136 128
129 bool File::Flush() {
130 ElapsedTimer timer;
131 bool return_value = DoFlush();
132 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed());
133 return return_value;
134 }
135
137 } // namespace base 136 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file.h ('k') | base/files/file_path.h » ('j') | mojo/public/tools/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698