| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/appcache/appcache_storage_impl.h" | 5 #include "content/browser/appcache/appcache_storage_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/location.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/message_loop/message_loop.h" | |
| 17 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/thread_task_runner_handle.h" |
| 21 #include "content/browser/appcache/appcache.h" | 22 #include "content/browser/appcache/appcache.h" |
| 22 #include "content/browser/appcache/appcache_database.h" | 23 #include "content/browser/appcache/appcache_database.h" |
| 23 #include "content/browser/appcache/appcache_entry.h" | 24 #include "content/browser/appcache/appcache_entry.h" |
| 24 #include "content/browser/appcache/appcache_group.h" | 25 #include "content/browser/appcache/appcache_group.h" |
| 25 #include "content/browser/appcache/appcache_histograms.h" | 26 #include "content/browser/appcache/appcache_histograms.h" |
| 26 #include "content/browser/appcache/appcache_quota_client.h" | 27 #include "content/browser/appcache/appcache_quota_client.h" |
| 27 #include "content/browser/appcache/appcache_response.h" | 28 #include "content/browser/appcache/appcache_response.h" |
| 28 #include "content/browser/appcache/appcache_service_impl.h" | 29 #include "content/browser/appcache/appcache_service_impl.h" |
| 29 #include "net/base/cache_type.h" | 30 #include "net/base/cache_type.h" |
| 30 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace | 132 } // namespace |
| 132 | 133 |
| 133 // DatabaseTask ----------------------------------------- | 134 // DatabaseTask ----------------------------------------- |
| 134 | 135 |
| 135 class AppCacheStorageImpl::DatabaseTask | 136 class AppCacheStorageImpl::DatabaseTask |
| 136 : public base::RefCountedThreadSafe<DatabaseTask> { | 137 : public base::RefCountedThreadSafe<DatabaseTask> { |
| 137 public: | 138 public: |
| 138 explicit DatabaseTask(AppCacheStorageImpl* storage) | 139 explicit DatabaseTask(AppCacheStorageImpl* storage) |
| 139 : storage_(storage), database_(storage->database_), | 140 : storage_(storage), |
| 140 io_thread_(base::MessageLoopProxy::current()) { | 141 database_(storage->database_), |
| 142 io_thread_(base::ThreadTaskRunnerHandle::Get()) { |
| 141 DCHECK(io_thread_.get()); | 143 DCHECK(io_thread_.get()); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void AddDelegate(DelegateReference* delegate_reference) { | 146 void AddDelegate(DelegateReference* delegate_reference) { |
| 145 delegates_.push_back(make_scoped_refptr(delegate_reference)); | 147 delegates_.push_back(make_scoped_refptr(delegate_reference)); |
| 146 } | 148 } |
| 147 | 149 |
| 148 // Schedules a task to be Run() on the DB thread. Tasks | 150 // Schedules a task to be Run() on the DB thread. Tasks |
| 149 // are run in the order in which they are scheduled. | 151 // are run in the order in which they are scheduled. |
| 150 void Schedule(); | 152 void Schedule(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 171 | 173 |
| 172 AppCacheStorageImpl* storage_; | 174 AppCacheStorageImpl* storage_; |
| 173 AppCacheDatabase* database_; | 175 AppCacheDatabase* database_; |
| 174 DelegateReferenceVector delegates_; | 176 DelegateReferenceVector delegates_; |
| 175 | 177 |
| 176 private: | 178 private: |
| 177 void CallRun(base::TimeTicks schedule_time); | 179 void CallRun(base::TimeTicks schedule_time); |
| 178 void CallRunCompleted(base::TimeTicks schedule_time); | 180 void CallRunCompleted(base::TimeTicks schedule_time); |
| 179 void OnFatalError(); | 181 void OnFatalError(); |
| 180 | 182 |
| 181 scoped_refptr<base::MessageLoopProxy> io_thread_; | 183 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
| 182 }; | 184 }; |
| 183 | 185 |
| 184 void AppCacheStorageImpl::DatabaseTask::Schedule() { | 186 void AppCacheStorageImpl::DatabaseTask::Schedule() { |
| 185 DCHECK(storage_); | 187 DCHECK(storage_); |
| 186 DCHECK(io_thread_->BelongsToCurrentThread()); | 188 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 187 if (!storage_->database_) | 189 if (!storage_->database_) |
| 188 return; | 190 return; |
| 189 | 191 |
| 190 if (storage_->db_thread_->PostTask( | 192 if (storage_->db_thread_->PostTask( |
| 191 FROM_HERE, | 193 FROM_HERE, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 309 |
| 308 void AppCacheStorageImpl::InitTask::RunCompleted() { | 310 void AppCacheStorageImpl::InitTask::RunCompleted() { |
| 309 storage_->last_group_id_ = last_group_id_; | 311 storage_->last_group_id_ = last_group_id_; |
| 310 storage_->last_cache_id_ = last_cache_id_; | 312 storage_->last_cache_id_ = last_cache_id_; |
| 311 storage_->last_response_id_ = last_response_id_; | 313 storage_->last_response_id_ = last_response_id_; |
| 312 storage_->last_deletable_response_rowid_ = last_deletable_response_rowid_; | 314 storage_->last_deletable_response_rowid_ = last_deletable_response_rowid_; |
| 313 | 315 |
| 314 if (!storage_->is_disabled()) { | 316 if (!storage_->is_disabled()) { |
| 315 storage_->usage_map_.swap(usage_map_); | 317 storage_->usage_map_.swap(usage_map_); |
| 316 const base::TimeDelta kDelay = base::TimeDelta::FromMinutes(5); | 318 const base::TimeDelta kDelay = base::TimeDelta::FromMinutes(5); |
| 317 base::MessageLoop::current()->PostDelayedTask( | 319 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 318 FROM_HERE, | 320 FROM_HERE, |
| 319 base::Bind(&AppCacheStorageImpl::DelayedStartDeletingUnusedResponses, | 321 base::Bind(&AppCacheStorageImpl::DelayedStartDeletingUnusedResponses, |
| 320 storage_->weak_factory_.GetWeakPtr()), | 322 storage_->weak_factory_.GetWeakPtr()), |
| 321 kDelay); | 323 kDelay); |
| 322 } | 324 } |
| 323 | 325 |
| 324 if (storage_->service()->quota_client()) | 326 if (storage_->service()->quota_client()) |
| 325 storage_->service()->quota_client()->NotifyAppCacheReady(); | 327 storage_->service()->quota_client()->NotifyAppCacheReady(); |
| 326 } | 328 } |
| 327 | 329 |
| (...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1731 deletable_response_ids_.insert( | 1733 deletable_response_ids_.insert( |
| 1732 deletable_response_ids_.end(), | 1734 deletable_response_ids_.end(), |
| 1733 response_ids.begin(), response_ids.end()); | 1735 response_ids.begin(), response_ids.end()); |
| 1734 if (!is_response_deletion_scheduled_) | 1736 if (!is_response_deletion_scheduled_) |
| 1735 ScheduleDeleteOneResponse(); | 1737 ScheduleDeleteOneResponse(); |
| 1736 } | 1738 } |
| 1737 | 1739 |
| 1738 void AppCacheStorageImpl::ScheduleDeleteOneResponse() { | 1740 void AppCacheStorageImpl::ScheduleDeleteOneResponse() { |
| 1739 DCHECK(!is_response_deletion_scheduled_); | 1741 DCHECK(!is_response_deletion_scheduled_); |
| 1740 const base::TimeDelta kBriefDelay = base::TimeDelta::FromMilliseconds(10); | 1742 const base::TimeDelta kBriefDelay = base::TimeDelta::FromMilliseconds(10); |
| 1741 base::MessageLoop::current()->PostDelayedTask( | 1743 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1742 FROM_HERE, | 1744 FROM_HERE, base::Bind(&AppCacheStorageImpl::DeleteOneResponse, |
| 1743 base::Bind(&AppCacheStorageImpl::DeleteOneResponse, | 1745 weak_factory_.GetWeakPtr()), |
| 1744 weak_factory_.GetWeakPtr()), | |
| 1745 kBriefDelay); | 1746 kBriefDelay); |
| 1746 is_response_deletion_scheduled_ = true; | 1747 is_response_deletion_scheduled_ = true; |
| 1747 } | 1748 } |
| 1748 | 1749 |
| 1749 void AppCacheStorageImpl::DeleteOneResponse() { | 1750 void AppCacheStorageImpl::DeleteOneResponse() { |
| 1750 DCHECK(is_response_deletion_scheduled_); | 1751 DCHECK(is_response_deletion_scheduled_); |
| 1751 DCHECK(!deletable_response_ids_.empty()); | 1752 DCHECK(!deletable_response_ids_.empty()); |
| 1752 | 1753 |
| 1753 if (!disk_cache()) { | 1754 if (!disk_cache()) { |
| 1754 DCHECK(is_disabled_); | 1755 DCHECK(is_disabled_); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 PendingForeignMarkings::iterator iter = pending_foreign_markings_.begin(); | 1818 PendingForeignMarkings::iterator iter = pending_foreign_markings_.begin(); |
| 1818 while (iter != pending_foreign_markings_.end()) { | 1819 while (iter != pending_foreign_markings_.end()) { |
| 1819 if (iter->second == cache_id) | 1820 if (iter->second == cache_id) |
| 1820 urls->push_back(iter->first); | 1821 urls->push_back(iter->first); |
| 1821 ++iter; | 1822 ++iter; |
| 1822 } | 1823 } |
| 1823 } | 1824 } |
| 1824 | 1825 |
| 1825 void AppCacheStorageImpl::ScheduleSimpleTask(const base::Closure& task) { | 1826 void AppCacheStorageImpl::ScheduleSimpleTask(const base::Closure& task) { |
| 1826 pending_simple_tasks_.push_back(task); | 1827 pending_simple_tasks_.push_back(task); |
| 1827 base::MessageLoop::current()->PostTask( | 1828 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1828 FROM_HERE, | 1829 FROM_HERE, base::Bind(&AppCacheStorageImpl::RunOnePendingSimpleTask, |
| 1829 base::Bind(&AppCacheStorageImpl::RunOnePendingSimpleTask, | 1830 weak_factory_.GetWeakPtr())); |
| 1830 weak_factory_.GetWeakPtr())); | |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 void AppCacheStorageImpl::RunOnePendingSimpleTask() { | 1833 void AppCacheStorageImpl::RunOnePendingSimpleTask() { |
| 1834 DCHECK(!pending_simple_tasks_.empty()); | 1834 DCHECK(!pending_simple_tasks_.empty()); |
| 1835 base::Closure task = pending_simple_tasks_.front(); | 1835 base::Closure task = pending_simple_tasks_.front(); |
| 1836 pending_simple_tasks_.pop_front(); | 1836 pending_simple_tasks_.pop_front(); |
| 1837 task.Run(); | 1837 task.Run(); |
| 1838 } | 1838 } |
| 1839 | 1839 |
| 1840 AppCacheDiskCache* AppCacheStorageImpl::disk_cache() { | 1840 AppCacheDiskCache* AppCacheStorageImpl::disk_cache() { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 | 1921 |
| 1922 void AppCacheStorageImpl::OnLazyCommitTimer() { | 1922 void AppCacheStorageImpl::OnLazyCommitTimer() { |
| 1923 lazy_commit_timer_.Stop(); | 1923 lazy_commit_timer_.Stop(); |
| 1924 if (is_disabled()) | 1924 if (is_disabled()) |
| 1925 return; | 1925 return; |
| 1926 scoped_refptr<DatabaseTask> task(new CommitLastAccessTimesTask(this)); | 1926 scoped_refptr<DatabaseTask> task(new CommitLastAccessTimesTask(this)); |
| 1927 task->Schedule(); | 1927 task->Schedule(); |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 } // namespace content | 1930 } // namespace content |
| OLD | NEW |