OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "webkit/browser/quota/quota_task.h" | |
6 | |
7 #include <algorithm> | |
8 #include <functional> | |
9 | |
10 #include "base/bind.h" | |
11 #include "base/location.h" | |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/message_loop/message_loop_proxy.h" | |
14 #include "base/single_thread_task_runner.h" | |
15 | |
16 using base::TaskRunner; | |
17 | |
18 namespace storage { | |
19 | |
20 // QuotaTask --------------------------------------------------------------- | |
21 | |
22 QuotaTask::~QuotaTask() { | |
23 } | |
24 | |
25 void QuotaTask::Start() { | |
26 DCHECK(observer_); | |
27 observer()->RegisterTask(this); | |
28 Run(); | |
29 } | |
30 | |
31 QuotaTask::QuotaTask(QuotaTaskObserver* observer) | |
32 : observer_(observer), | |
33 original_task_runner_(base::MessageLoopProxy::current()), | |
34 delete_scheduled_(false) { | |
35 } | |
36 | |
37 void QuotaTask::CallCompleted() { | |
38 DCHECK(original_task_runner_->BelongsToCurrentThread()); | |
39 if (observer_) { | |
40 observer_->UnregisterTask(this); | |
41 Completed(); | |
42 } | |
43 } | |
44 | |
45 void QuotaTask::Abort() { | |
46 DCHECK(original_task_runner_->BelongsToCurrentThread()); | |
47 observer_ = NULL; | |
48 Aborted(); | |
49 } | |
50 | |
51 void QuotaTask::DeleteSoon() { | |
52 DCHECK(original_task_runner_->BelongsToCurrentThread()); | |
53 if (delete_scheduled_) | |
54 return; | |
55 delete_scheduled_ = true; | |
56 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
57 } | |
58 | |
59 // QuotaTaskObserver ------------------------------------------------------- | |
60 | |
61 QuotaTaskObserver::~QuotaTaskObserver() { | |
62 std::for_each(running_quota_tasks_.begin(), | |
63 running_quota_tasks_.end(), | |
64 std::mem_fun(&QuotaTask::Abort)); | |
65 } | |
66 | |
67 QuotaTaskObserver::QuotaTaskObserver() { | |
68 } | |
69 | |
70 void QuotaTaskObserver::RegisterTask(QuotaTask* task) { | |
71 running_quota_tasks_.insert(task); | |
72 } | |
73 | |
74 void QuotaTaskObserver::UnregisterTask(QuotaTask* task) { | |
75 DCHECK(running_quota_tasks_.find(task) != running_quota_tasks_.end()); | |
76 running_quota_tasks_.erase(task); | |
77 } | |
78 | |
79 } // namespace storage | |
OLD | NEW |