Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / base / profiler / scoped_tracker.cc
blob26b17c015539b043d6b5c981b7a3c802587c7723
1 // Copyright 2014 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/profiler/scoped_tracker.h"
7 #include "base/bind.h"
9 namespace tracked_objects {
11 namespace {
13 ScopedProfile::Mode g_scoped_profile_mode = ScopedProfile::DISABLED;
15 // Executes |callback|, augmenting it with provided |location|.
16 void ExecuteAndTrackCallback(const Location& location,
17 const base::Closure& callback) {
18 ScopedProfile tracking_profile(location, ScopedProfile::ENABLED);
19 callback.Run();
22 } // namespace
24 // static
25 void ScopedTracker::Enable() {
26 g_scoped_profile_mode = ScopedProfile::ENABLED;
29 // static
30 base::Closure ScopedTracker::TrackCallback(const Location& location,
31 const base::Closure& callback) {
32 if (g_scoped_profile_mode != ScopedProfile::ENABLED)
33 return callback;
35 return base::Bind(ExecuteAndTrackCallback, location, callback);
38 ScopedTracker::ScopedTracker(const Location& location)
39 : scoped_profile_(location, g_scoped_profile_mode) {
42 } // namespace tracked_objects