Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Side by Side Diff: webkit/quota/quota_task.h

Issue 10197007: Change webkit/{fileapi,quota} code to use TaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/quota/quota_manager.cc ('k') | webkit/quota/quota_task.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_QUOTA_QUOTA_TASK_H_ 5 #ifndef WEBKIT_QUOTA_QUOTA_TASK_H_
6 #define WEBKIT_QUOTA_QUOTA_TASK_H_ 6 #define WEBKIT_QUOTA_QUOTA_TASK_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop_proxy.h"
15 14
16 namespace base { 15 namespace base {
17 class MessageLoopProxy; 16 class SingleThreadTaskRunner;
17 class TaskRunner;
18 } 18 }
19 19
20 namespace quota { 20 namespace quota {
21 21
22 class QuotaTaskObserver; 22 class QuotaTaskObserver;
23 class QuotaThreadTask;
23 24
24 // A base class for quota tasks. 25 // A base class for quota tasks.
26 // TODO(kinuko): Revise this using base::Callback.
25 class QuotaTask { 27 class QuotaTask {
26 public: 28 public:
27 virtual ~QuotaTask(); 29 virtual ~QuotaTask();
28 void Start(); 30 void Start();
29 31
30 protected: 32 protected:
31 explicit QuotaTask(QuotaTaskObserver* observer); 33 explicit QuotaTask(QuotaTaskObserver* observer);
32 34
33 // The task body. 35 // The task body.
34 virtual void Run() = 0; 36 virtual void Run() = 0;
35 37
36 // Called upon completion, on the original message loop. 38 // Called upon completion, on the original message loop.
37 virtual void Completed() = 0; 39 virtual void Completed() = 0;
38 40
39 // Called when the task is aborted. 41 // Called when the task is aborted.
40 virtual void Aborted() {} 42 virtual void Aborted() {}
41 43
42 void CallCompleted(); 44 void CallCompleted();
43 45
44 // Call this to delete itself. 46 // Call this to delete itself.
45 void DeleteSoon(); 47 void DeleteSoon();
46 48
47 QuotaTaskObserver* observer() const { return observer_; } 49 QuotaTaskObserver* observer() const { return observer_; }
48 scoped_refptr<base::MessageLoopProxy> original_message_loop() const { 50 base::SingleThreadTaskRunner* original_task_runner() const {
49 return original_message_loop_; 51 return original_task_runner_;
50 } 52 }
51 53
52 private: 54 private:
53 friend class QuotaTaskObserver; 55 friend class QuotaTaskObserver;
56 friend class QuotaThreadTask;
54 void Abort(); 57 void Abort();
55 QuotaTaskObserver* observer_; 58 QuotaTaskObserver* observer_;
56 scoped_refptr<base::MessageLoopProxy> original_message_loop_; 59 scoped_refptr<base::SingleThreadTaskRunner> original_task_runner_;
57 }; 60 };
58 61
59 // For tasks that post tasks to the other thread. 62 // For tasks that post tasks to the other thread.
60 class QuotaThreadTask : public QuotaTask, 63 class QuotaThreadTask : public QuotaTask,
61 public base::RefCountedThreadSafe<QuotaThreadTask> { 64 public base::RefCountedThreadSafe<QuotaThreadTask> {
62 public: 65 public:
63 QuotaThreadTask(QuotaTaskObserver* observer, 66 QuotaThreadTask(QuotaTaskObserver* observer,
64 scoped_refptr<base::MessageLoopProxy> target_message_loop); 67 base::TaskRunner* target_task_runner);
65 68
66 protected: 69 protected:
67 virtual ~QuotaThreadTask(); 70 virtual ~QuotaThreadTask();
68 71
69 // One of the following Run methods should be overridden for execution 72 // One of the following Run methods should be overridden for execution
70 // on the target thread. 73 // on the target thread.
71 74
72 // A task to invoke the CallCompleted() method on the original thread will 75 // A task to invoke the CallCompleted() method on the original thread will
73 // be scheduled immediately upon return from RunOnTargetThread(). 76 // be scheduled immediately upon return from RunOnTargetThread().
74 virtual void RunOnTargetThread(); 77 virtual void RunOnTargetThread();
75 78
76 // A task to invoke the CallCompleted() method on the original thread will 79 // A task to invoke the CallCompleted() method on the original thread will
77 // only be scheduled if RunOnTargetThreadAsync returns true. If false is 80 // only be scheduled if RunOnTargetThreadAsync returns true. If false is
78 // returned, the derived class should schedule a task to do so upon actual 81 // returned, the derived class should schedule a task to do so upon actual
79 // completion. 82 // completion.
80 virtual bool RunOnTargetThreadAsync(); 83 virtual bool RunOnTargetThreadAsync();
81 84
82 virtual void Run() OVERRIDE; 85 virtual void Run() OVERRIDE;
83 scoped_refptr<base::MessageLoopProxy> target_message_loop() const { 86 base::TaskRunner* target_task_runner() const {
84 return target_message_loop_; 87 return target_task_runner_;
85 } 88 }
86 89
87 private: 90 private:
88 friend class base::RefCountedThreadSafe<QuotaThreadTask>; 91 friend class base::RefCountedThreadSafe<QuotaThreadTask>;
89 friend class QuotaTaskObserver; 92 friend class QuotaTaskObserver;
90 void CallRunOnTargetThread(); 93 void CallRunOnTargetThread();
91 94
92 scoped_refptr<base::MessageLoopProxy> target_message_loop_; 95 scoped_refptr<base::TaskRunner> target_task_runner_;
93 }; 96 };
94 97
95 class QuotaTaskObserver { 98 class QuotaTaskObserver {
96 public: 99 public:
97 virtual ~QuotaTaskObserver(); 100 virtual ~QuotaTaskObserver();
98 101
99 protected: 102 protected:
100 friend class QuotaTask; 103 friend class QuotaTask;
101 friend class QuotaThreadTask; 104 friend class QuotaThreadTask;
102 105
103 QuotaTaskObserver(); 106 QuotaTaskObserver();
104 void RegisterTask(QuotaTask* task); 107 void RegisterTask(QuotaTask* task);
105 void UnregisterTask(QuotaTask* task); 108 void UnregisterTask(QuotaTask* task);
106 109
107 typedef std::set<QuotaTask*> TaskSet; 110 typedef std::set<QuotaTask*> TaskSet;
108 TaskSet running_quota_tasks_; 111 TaskSet running_quota_tasks_;
109 }; 112 };
110 } 113 }
111 114
112 #endif // WEBKIT_QUOTA_QUOTA_TASK_H_ 115 #endif // WEBKIT_QUOTA_QUOTA_TASK_H_
OLDNEW
« no previous file with comments | « webkit/quota/quota_manager.cc ('k') | webkit/quota/quota_task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698