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/message_loop/message_loop_proxy.h"
14 #include "base/single_thread_task_runner.h"
16 using base::TaskRunner
;
20 // QuotaTask ---------------------------------------------------------------
22 QuotaTask::~QuotaTask() {
25 void QuotaTask::Start() {
27 observer()->RegisterTask(this);
31 QuotaTask::QuotaTask(QuotaTaskObserver
* observer
)
32 : observer_(observer
),
33 original_task_runner_(base::MessageLoopProxy::current()),
34 delete_scheduled_(false) {
37 void QuotaTask::CallCompleted() {
38 DCHECK(original_task_runner_
->BelongsToCurrentThread());
40 observer_
->UnregisterTask(this);
45 void QuotaTask::Abort() {
46 DCHECK(original_task_runner_
->BelongsToCurrentThread());
51 void QuotaTask::DeleteSoon() {
52 DCHECK(original_task_runner_
->BelongsToCurrentThread());
53 if (delete_scheduled_
)
55 delete_scheduled_
= true;
56 base::MessageLoop::current()->DeleteSoon(FROM_HERE
, this);
59 // QuotaTaskObserver -------------------------------------------------------
61 QuotaTaskObserver::~QuotaTaskObserver() {
62 std::for_each(running_quota_tasks_
.begin(),
63 running_quota_tasks_
.end(),
64 std::mem_fun(&QuotaTask::Abort
));
67 QuotaTaskObserver::QuotaTaskObserver() {
70 void QuotaTaskObserver::RegisterTask(QuotaTask
* task
) {
71 running_quota_tasks_
.insert(task
);
74 void QuotaTaskObserver::UnregisterTask(QuotaTask
* task
) {
75 DCHECK(running_quota_tasks_
.find(task
) != running_quota_tasks_
.end());
76 running_quota_tasks_
.erase(task
);
79 } // namespace storage