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 "webkit/browser/appcache/appcache_storage_impl.h" | 5 #include "webkit/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> |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 void AppCacheStorageImpl::MarkEntryAsForeignTask::RunCompleted() { | 1115 void AppCacheStorageImpl::MarkEntryAsForeignTask::RunCompleted() { |
1116 DCHECK(storage_->pending_foreign_markings_.front().first == entry_url_ && | 1116 DCHECK(storage_->pending_foreign_markings_.front().first == entry_url_ && |
1117 storage_->pending_foreign_markings_.front().second == cache_id_); | 1117 storage_->pending_foreign_markings_.front().second == cache_id_); |
1118 storage_->pending_foreign_markings_.pop_front(); | 1118 storage_->pending_foreign_markings_.pop_front(); |
1119 } | 1119 } |
1120 | 1120 |
1121 // MakeGroupObsoleteTask ------- | 1121 // MakeGroupObsoleteTask ------- |
1122 | 1122 |
1123 class AppCacheStorageImpl::MakeGroupObsoleteTask : public DatabaseTask { | 1123 class AppCacheStorageImpl::MakeGroupObsoleteTask : public DatabaseTask { |
1124 public: | 1124 public: |
1125 MakeGroupObsoleteTask(AppCacheStorageImpl* storage, AppCacheGroup* group); | 1125 MakeGroupObsoleteTask(AppCacheStorageImpl* storage, |
| 1126 AppCacheGroup* group, |
| 1127 int response_code); |
1126 | 1128 |
1127 // DatabaseTask: | 1129 // DatabaseTask: |
1128 virtual void Run() OVERRIDE; | 1130 virtual void Run() OVERRIDE; |
1129 virtual void RunCompleted() OVERRIDE; | 1131 virtual void RunCompleted() OVERRIDE; |
1130 virtual void CancelCompletion() OVERRIDE; | 1132 virtual void CancelCompletion() OVERRIDE; |
1131 | 1133 |
1132 protected: | 1134 protected: |
1133 virtual ~MakeGroupObsoleteTask() {} | 1135 virtual ~MakeGroupObsoleteTask() {} |
1134 | 1136 |
1135 private: | 1137 private: |
1136 scoped_refptr<AppCacheGroup> group_; | 1138 scoped_refptr<AppCacheGroup> group_; |
1137 int64 group_id_; | 1139 int64 group_id_; |
1138 GURL origin_; | 1140 GURL origin_; |
1139 bool success_; | 1141 bool success_; |
| 1142 int response_code_; |
1140 int64 new_origin_usage_; | 1143 int64 new_origin_usage_; |
1141 std::vector<int64> newly_deletable_response_ids_; | 1144 std::vector<int64> newly_deletable_response_ids_; |
1142 }; | 1145 }; |
1143 | 1146 |
1144 AppCacheStorageImpl::MakeGroupObsoleteTask::MakeGroupObsoleteTask( | 1147 AppCacheStorageImpl::MakeGroupObsoleteTask::MakeGroupObsoleteTask( |
1145 AppCacheStorageImpl* storage, AppCacheGroup* group) | 1148 AppCacheStorageImpl* storage, |
1146 : DatabaseTask(storage), group_(group), group_id_(group->group_id()), | 1149 AppCacheGroup* group, |
| 1150 int response_code) |
| 1151 : DatabaseTask(storage), |
| 1152 group_(group), |
| 1153 group_id_(group->group_id()), |
1147 origin_(group->manifest_url().GetOrigin()), | 1154 origin_(group->manifest_url().GetOrigin()), |
1148 success_(false), new_origin_usage_(-1) { | 1155 success_(false), |
1149 } | 1156 response_code_(response_code), |
| 1157 new_origin_usage_(-1) {} |
1150 | 1158 |
1151 void AppCacheStorageImpl::MakeGroupObsoleteTask::Run() { | 1159 void AppCacheStorageImpl::MakeGroupObsoleteTask::Run() { |
1152 DCHECK(!success_); | 1160 DCHECK(!success_); |
1153 sql::Connection* connection = database_->db_connection(); | 1161 sql::Connection* connection = database_->db_connection(); |
1154 if (!connection) | 1162 if (!connection) |
1155 return; | 1163 return; |
1156 | 1164 |
1157 sql::Transaction transaction(connection); | 1165 sql::Transaction transaction(connection); |
1158 if (!transaction.Begin()) | 1166 if (!transaction.Begin()) |
1159 return; | 1167 return; |
(...skipping 21 matching lines...) Expand all Loading... |
1181 if (!storage_->is_disabled()) { | 1189 if (!storage_->is_disabled()) { |
1182 storage_->UpdateUsageMapAndNotify(origin_, new_origin_usage_); | 1190 storage_->UpdateUsageMapAndNotify(origin_, new_origin_usage_); |
1183 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); | 1191 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); |
1184 | 1192 |
1185 // Also remove from the working set, caches for an 'obsolete' group | 1193 // Also remove from the working set, caches for an 'obsolete' group |
1186 // may linger in use, but the group itself cannot be looked up by | 1194 // may linger in use, but the group itself cannot be looked up by |
1187 // 'manifest_url' in the working set any longer. | 1195 // 'manifest_url' in the working set any longer. |
1188 storage_->working_set()->RemoveGroup(group_.get()); | 1196 storage_->working_set()->RemoveGroup(group_.get()); |
1189 } | 1197 } |
1190 } | 1198 } |
1191 FOR_EACH_DELEGATE(delegates_, OnGroupMadeObsolete(group_.get(), success_)); | 1199 FOR_EACH_DELEGATE( |
| 1200 delegates_, OnGroupMadeObsolete(group_.get(), success_, response_code_)); |
1192 group_ = NULL; | 1201 group_ = NULL; |
1193 } | 1202 } |
1194 | 1203 |
1195 void AppCacheStorageImpl::MakeGroupObsoleteTask::CancelCompletion() { | 1204 void AppCacheStorageImpl::MakeGroupObsoleteTask::CancelCompletion() { |
1196 // Overriden to safely drop our reference to the group | 1205 // Overriden to safely drop our reference to the group |
1197 // which is not thread safe refcounted. | 1206 // which is not thread safe refcounted. |
1198 DatabaseTask::CancelCompletion(); | 1207 DatabaseTask::CancelCompletion(); |
1199 group_ = NULL; | 1208 group_ = NULL; |
1200 } | 1209 } |
1201 | 1210 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 DCHECK(entry); | 1609 DCHECK(entry); |
1601 if (entry) | 1610 if (entry) |
1602 entry->add_types(AppCacheEntry::FOREIGN); | 1611 entry->add_types(AppCacheEntry::FOREIGN); |
1603 } | 1612 } |
1604 scoped_refptr<MarkEntryAsForeignTask> task( | 1613 scoped_refptr<MarkEntryAsForeignTask> task( |
1605 new MarkEntryAsForeignTask(this, entry_url, cache_id)); | 1614 new MarkEntryAsForeignTask(this, entry_url, cache_id)); |
1606 task->Schedule(); | 1615 task->Schedule(); |
1607 pending_foreign_markings_.push_back(std::make_pair(entry_url, cache_id)); | 1616 pending_foreign_markings_.push_back(std::make_pair(entry_url, cache_id)); |
1608 } | 1617 } |
1609 | 1618 |
1610 void AppCacheStorageImpl::MakeGroupObsolete( | 1619 void AppCacheStorageImpl::MakeGroupObsolete(AppCacheGroup* group, |
1611 AppCacheGroup* group, Delegate* delegate) { | 1620 Delegate* delegate, |
| 1621 int response_code) { |
1612 DCHECK(group && delegate); | 1622 DCHECK(group && delegate); |
1613 scoped_refptr<MakeGroupObsoleteTask> task( | 1623 scoped_refptr<MakeGroupObsoleteTask> task( |
1614 new MakeGroupObsoleteTask(this, group)); | 1624 new MakeGroupObsoleteTask(this, group, response_code)); |
1615 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | 1625 task->AddDelegate(GetOrCreateDelegateReference(delegate)); |
1616 task->Schedule(); | 1626 task->Schedule(); |
1617 } | 1627 } |
1618 | 1628 |
1619 AppCacheResponseReader* AppCacheStorageImpl::CreateResponseReader( | 1629 AppCacheResponseReader* AppCacheStorageImpl::CreateResponseReader( |
1620 const GURL& manifest_url, int64 group_id, int64 response_id) { | 1630 const GURL& manifest_url, int64 group_id, int64 response_id) { |
1621 return new AppCacheResponseReader(response_id, group_id, disk_cache()); | 1631 return new AppCacheResponseReader(response_id, group_id, disk_cache()); |
1622 } | 1632 } |
1623 | 1633 |
1624 AppCacheResponseWriter* AppCacheStorageImpl::CreateResponseWriter( | 1634 AppCacheResponseWriter* AppCacheStorageImpl::CreateResponseWriter( |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, | 1851 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, |
1842 weak_factory_.GetWeakPtr())); | 1852 weak_factory_.GetWeakPtr())); |
1843 } | 1853 } |
1844 | 1854 |
1845 void AppCacheStorageImpl::CallScheduleReinitialize() { | 1855 void AppCacheStorageImpl::CallScheduleReinitialize() { |
1846 service_->ScheduleReinitialize(); | 1856 service_->ScheduleReinitialize(); |
1847 // note: 'this' may be deleted at this point. | 1857 // note: 'this' may be deleted at this point. |
1848 } | 1858 } |
1849 | 1859 |
1850 } // namespace appcache | 1860 } // namespace appcache |
OLD | NEW |