Don't preload rarely seen large images
[chromium-blink-merge.git] / storage / browser / quota / quota_task.cc
bloba0bda596a3ac833fdf82018456b578d3930620bc
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/thread_task_runner_handle.h"
15 using base::TaskRunner;
17 namespace storage {
19 // QuotaTask ---------------------------------------------------------------
21 QuotaTask::~QuotaTask() {
24 void QuotaTask::Start() {
25 DCHECK(observer_);
26 observer()->RegisterTask(this);
27 Run();
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());
38 if (observer_) {
39 observer_->UnregisterTask(this);
40 Completed();
44 void QuotaTask::Abort() {
45 DCHECK(original_task_runner_->BelongsToCurrentThread());
46 observer_ = NULL;
47 Aborted();
50 void QuotaTask::DeleteSoon() {
51 DCHECK(original_task_runner_->BelongsToCurrentThread());
52 if (delete_scheduled_)
53 return;
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