diff options
-rw-r--r-- | base/profiler/scoped_tracker.cc | 16 | ||||
-rw-r--r-- | base/profiler/scoped_tracker.h | 19 | ||||
-rw-r--r-- | net/disk_cache/blockfile/in_flight_backend_io.cc | 98 |
3 files changed, 99 insertions, 34 deletions
diff --git a/base/profiler/scoped_tracker.cc b/base/profiler/scoped_tracker.cc index 26b17c0..d15b7de 100644 --- a/base/profiler/scoped_tracker.cc +++ b/base/profiler/scoped_tracker.cc @@ -12,13 +12,6 @@ namespace { ScopedProfile::Mode g_scoped_profile_mode = ScopedProfile::DISABLED; -// Executes |callback|, augmenting it with provided |location|. -void ExecuteAndTrackCallback(const Location& location, - const base::Closure& callback) { - ScopedProfile tracking_profile(location, ScopedProfile::ENABLED); - callback.Run(); -} - } // namespace // static @@ -26,15 +19,6 @@ 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(ExecuteAndTrackCallback, location, callback); -} - ScopedTracker::ScopedTracker(const Location& location) : scoped_profile_(location, g_scoped_profile_mode) { } diff --git a/base/profiler/scoped_tracker.h b/base/profiler/scoped_tracker.h index f83654e..23e2f07 100644 --- a/base/profiler/scoped_tracker.h +++ b/base/profiler/scoped_tracker.h @@ -10,6 +10,7 @@ // found using profiler data. #include "base/base_export.h" +#include "base/bind.h" #include "base/callback_forward.h" #include "base/location.h" #include "base/profiler/scoped_profile.h" @@ -47,10 +48,24 @@ class BASE_EXPORT ScopedTracker { // many possible callbacks, but they come from a relatively small number of // places. We can instrument these few places and at least know which one // passes the janky callback. - static base::Closure TrackCallback(const Location& location, - const base::Closure& callback); + template <typename P1> + static base::Callback<void(P1)> TrackCallback( + const Location& location, + const base::Callback<void(P1)>& callback) { + return base::Bind(&ScopedTracker::ExecuteAndTrackCallback<P1>, location, + callback); + } private: + // Executes |callback|, augmenting it with provided |location|. + template <typename P1> + static void ExecuteAndTrackCallback(const Location& location, + const base::Callback<void(P1)>& callback, + P1 p1) { + ScopedTracker tracking_profile(location); + callback.Run(p1); + } + const ScopedProfile scoped_profile_; DISALLOW_COPY_AND_ASSIGN(ScopedTracker); diff --git a/net/disk_cache/blockfile/in_flight_backend_io.cc b/net/disk_cache/blockfile/in_flight_backend_io.cc index 2cb3ff0..5b3b904 100644 --- a/net/disk_cache/blockfile/in_flight_backend_io.cc +++ b/net/disk_cache/blockfile/in_flight_backend_io.cc @@ -341,35 +341,57 @@ InFlightBackendIO::~InFlightBackendIO() { } void InFlightBackendIO::Init(const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + // TODO(vadimt): Remove wrapping the callback with + // ScopedTracker::TrackCallback() once crbug.com/422516 is fixed. + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, + tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 InFlightBackendIO::Init"), + callback))); operation->Init(); PostOperation(operation.get()); } void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::OpenEntry"), + callback))); operation->OpenEntry(key, entry); PostOperation(operation.get()); } void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::CreateEntry"), + callback))); operation->CreateEntry(key, entry); PostOperation(operation.get()); } void InFlightBackendIO::DoomEntry(const std::string& key, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::DoomEntry"), + callback))); operation->DoomEntry(key); PostOperation(operation.get()); } void InFlightBackendIO::DoomAllEntries( const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::DoomAllEntries"), + callback))); operation->DoomAllEntries(); PostOperation(operation.get()); } @@ -377,14 +399,22 @@ void InFlightBackendIO::DoomAllEntries( void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, const base::Time end_time, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::DoomEntriesBetween"), + callback))); operation->DoomEntriesBetween(initial_time, end_time); PostOperation(operation.get()); } void InFlightBackendIO::DoomEntriesSince( const base::Time initial_time, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::DoomEntriesSince"), + callback))); operation->DoomEntriesSince(initial_time); PostOperation(operation.get()); } @@ -392,7 +422,11 @@ void InFlightBackendIO::DoomEntriesSince( void InFlightBackendIO::OpenNextEntry(Rankings::Iterator* iterator, Entry** next_entry, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::OpenNextEntry"), + callback))); operation->OpenNextEntry(iterator, next_entry); PostOperation(operation.get()); } @@ -427,14 +461,22 @@ void InFlightBackendIO::DoomEntryImpl(EntryImpl* entry) { } void InFlightBackendIO::FlushQueue(const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::FlushQueue"), + callback))); operation->FlushQueue(); PostOperation(operation.get()); } void InFlightBackendIO::RunTask( const base::Closure& task, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, + tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 InFlightBackendIO::RunTask"), + callback))); operation->RunTask(task); PostOperation(operation.get()); } @@ -442,7 +484,11 @@ void InFlightBackendIO::RunTask( void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, int buf_len, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::ReadData"), + callback))); operation->ReadData(entry, index, offset, buf, buf_len); PostOperation(operation.get()); } @@ -451,7 +497,11 @@ void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, int buf_len, bool truncate, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::WriteData"), + callback))); operation->WriteData(entry, index, offset, buf, buf_len, truncate); PostOperation(operation.get()); } @@ -459,7 +509,11 @@ void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, void InFlightBackendIO::ReadSparseData( EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::ReadSparseData"), + callback))); operation->ReadSparseData(entry, offset, buf, buf_len); PostOperation(operation.get()); } @@ -467,7 +521,11 @@ void InFlightBackendIO::ReadSparseData( void InFlightBackendIO::WriteSparseData( EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::WriteSparseData"), + callback))); operation->WriteSparseData(entry, offset, buf, buf_len); PostOperation(operation.get()); } @@ -475,7 +533,11 @@ void InFlightBackendIO::WriteSparseData( void InFlightBackendIO::GetAvailableRange( EntryImpl* entry, int64 offset, int len, int64* start, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::GetAvailableRange"), + callback))); operation->GetAvailableRange(entry, offset, len, start); PostOperation(operation.get()); } @@ -489,7 +551,11 @@ void InFlightBackendIO::CancelSparseIO(EntryImpl* entry) { void InFlightBackendIO::ReadyForSparseIO( EntryImpl* entry, const net::CompletionCallback& callback) { - scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + scoped_refptr<BackendIO> operation(new BackendIO( + this, backend_, tracked_objects::ScopedTracker::TrackCallback( + FROM_HERE_WITH_EXPLICIT_FUNCTION( + "422516 InFlightBackendIO::CancelSparseIO"), + callback))); operation->ReadyForSparseIO(entry); PostOperation(operation.get()); } |