Write new Starts/EndsWith and convert FilePath functions to StringPiece.
[chromium-blink-merge.git] / base / files / file_tracing.cc
blobc25772db8ab5a101f47885ce58016eb576687dd7
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 #include "base/files/file_tracing.h"
7 #include "base/files/file.h"
9 namespace base {
11 namespace {
12 FileTracing::Provider* g_provider = nullptr;
15 // static
16 void FileTracing::SetProvider(FileTracing::Provider* provider) {
17 g_provider = provider;
20 FileTracing::ScopedEnabler::ScopedEnabler() {
21 if (g_provider)
22 g_provider->FileTracingEnable(this);
25 FileTracing::ScopedEnabler::~ScopedEnabler() {
26 if (g_provider)
27 g_provider->FileTracingDisable(this);
30 FileTracing::ScopedTrace::ScopedTrace() : id_(nullptr) {}
32 FileTracing::ScopedTrace::~ScopedTrace() {
33 if (id_ && g_provider)
34 g_provider->FileTracingEventEnd(name_, id_);
37 bool FileTracing::ScopedTrace::ShouldInitialize() const {
38 return g_provider && g_provider->FileTracingCategoryIsEnabled();
41 void FileTracing::ScopedTrace::Initialize(
42 const char* name, File* file, int64 size) {
43 if (!g_provider)
44 return;
46 id_ = &file->trace_enabler_;
47 name_ = name;
49 g_provider->FileTracingEventBegin(name_, id_, file->path_, size);
52 } // namespace base