From 4f1935ea36204273208e790adff22aecf20c7c2b Mon Sep 17 00:00:00 2001 From: "kaiwang@chromium.org" Date: Fri, 16 Nov 2012 23:10:07 +0000 Subject: Add function to CancelableTaskTracker and convert BootTimeLoader (take 2) This is the second try of: https://chromiumcodereview.appspot.com/11410073 Previous code has a potential race condition: ---------------------------------------------------------------- In old code when IsCanceledCallback is deleted. CancellationFlag is deleted In task thread, and Untrack is called on client thread. There's potential racy between: 1. CancellationFlag deletion. (task thread) 2. Untrack is called. (client thread) 3. TryCancel is called for the specific task. (client thread) When the order is 1, 3, 2. There will be a CancellationFlag use after delettion bug. ---------------------------------------------------------------- BUG=155883 TBR=brettw Review URL: https://codereview.chromium.org/11414041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168321 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chromeos/boot_times_loader.h | 32 +++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'chrome/browser/chromeos/boot_times_loader.h') diff --git a/chrome/browser/chromeos/boot_times_loader.h b/chrome/browser/chromeos/boot_times_loader.h index 691a44ff..dc420e8 100644 --- a/chrome/browser/chromeos/boot_times_loader.h +++ b/chrome/browser/chromeos/boot_times_loader.h @@ -12,7 +12,7 @@ #include "base/callback_forward.h" #include "base/compiler_specific.h" #include "base/time.h" -#include "chrome/browser/common/cancelable_request.h" +#include "chrome/common/cancelable_task_tracker.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/render_widget_host.h" @@ -22,17 +22,14 @@ namespace chromeos { // BootTimesLoader loads the bootimes of Chrome OS from the file system. // Loading is done asynchronously on the file thread. Once loaded, // BootTimesLoader calls back to a method of your choice with the boot times. -// To use BootTimesLoader do the following: +// To use BootTimesLoader, do the following: // // . In your class define a member field of type chromeos::BootTimesLoader and -// CancelableRequestConsumerBase. +// CancelableTaskTracker. // . Define the callback method, something like: -// void OnBootTimesLoader(chromeos::BootTimesLoader::Handle, -// BootTimesLoader::BootTimes boot_times); -// . When you want the version invoke: loader.GetBootTimes(&consumer, callback); -class BootTimesLoader - : public CancelableRequestProvider, - public content::NotificationObserver { +// void OnBootTimesLoaded(const BootTimesLoader::BootTimes& boot_times); +// . When you want the version invoke: loader.GetBootTimes(callback, &tracker_); +class BootTimesLoader : public content::NotificationObserver { public: BootTimesLoader(); virtual ~BootTimesLoader(); @@ -60,17 +57,14 @@ class BootTimesLoader total(0) {} } BootTimes; - // Signature - typedef base::Callback GetBootTimesCallback; - - typedef CancelableRequest GetBootTimesRequest; - static BootTimesLoader* Get(); + typedef base::Callback GetBootTimesCallback; + // Asynchronously requests the info. - Handle GetBootTimes( - CancelableRequestConsumerBase* consumer, - const GetBootTimesCallback& callback); + CancelableTaskTracker::TaskId GetBootTimes( + const GetBootTimesCallback& callback, + CancelableTaskTracker* tracker); // Add a time marker for login. A timeline will be dumped to // /tmp/login-times-sent after login is done. If |send_to_uma| is true @@ -119,7 +113,9 @@ class BootTimesLoader public: Backend() {} - void GetBootTimes(const scoped_refptr& request); + void GetBootTimesAndRunCallback( + const CancelableTaskTracker::IsCanceledCallback& is_canceled_cb, + const GetBootTimesCallback& callback); private: friend class base::RefCountedThreadSafe; -- cgit v1.1