Allow supervised users to create bookmark apps.
[chromium-blink-merge.git] / base / files / file_tracing.h
blob8452037790c2b21762c1d87cf419ef8a08f47313
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_FILES_FILE_TRACING_H_
6 #define BASE_FILES_FILE_TRACING_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/macros.h"
12 #define FILE_TRACING_PREFIX "File"
14 #define SCOPED_FILE_TRACE_WITH_SIZE(name, size) \
15 FileTracing::ScopedTrace scoped_file_trace; \
16 if (scoped_file_trace.ShouldInitialize()) \
17 scoped_file_trace.Initialize(FILE_TRACING_PREFIX "::" name, this, size)
19 #define SCOPED_FILE_TRACE(name) SCOPED_FILE_TRACE_WITH_SIZE(name, 0)
21 namespace base {
23 class File;
24 class FilePath;
26 class BASE_EXPORT FileTracing {
27 public:
28 class Provider {
29 public:
30 // Whether the file tracing category is currently enabled.
31 virtual bool FileTracingCategoryIsEnabled() const = 0;
33 // Enables file tracing for |id|. Must be called before recording events.
34 virtual void FileTracingEnable(void* id) = 0;
36 // Disables file tracing for |id|.
37 virtual void FileTracingDisable(void* id) = 0;
39 // Begins an event for |id| with |name|. |path| tells where in the directory
40 // structure the event is happening (and may be blank). |size| is reported
41 // if not 0.
42 virtual void FileTracingEventBegin(
43 const char* name, void* id, const FilePath& path, int64 size) = 0;
45 // Ends an event for |id| with |name|. |path| tells where in the directory
46 // structure the event is happening (and may be blank). |size| is reported
47 // if not 0.
48 virtual void FileTracingEventEnd(
49 const char* name, void* id, const FilePath& path, int64 size) = 0;
52 // Sets a global file tracing provider to query categories and record events.
53 static void SetProvider(Provider* provider);
55 // Enables file tracing while in scope.
56 class ScopedEnabler {
57 public:
58 ScopedEnabler();
59 ~ScopedEnabler();
62 class ScopedTrace {
63 public:
64 ScopedTrace();
65 ~ScopedTrace();
67 // Whether this trace should be initialized or not.
68 bool ShouldInitialize() const;
70 // Called only if the tracing category is enabled.
71 void Initialize(const char* event, File* file, int64 size);
73 private:
74 // True if |Initialize()| has been called. Don't touch |path_|, |event_|,
75 // or |bytes_| if |initialized_| is false.
76 bool initialized_;
78 // The event name to trace (e.g. "Read", "Write"). Prefixed with "File".
79 const char* name_;
81 // The file being traced. Must outlive this class.
82 File* file_;
84 // The size (in bytes) of this trace. Not reported if 0.
85 int64 size_;
87 DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
90 DISALLOW_COPY_AND_ASSIGN(FileTracing);
93 } // namespace base
95 #endif // BASE_FILES_FILE_TRACING_H_