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

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: comment 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"
7 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
8 #include "base/timer/elapsed_timer.h" 9 #include "base/timer/elapsed_timer.h"
9 10
10 namespace base { 11 namespace base {
11 12
12 File::Info::Info() 13 File::Info::Info()
13 : size(0), 14 : size(0),
14 is_directory(false), 15 is_directory(false),
15 is_symbolic_link(false) { 16 is_symbolic_link(false) {
16 } 17 }
17 18
18 File::Info::~Info() { 19 File::Info::~Info() {
19 } 20 }
20 21
21 File::File() 22 File::File()
22 : error_details_(FILE_ERROR_FAILED), 23 : error_details_(FILE_ERROR_FAILED),
23 created_(false), 24 created_(false),
24 async_(false) { 25 async_(false) {
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),
30 created_(false), 31 created_(false),
31 async_(false) { 32 async_(false) {
32 Initialize(name, flags); 33 Initialize(path, flags);
33 } 34 }
34 #endif 35 #endif
35 36
36 File::File(PlatformFile platform_file) 37 File::File(PlatformFile platform_file)
37 : file_(platform_file), 38 : file_(platform_file),
38 error_details_(FILE_OK), 39 error_details_(FILE_OK),
39 created_(false), 40 created_(false),
40 async_(false) { 41 async_(false) {
41 #if defined(OS_POSIX) 42 #if defined(OS_POSIX)
42 DCHECK_GE(platform_file, -1); 43 DCHECK_GE(platform_file, -1);
43 #endif 44 #endif
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) {
50 } 51 }
51 52
52 File::File(RValue other) 53 File::File(RValue other)
53 : file_(other.object->TakePlatformFile()), 54 : file_(other.object->TakePlatformFile()),
55 path_(other.object->path_),
54 error_details_(other.object->error_details()), 56 error_details_(other.object->error_details()),
55 created_(other.object->created()), 57 created_(other.object->created()),
56 async_(other.object->async_) { 58 async_(other.object->async_) {
57 } 59 }
58 60
59 File::~File() { 61 File::~File() {
60 // Go through the AssertIOAllowed logic. 62 // Go through the AssertIOAllowed logic.
61 Close(); 63 Close();
62 } 64 }
63 65
64 File& File::operator=(RValue other) { 66 File& File::operator=(RValue other) {
65 if (this != other.object) { 67 if (this != other.object) {
66 Close(); 68 Close();
67 SetPlatformFile(other.object->TakePlatformFile()); 69 SetPlatformFile(other.object->TakePlatformFile());
70 path_ = other.object->path_;
68 error_details_ = other.object->error_details(); 71 error_details_ = other.object->error_details();
69 created_ = other.object->created(); 72 created_ = other.object->created();
70 async_ = other.object->async_; 73 async_ = other.object->async_;
71 } 74 }
72 return *this; 75 return *this;
73 } 76 }
74 77
75 #if !defined(OS_NACL) 78 #if !defined(OS_NACL)
76 void File::Initialize(const FilePath& name, uint32 flags) { 79 void File::Initialize(const FilePath& path, uint32 flags) {
77 if (name.ReferencesParent()) { 80 if (path.ReferencesParent()) {
78 error_details_ = FILE_ERROR_ACCESS_DENIED; 81 error_details_ = FILE_ERROR_ACCESS_DENIED;
79 return; 82 return;
80 } 83 }
81 DoInitialize(name, flags); 84 path_ = path;
85 SCOPED_FILE_TRACE("Initialize");
86 DoInitialize(flags);
82 } 87 }
83 #endif 88 #endif
84 89
85 std::string File::ErrorToString(Error error) { 90 std::string File::ErrorToString(Error error) {
86 switch (error) { 91 switch (error) {
87 case FILE_OK: 92 case FILE_OK:
88 return "FILE_OK"; 93 return "FILE_OK";
89 case FILE_ERROR_FAILED: 94 case FILE_ERROR_FAILED:
90 return "FILE_ERROR_FAILED"; 95 return "FILE_ERROR_FAILED";
91 case FILE_ERROR_IN_USE: 96 case FILE_ERROR_IN_USE:
(...skipping 29 matching lines...) Expand all
121 case FILE_ERROR_MAX: 126 case FILE_ERROR_MAX:
122 break; 127 break;
123 } 128 }
124 129
125 NOTREACHED(); 130 NOTREACHED();
126 return ""; 131 return "";
127 } 132 }
128 133
129 bool File::Flush() { 134 bool File::Flush() {
130 ElapsedTimer timer; 135 ElapsedTimer timer;
136 SCOPED_FILE_TRACE("Flush");
131 bool return_value = DoFlush(); 137 bool return_value = DoFlush();
132 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); 138 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed());
133 return return_value; 139 return return_value;
134 } 140 }
135 141
136 } // namespace base 142 } // 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