mesa gn build: suppress -Wstring-conversion warnings
[chromium-blink-merge.git] / storage / browser / fileapi / timed_task_helper.h
blob4663501b4ff0f497657cf9d359830ccb68ae829d
1 // Copyright 2013 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 #ifndef STORAGE_BROWSER_FILEAPI_TIMED_TASK_HELPER_H_
6 #define STORAGE_BROWSER_FILEAPI_TIMED_TASK_HELPER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/location.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "storage/browser/storage_browser_export.h"
16 namespace base {
17 class SequencedTaskRunner;
20 namespace storage {
22 // Works similarly as base::Timer, but takes SequencedTaskRunner and
23 // runs tasks on it (instead of implicitly bound to a thread).
24 // TODO(kinuko): This has nothing to do with fileapi. Move somewhere
25 // more common place.
26 class STORAGE_EXPORT TimedTaskHelper {
27 public:
28 explicit TimedTaskHelper(base::SequencedTaskRunner* task_runner);
29 ~TimedTaskHelper();
31 bool IsRunning() const;
32 void Start(const tracked_objects::Location& posted_from,
33 base::TimeDelta delay,
34 const base::Closure& user_task);
35 void Reset();
37 private:
38 struct Tracker;
39 static void Fired(scoped_ptr<Tracker> tracker);
41 void OnFired(scoped_ptr<Tracker> tracker);
42 void PostDelayedTask(scoped_ptr<Tracker> tracker, base::TimeDelta delay);
44 scoped_refptr<base::SequencedTaskRunner> task_runner_;
45 tracked_objects::Location posted_from_;
46 base::TimeDelta delay_;
47 base::Closure user_task_;
49 base::TimeTicks desired_run_time_;
51 // This is set to non-null and owned by a timer task while timer is running.
52 Tracker* tracker_;
54 DISALLOW_COPY_AND_ASSIGN(TimedTaskHelper);
57 } // namespace storage
59 #endif // STORAGE_BROWSER_FILEAPI_TIMED_TASK_HELPER_H_