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

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

Issue 1127713004: Revert of Add granular base::File tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do-initialize
Patch Set: 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
« no previous file with comments | « base/files/file.h ('k') | base/files/file_posix.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 // 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 #include "base/files/file_tracing.h"
8 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
9 #include "base/timer/elapsed_timer.h" 8 #include "base/timer/elapsed_timer.h"
10 9
11 namespace base { 10 namespace base {
12 11
13 File::Info::Info() 12 File::Info::Info()
14 : size(0), 13 : size(0),
15 is_directory(false), 14 is_directory(false),
16 is_symbolic_link(false) { 15 is_symbolic_link(false) {
17 } 16 }
18 17
19 File::Info::~Info() { 18 File::Info::~Info() {
20 } 19 }
21 20
22 File::File() 21 File::File()
23 : error_details_(FILE_ERROR_FAILED), 22 : error_details_(FILE_ERROR_FAILED),
24 created_(false), 23 created_(false),
25 async_(false) { 24 async_(false) {
26 } 25 }
27 26
28 #if !defined(OS_NACL) 27 #if !defined(OS_NACL)
29 File::File(const FilePath& path, uint32 flags) 28 File::File(const FilePath& name, uint32 flags)
30 : error_details_(FILE_OK), 29 : error_details_(FILE_OK),
31 created_(false), 30 created_(false),
32 async_(false) { 31 async_(false) {
33 Initialize(path, flags); 32 Initialize(name, flags);
34 } 33 }
35 #endif 34 #endif
36 35
37 File::File(PlatformFile platform_file) 36 File::File(PlatformFile platform_file)
38 : file_(platform_file), 37 : file_(platform_file),
39 error_details_(FILE_OK), 38 error_details_(FILE_OK),
40 created_(false), 39 created_(false),
41 async_(false) { 40 async_(false) {
42 #if defined(OS_POSIX) 41 #if defined(OS_POSIX)
43 DCHECK_GE(platform_file, -1); 42 DCHECK_GE(platform_file, -1);
44 #endif 43 #endif
45 } 44 }
46 45
47 File::File(Error error_details) 46 File::File(Error error_details)
48 : error_details_(error_details), 47 : error_details_(error_details),
49 created_(false), 48 created_(false),
50 async_(false) { 49 async_(false) {
51 } 50 }
52 51
53 File::File(RValue other) 52 File::File(RValue other)
54 : file_(other.object->TakePlatformFile()), 53 : file_(other.object->TakePlatformFile()),
55 path_(other.object->path_),
56 error_details_(other.object->error_details()), 54 error_details_(other.object->error_details()),
57 created_(other.object->created()), 55 created_(other.object->created()),
58 async_(other.object->async_) { 56 async_(other.object->async_) {
59 } 57 }
60 58
61 File::~File() { 59 File::~File() {
62 // Go through the AssertIOAllowed logic. 60 // Go through the AssertIOAllowed logic.
63 Close(); 61 Close();
64 } 62 }
65 63
66 File& File::operator=(RValue other) { 64 File& File::operator=(RValue other) {
67 if (this != other.object) { 65 if (this != other.object) {
68 Close(); 66 Close();
69 SetPlatformFile(other.object->TakePlatformFile()); 67 SetPlatformFile(other.object->TakePlatformFile());
70 path_ = other.object->path_;
71 error_details_ = other.object->error_details(); 68 error_details_ = other.object->error_details();
72 created_ = other.object->created(); 69 created_ = other.object->created();
73 async_ = other.object->async_; 70 async_ = other.object->async_;
74 } 71 }
75 return *this; 72 return *this;
76 } 73 }
77 74
78 #if !defined(OS_NACL) 75 #if !defined(OS_NACL)
79 void File::Initialize(const FilePath& path, uint32 flags) { 76 void File::Initialize(const FilePath& name, uint32 flags) {
80 if (path.ReferencesParent()) { 77 if (name.ReferencesParent()) {
81 error_details_ = FILE_ERROR_ACCESS_DENIED; 78 error_details_ = FILE_ERROR_ACCESS_DENIED;
82 return; 79 return;
83 } 80 }
84 path_ = path; 81 DoInitialize(name, flags);
85 SCOPED_FILE_TRACE("Initialize");
86 DoInitialize(flags);
87 } 82 }
88 #endif 83 #endif
89 84
90 std::string File::ErrorToString(Error error) { 85 std::string File::ErrorToString(Error error) {
91 switch (error) { 86 switch (error) {
92 case FILE_OK: 87 case FILE_OK:
93 return "FILE_OK"; 88 return "FILE_OK";
94 case FILE_ERROR_FAILED: 89 case FILE_ERROR_FAILED:
95 return "FILE_ERROR_FAILED"; 90 return "FILE_ERROR_FAILED";
96 case FILE_ERROR_IN_USE: 91 case FILE_ERROR_IN_USE:
(...skipping 29 matching lines...) Expand all
126 case FILE_ERROR_MAX: 121 case FILE_ERROR_MAX:
127 break; 122 break;
128 } 123 }
129 124
130 NOTREACHED(); 125 NOTREACHED();
131 return ""; 126 return "";
132 } 127 }
133 128
134 bool File::Flush() { 129 bool File::Flush() {
135 ElapsedTimer timer; 130 ElapsedTimer timer;
136 SCOPED_FILE_TRACE("Flush");
137 bool return_value = DoFlush(); 131 bool return_value = DoFlush();
138 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); 132 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed());
139 return return_value; 133 return return_value;
140 } 134 }
141 135
142 File::TraceEnabler::TraceEnabler() {
143 FILE_TRACING_BEGIN();
144 }
145
146 File::TraceEnabler::~TraceEnabler() {
147 FILE_TRACING_END();
148 }
149
150 } // namespace base 136 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file.h ('k') | base/files/file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698