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

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: win fixes 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/files/file_tracing.h"
7 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
8 #include "base/timer/elapsed_timer.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 FILE_TRACING_BEGIN();
oystein (OOO til 10th of July) 2015/05/01 18:21:05 It could be cleaner to do these BEGIN/END calls in
Dan Beam 2015/05/01 23:29:04 Done.
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 FILE_TRACING_BEGIN();
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 FILE_TRACING_BEGIN();
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 FILE_TRACING_BEGIN();
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 FILE_TRACING_BEGIN();
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 FILE_TRACING_END();
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;
oystein (OOO til 10th of July) 2015/05/01 18:15:31 What's the reason for setting this here, instead o
Dan Beam 2015/05/01 23:29:04 Done. (originally my rationale was: it'd be weird
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 SCOPED_FILE_TRACE("Initialize");
89 DoInitialize(flags);
82 } 90 }
83 #endif 91 #endif
84 92
85 std::string File::ErrorToString(Error error) { 93 std::string File::ErrorToString(Error error) {
86 switch (error) { 94 switch (error) {
87 case FILE_OK: 95 case FILE_OK:
88 return "FILE_OK"; 96 return "FILE_OK";
89 case FILE_ERROR_FAILED: 97 case FILE_ERROR_FAILED:
90 return "FILE_ERROR_FAILED"; 98 return "FILE_ERROR_FAILED";
91 case FILE_ERROR_IN_USE: 99 case FILE_ERROR_IN_USE:
(...skipping 27 matching lines...) Expand all
119 case FILE_ERROR_IO: 127 case FILE_ERROR_IO:
120 return "FILE_ERROR_IO"; 128 return "FILE_ERROR_IO";
121 case FILE_ERROR_MAX: 129 case FILE_ERROR_MAX:
122 break; 130 break;
123 } 131 }
124 132
125 NOTREACHED(); 133 NOTREACHED();
126 return ""; 134 return "";
127 } 135 }
128 136
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
136 } // namespace base 137 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file.h ('k') | base/files/file_posix.cc » ('j') | base/files/file_tracing.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698