OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_BROWSER_QUOTA_QUOTA_TASK_H_ | 5 #include "storage/browser/quota/quota_task.h" |
6 #define WEBKIT_BROWSER_QUOTA_QUOTA_TASK_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/sequenced_task_runner_helpers.h" | |
14 #include "webkit/browser/storage_browser_export.h" | |
15 | |
16 namespace base { | |
17 class SingleThreadTaskRunner; | |
18 class TaskRunner; | |
19 } | |
20 | |
21 namespace storage { | |
22 | |
23 class QuotaTaskObserver; | |
24 | |
25 // A base class for quota tasks. | |
26 // TODO(kinuko): Revise this using base::Callback. | |
27 class QuotaTask { | |
28 public: | |
29 void Start(); | |
30 | |
31 protected: | |
32 explicit QuotaTask(QuotaTaskObserver* observer); | |
33 virtual ~QuotaTask(); | |
34 | |
35 // The task body. | |
36 virtual void Run() = 0; | |
37 | |
38 // Called upon completion, on the original message loop. | |
39 virtual void Completed() = 0; | |
40 | |
41 // Called when the task is aborted. | |
42 virtual void Aborted() {} | |
43 | |
44 void CallCompleted(); | |
45 | |
46 // Call this to delete itself. | |
47 void DeleteSoon(); | |
48 | |
49 QuotaTaskObserver* observer() const { return observer_; } | |
50 base::SingleThreadTaskRunner* original_task_runner() const { | |
51 return original_task_runner_.get(); | |
52 } | |
53 | |
54 private: | |
55 friend class base::DeleteHelper<QuotaTask>; | |
56 friend class QuotaTaskObserver; | |
57 | |
58 void Abort(); | |
59 QuotaTaskObserver* observer_; | |
60 scoped_refptr<base::SingleThreadTaskRunner> original_task_runner_; | |
61 bool delete_scheduled_; | |
62 }; | |
63 | |
64 class STORAGE_EXPORT QuotaTaskObserver { | |
65 protected: | |
66 friend class QuotaTask; | |
67 | |
68 QuotaTaskObserver(); | |
69 virtual ~QuotaTaskObserver(); | |
70 | |
71 void RegisterTask(QuotaTask* task); | |
72 void UnregisterTask(QuotaTask* task); | |
73 | |
74 typedef std::set<QuotaTask*> TaskSet; | |
75 TaskSet running_quota_tasks_; | |
76 }; | |
77 } | |
78 | |
79 #endif // WEBKIT_BROWSER_QUOTA_QUOTA_TASK_H_ | |
OLD | NEW |