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

Unified Diff: base/profiler/scoped_tracker.cc

Issue 683283004: Enabling augmenting callback with Location (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/profiler/scoped_tracker.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/profiler/scoped_tracker.cc
diff --git a/base/profiler/scoped_tracker.cc b/base/profiler/scoped_tracker.cc
index 5cd0bcae34984d1d99017ccb699d7dbe48409439..7f378185f74ce68b45f4918368314030ee4735c3 100644
--- a/base/profiler/scoped_tracker.cc
+++ b/base/profiler/scoped_tracker.cc
@@ -4,12 +4,21 @@
#include "base/profiler/scoped_tracker.h"
+#include "base/bind.h"
+
namespace tracked_objects {
namespace {
ScopedProfile::Mode g_scoped_profile_mode = ScopedProfile::DISABLED;
+// Executes |callback|, augmenting it with provided |location|.
+void ExecuteAndAugmentCallback(const Location& location,
Ilya Sherman 2014/10/29 00:23:00 nit: I find the "augment" part of this name confus
vadimt 2014/10/29 00:52:21 Done.
+ const base::Closure& callback) {
+ ScopedProfile tracking_profile(location);
Ilya Sherman 2014/10/29 00:23:00 Hmm, why not use a ScopedTracker here instead?
vadimt 2014/10/29 00:52:21 ScopedTracker checks if tracking is enabled and ca
Ilya Sherman 2014/10/29 00:57:12 My point is: Why does TrackCallback check g_scoped
vadimt 2014/10/29 17:47:29 This allows me to totally skip creating/destroying
Ilya Sherman 2014/10/30 00:51:35 I think this is unnecessary optimization that redu
+ callback.Run();
+}
+
} // namespace
// static
@@ -17,6 +26,15 @@ void ScopedTracker::Enable() {
g_scoped_profile_mode = ScopedProfile::ENABLED;
}
+// static
+base::Closure ScopedTracker::TrackCallback(const Location& location,
+ const base::Closure& callback) {
+ if (g_scoped_profile_mode != ScopedProfile::ENABLED)
+ return callback;
+
+ return base::Bind(ExecuteAndAugmentCallback, location, callback);
+}
+
ScopedTracker::ScopedTracker(const Location& location)
: scoped_profile_(location, g_scoped_profile_mode) {
}
« no previous file with comments | « base/profiler/scoped_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698