We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / storage / browser / quota / quota_task.cc
blobb8d4ed142a0b3371f84caab3cd30060eee7f47b8
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"
7 #include <algorithm>
8 #include <functional>
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;
18 namespace storage {
20 // QuotaTask ---------------------------------------------------------------
22 QuotaTask::~QuotaTask() {
25 void QuotaTask::Start() {
26 DCHECK(observer_);
27 observer()->RegisterTask(this);
28 Run();
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());
39 if (observer_) {
40 observer_->UnregisterTask(this);
41 Completed();
45 void QuotaTask::Abort() {
46 DCHECK(original_task_runner_->BelongsToCurrentThread());
47 observer_ = NULL;
48 Aborted();
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);
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