summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/boot_times_loader.h
diff options
context:
space:
mode:
authorkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-16 23:10:07 +0000
committerkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-16 23:10:07 +0000
commit4f1935ea36204273208e790adff22aecf20c7c2b (patch)
tree02d0ecbbcd2aef14a066251449c934b7453ede6f /chrome/browser/chromeos/boot_times_loader.h
parent9b2569b07c401bae46d6250d3435308e89f0c60f (diff)
downloadchromium_src-4f1935ea36204273208e790adff22aecf20c7c2b.zip
chromium_src-4f1935ea36204273208e790adff22aecf20c7c2b.tar.gz
chromium_src-4f1935ea36204273208e790adff22aecf20c7c2b.tar.bz2
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
Diffstat (limited to 'chrome/browser/chromeos/boot_times_loader.h')
-rw-r--r--chrome/browser/chromeos/boot_times_loader.h32
1 files changed, 14 insertions, 18 deletions
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<void(Handle, BootTimes)> GetBootTimesCallback;
-
- typedef CancelableRequest<GetBootTimesCallback> GetBootTimesRequest;
-
static BootTimesLoader* Get();
+ typedef base::Callback<void(const BootTimes&)> 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<GetBootTimesRequest>& request);
+ void GetBootTimesAndRunCallback(
+ const CancelableTaskTracker::IsCanceledCallback& is_canceled_cb,
+ const GetBootTimesCallback& callback);
private:
friend class base::RefCountedThreadSafe<Backend>;