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