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 #include "storage/browser/quota/quota_task.h"
10 #include "base/bind.h"
11 #include "base/location.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/thread_task_runner_handle.h"
15 using base::TaskRunner
;
19 // QuotaTask ---------------------------------------------------------------
21 QuotaTask::~QuotaTask() {
24 void QuotaTask::Start() {
26 observer()->RegisterTask(this);
30 QuotaTask::QuotaTask(QuotaTaskObserver
* observer
)
31 : observer_(observer
),
32 original_task_runner_(base::ThreadTaskRunnerHandle::Get()),
33 delete_scheduled_(false) {
36 void QuotaTask::CallCompleted() {
37 DCHECK(original_task_runner_
->BelongsToCurrentThread());
39 observer_
->UnregisterTask(this);
44 void QuotaTask::Abort() {
45 DCHECK(original_task_runner_
->BelongsToCurrentThread());
50 void QuotaTask::DeleteSoon() {
51 DCHECK(original_task_runner_
->BelongsToCurrentThread());
52 if (delete_scheduled_
)
54 delete_scheduled_
= true;
55 base::MessageLoop::current()->DeleteSoon(FROM_HERE
, this);
58 // QuotaTaskObserver -------------------------------------------------------
60 QuotaTaskObserver::~QuotaTaskObserver() {
61 std::for_each(running_quota_tasks_
.begin(),
62 running_quota_tasks_
.end(),
63 std::mem_fun(&QuotaTask::Abort
));
66 QuotaTaskObserver::QuotaTaskObserver() {
69 void QuotaTaskObserver::RegisterTask(QuotaTask
* task
) {
70 running_quota_tasks_
.insert(task
);
73 void QuotaTaskObserver::UnregisterTask(QuotaTask
* task
) {
74 DCHECK(running_quota_tasks_
.find(task
) != running_quota_tasks_
.end());
75 running_quota_tasks_
.erase(task
);
78 } // namespace storage