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

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

Issue 1072133006: Add granular file tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do-initialize
Patch Set: take 2 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 | « no previous file | base/files/file.cc » ('j') | base/files/file_posix.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_FILES_FILE_H_ 5 #ifndef BASE_FILES_FILE_H_
6 #define BASE_FILES_FILE_H_ 6 #define BASE_FILES_FILE_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
11 #endif 11 #endif
12 12
13 #if defined(OS_POSIX) 13 #if defined(OS_POSIX)
14 #include <sys/stat.h> 14 #include <sys/stat.h>
15 #endif 15 #endif
16 16
17 #include <string> 17 #include <string>
18 18
19 #include "base/base_export.h" 19 #include "base/base_export.h"
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/files/file_path.h"
21 #include "base/files/scoped_file.h" 22 #include "base/files/scoped_file.h"
22 #include "base/gtest_prod_util.h" 23 #include "base/gtest_prod_util.h"
23 #include "base/move.h" 24 #include "base/move.h"
24 #include "base/time/time.h" 25 #include "base/time/time.h"
25 26
26 #if defined(OS_WIN) 27 #if defined(OS_WIN)
27 #include "base/win/scoped_handle.h" 28 #include "base/win/scoped_handle.h"
28 #endif 29 #endif
29 30
30 FORWARD_DECLARE_TEST(FileTest, MemoryCorruption); 31 FORWARD_DECLARE_TEST(FileTest, MemoryCorruption);
31 32
32 namespace base { 33 namespace base {
33 34
34 class FilePath;
35
36 #if defined(OS_WIN) 35 #if defined(OS_WIN)
37 typedef HANDLE PlatformFile; 36 typedef HANDLE PlatformFile;
38 #elif defined(OS_POSIX) 37 #elif defined(OS_POSIX)
39 typedef int PlatformFile; 38 typedef int PlatformFile;
40 39
41 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) 40 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL)
42 typedef struct stat stat_wrapper_t; 41 typedef struct stat stat_wrapper_t;
43 #else 42 #else
44 typedef struct stat64 stat_wrapper_t; 43 typedef struct stat64 stat_wrapper_t;
45 #endif 44 #endif
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // The last accessed time of a file. 154 // The last accessed time of a file.
156 Time last_accessed; 155 Time last_accessed;
157 156
158 // The creation time of a file. 157 // The creation time of a file.
159 Time creation_time; 158 Time creation_time;
160 }; 159 };
161 160
162 File(); 161 File();
163 162
164 // Creates or opens the given file. This will fail with 'access denied' if the 163 // Creates or opens the given file. This will fail with 'access denied' if the
165 // |name| contains path traversal ('..') components. 164 // |path| contains path traversal ('..') components.
166 File(const FilePath& name, uint32 flags); 165 File(const FilePath& path, uint32 flags);
167 166
168 // Takes ownership of |platform_file|. 167 // Takes ownership of |platform_file|.
169 explicit File(PlatformFile platform_file); 168 explicit File(PlatformFile platform_file);
170 169
171 // Creates an object with a specific error_details code. 170 // Creates an object with a specific error_details code.
172 explicit File(Error error_details); 171 explicit File(Error error_details);
173 172
174 // Move constructor for C++03 move emulation of this type. 173 // Move constructor for C++03 move emulation of this type.
175 File(RValue other); 174 File(RValue other);
176 175
177 ~File(); 176 ~File();
178 177
179 // Move operator= for C++03 move emulation of this type. 178 // Move operator= for C++03 move emulation of this type.
180 File& operator=(RValue other); 179 File& operator=(RValue other);
181 180
182 // Creates or opens the given file. 181 // Creates or opens the given file.
183 void Initialize(const FilePath& name, uint32 flags); 182 void Initialize(const FilePath& path, uint32 flags);
184 183
185 bool IsValid() const; 184 bool IsValid() const;
186 185
187 // Returns true if a new file was created (or an old one truncated to zero 186 // Returns true if a new file was created (or an old one truncated to zero
188 // length to simulate a new file, which can happen with 187 // length to simulate a new file, which can happen with
189 // FLAG_CREATE_ALWAYS), and false otherwise. 188 // FLAG_CREATE_ALWAYS), and false otherwise.
190 bool created() const { return created_; } 189 bool created() const { return created_; }
191 190
192 // Returns the OS result of opening this file. Note that the way to verify 191 // Returns the OS result of opening this file. Note that the way to verify
193 // the success of the operation is to use IsValid(), not this method: 192 // the success of the operation is to use IsValid(), not this method:
194 // File file(name, flags); 193 // File file(path, flags);
195 // if (!file.IsValid()) 194 // if (!file.IsValid())
196 // return; 195 // return;
197 Error error_details() const { return error_details_; } 196 Error error_details() const { return error_details_; }
198 197
199 PlatformFile GetPlatformFile() const; 198 PlatformFile GetPlatformFile() const;
200 PlatformFile TakePlatformFile(); 199 PlatformFile TakePlatformFile();
201 200
202 // Destroying this object closes the file automatically. 201 // Destroying this object closes the file automatically.
203 void Close(); 202 void Close();
204 203
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 #elif defined(OS_POSIX) 297 #elif defined(OS_POSIX)
299 static Error OSErrorToFileError(int saved_errno); 298 static Error OSErrorToFileError(int saved_errno);
300 #endif 299 #endif
301 300
302 // Converts an error value to a human-readable form. Used for logging. 301 // Converts an error value to a human-readable form. Used for logging.
303 static std::string ErrorToString(Error error); 302 static std::string ErrorToString(Error error);
304 303
305 private: 304 private:
306 FRIEND_TEST_ALL_PREFIXES(::FileTest, MemoryCorruption); 305 FRIEND_TEST_ALL_PREFIXES(::FileTest, MemoryCorruption);
307 306
307 // The tracing group file traces will show up as.
308 static const char kTraceGroup[];
Sami 2015/04/28 11:10:39 nit: Usually we just write the trace category expl
Dan Beam 2015/04/28 15:47:58 I guess I can do this, it's just... TRACE_DISABLED
Sami 2015/04/28 15:51:05 I don't think it's a hard rule, so I'll leave it u
groby-ooo-7-16 2015/04/28 20:26:54 I don't have a specific preference, but consider n
Dan Beam 2015/04/29 02:48:03 $ git grep \\bkTraceGroup\\b yields only these re
309
308 #if defined(OS_POSIX) 310 #if defined(OS_POSIX)
309 // Encloses a single ScopedFD, saving a cheap tamper resistent memory checksum 311 // Encloses a single ScopedFD, saving a cheap tamper resistent memory checksum
310 // alongside it. This checksum is validated at every access, allowing early 312 // alongside it. This checksum is validated at every access, allowing early
311 // detection of memory corruption. 313 // detection of memory corruption.
312 314
313 // TODO(gavinp): This is in place temporarily to help us debug 315 // TODO(gavinp): This is in place temporarily to help us debug
314 // https://crbug.com/424562 , which can't be reproduced in valgrind. Remove 316 // https://crbug.com/424562 , which can't be reproduced in valgrind. Remove
315 // this code after we have fixed this issue. 317 // this code after we have fixed this issue.
316 class MemoryCheckingScopedFD { 318 class MemoryCheckingScopedFD {
317 public: 319 public:
(...skipping 25 matching lines...) Expand all
343 // failing a CHECK if they do not. 345 // failing a CHECK if they do not.
344 void Check() const; 346 void Check() const;
345 347
346 void UpdateChecksum(); 348 void UpdateChecksum();
347 349
348 ScopedFD file_; 350 ScopedFD file_;
349 unsigned int file_memory_checksum_; 351 unsigned int file_memory_checksum_;
350 }; 352 };
351 #endif 353 #endif
352 354
353 // Creates or opens the given file. Only called if |name| has no traversal 355 // Creates or opens the given file. Only called if |path_| has no traversal
354 // ('..') components. 356 // ('..') components.
355 void DoInitialize(const FilePath& name, uint32 flags); 357 void DoInitialize(uint32 flags);
356 358
357 // TODO(tnagel): Reintegrate into Flush() once histogram isn't needed anymore, 359 // TODO(tnagel): Reintegrate into Flush() once histogram isn't needed anymore,
358 // cf. issue 473337. 360 // cf. issue 473337.
359 bool DoFlush(); 361 bool DoFlush();
360 362
361 void SetPlatformFile(PlatformFile file); 363 void SetPlatformFile(PlatformFile file);
362 364
363 #if defined(OS_WIN) 365 #if defined(OS_WIN)
364 win::ScopedHandle file_; 366 win::ScopedHandle file_;
365 #elif defined(OS_POSIX) 367 #elif defined(OS_POSIX)
366 MemoryCheckingScopedFD file_; 368 MemoryCheckingScopedFD file_;
367 #endif 369 #endif
368 370
groby-ooo-7-16 2015/04/28 20:26:54 |unsafe_path_|, then?
Dan Beam 2015/04/29 02:48:02 Done.
371 // Path that |Initialize()| was called with. Can be unsafe (e.g. have '..').
372 FilePath path_;
373
369 Error error_details_; 374 Error error_details_;
370 bool created_; 375 bool created_;
371 bool async_; 376 bool async_;
372 }; 377 };
373 378
374 } // namespace base 379 } // namespace base
375 380
376 #endif // BASE_FILES_FILE_H_ 381 #endif // BASE_FILES_FILE_H_
OLDNEW
« no previous file with comments | « no previous file | base/files/file.cc » ('j') | base/files/file_posix.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698