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

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

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

Powered by Google App Engine
This is Rietveld 408576698