| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/quota/quota_task.h" | 5 #include "webkit/quota/quota_task.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 QuotaThreadTask::~QuotaThreadTask() { | 60 QuotaThreadTask::~QuotaThreadTask() { |
| 61 } | 61 } |
| 62 | 62 |
| 63 void QuotaThreadTask::Run() { | 63 void QuotaThreadTask::Run() { |
| 64 target_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 64 target_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 65 this, &QuotaThreadTask::CallRunOnTargetThread)); | 65 this, &QuotaThreadTask::CallRunOnTargetThread)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void QuotaThreadTask::CallRunOnTargetThread() { | 68 void QuotaThreadTask::CallRunOnTargetThread() { |
| 69 DCHECK(target_message_loop_->BelongsToCurrentThread()); | 69 DCHECK(target_message_loop_->BelongsToCurrentThread()); |
| 70 if (RunOnTargetThreadAsync()) |
| 71 original_message_loop()->PostTask( |
| 72 FROM_HERE, NewRunnableMethod(this, &QuotaThreadTask::CallCompleted)); |
| 73 } |
| 74 |
| 75 bool QuotaThreadTask::RunOnTargetThreadAsync() { |
| 70 RunOnTargetThread(); | 76 RunOnTargetThread(); |
| 71 original_message_loop()->PostTask( | 77 return true; |
| 72 FROM_HERE, NewRunnableMethod(this, &QuotaThreadTask::CallCompleted)); | 78 } |
| 79 |
| 80 void QuotaThreadTask::RunOnTargetThread() { |
| 73 } | 81 } |
| 74 | 82 |
| 75 // QuotaTaskObserver ------------------------------------------------------- | 83 // QuotaTaskObserver ------------------------------------------------------- |
| 76 | 84 |
| 77 QuotaTaskObserver::~QuotaTaskObserver() { | 85 QuotaTaskObserver::~QuotaTaskObserver() { |
| 78 std::for_each(running_quota_tasks_.begin(), | 86 std::for_each(running_quota_tasks_.begin(), |
| 79 running_quota_tasks_.end(), | 87 running_quota_tasks_.end(), |
| 80 std::mem_fun(&QuotaTask::Abort)); | 88 std::mem_fun(&QuotaTask::Abort)); |
| 81 } | 89 } |
| 82 | 90 |
| 83 QuotaTaskObserver::QuotaTaskObserver() { | 91 QuotaTaskObserver::QuotaTaskObserver() { |
| 84 } | 92 } |
| 85 | 93 |
| 86 void QuotaTaskObserver::RegisterTask(QuotaTask* task) { | 94 void QuotaTaskObserver::RegisterTask(QuotaTask* task) { |
| 87 running_quota_tasks_.insert(task); | 95 running_quota_tasks_.insert(task); |
| 88 } | 96 } |
| 89 | 97 |
| 90 void QuotaTaskObserver::UnregisterTask(QuotaTask* task) { | 98 void QuotaTaskObserver::UnregisterTask(QuotaTask* task) { |
| 91 DCHECK(running_quota_tasks_.find(task) != running_quota_tasks_.end()); | 99 DCHECK(running_quota_tasks_.find(task) != running_quota_tasks_.end()); |
| 92 running_quota_tasks_.erase(task); | 100 running_quota_tasks_.erase(task); |
| 93 } | 101 } |
| 94 | 102 |
| 95 } // namespace quota | 103 } // namespace quota |
| OLD | NEW |