Chromium Code Reviews| 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/appcache/appcache_storage_impl.h" | 5 #include "webkit/appcache/appcache_storage_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
| 10 #include "app/sql/transaction.h" | 10 #include "app/sql/transaction.h" |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 last_deletable_response_rowid_(0), | 1072 last_deletable_response_rowid_(0), |
| 1073 ALLOW_THIS_IN_INITIALIZER_LIST(doom_callback_( | 1073 ALLOW_THIS_IN_INITIALIZER_LIST(doom_callback_( |
| 1074 this, &AppCacheStorageImpl::OnDeletedOneResponse)), | 1074 this, &AppCacheStorageImpl::OnDeletedOneResponse)), |
| 1075 ALLOW_THIS_IN_INITIALIZER_LIST(init_callback_( | 1075 ALLOW_THIS_IN_INITIALIZER_LIST(init_callback_( |
| 1076 this, &AppCacheStorageImpl::OnDiskCacheInitialized)), | 1076 this, &AppCacheStorageImpl::OnDiskCacheInitialized)), |
| 1077 database_(NULL), is_disabled_(false), | 1077 database_(NULL), is_disabled_(false), |
| 1078 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 1078 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 1079 } | 1079 } |
| 1080 | 1080 |
| 1081 AppCacheStorageImpl::~AppCacheStorageImpl() { | 1081 AppCacheStorageImpl::~AppCacheStorageImpl() { |
| 1082 STLDeleteElements(&pending_simple_tasks_); | 1082 STLDeleteElements(&pending_simple_tasks_); |
|
michaeln
2011/07/14 00:42:34
I this this CL can be simplified a lot by posting
marja(google)
2011/07/14 10:31:59
Done.
| |
| 1083 | 1083 |
| 1084 std::for_each(pending_quota_queries_.begin(), | 1084 std::for_each(pending_quota_queries_.begin(), |
| 1085 pending_quota_queries_.end(), | 1085 pending_quota_queries_.end(), |
| 1086 std::mem_fun(&DatabaseTask::CancelCompletion)); | 1086 std::mem_fun(&DatabaseTask::CancelCompletion)); |
| 1087 std::for_each(scheduled_database_tasks_.begin(), | 1087 std::for_each(scheduled_database_tasks_.begin(), |
| 1088 scheduled_database_tasks_.end(), | 1088 scheduled_database_tasks_.end(), |
| 1089 std::mem_fun(&DatabaseTask::CancelCompletion)); | 1089 std::mem_fun(&DatabaseTask::CancelCompletion)); |
| 1090 | 1090 |
| 1091 if (database_) | 1091 if (database_) |
| 1092 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_); | 1092 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1120 task->Schedule(); | 1120 task->Schedule(); |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 void AppCacheStorageImpl::GetAllInfo(Delegate* delegate) { | 1123 void AppCacheStorageImpl::GetAllInfo(Delegate* delegate) { |
| 1124 DCHECK(delegate); | 1124 DCHECK(delegate); |
| 1125 scoped_refptr<GetAllInfoTask> task(new GetAllInfoTask(this)); | 1125 scoped_refptr<GetAllInfoTask> task(new GetAllInfoTask(this)); |
| 1126 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | 1126 task->AddDelegate(GetOrCreateDelegateReference(delegate)); |
| 1127 task->Schedule(); | 1127 task->Schedule(); |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 void AppCacheStorageImpl::SyncGetAllInfo(Delegate* delegate) { | |
| 1131 DCHECK(delegate); | |
| 1132 scoped_refptr<GetAllInfoTask> task(new GetAllInfoTask(this)); | |
| 1133 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | |
| 1134 task->Run(); | |
| 1135 task->RunCompleted(); | |
| 1136 } | |
| 1137 | |
| 1130 void AppCacheStorageImpl::LoadCache(int64 id, Delegate* delegate) { | 1138 void AppCacheStorageImpl::LoadCache(int64 id, Delegate* delegate) { |
| 1131 DCHECK(delegate); | 1139 DCHECK(delegate); |
| 1132 if (is_disabled_) { | 1140 if (is_disabled_) { |
| 1133 delegate->OnCacheLoaded(NULL, id); | 1141 delegate->OnCacheLoaded(NULL, id); |
| 1134 return; | 1142 return; |
| 1135 } | 1143 } |
| 1136 | 1144 |
| 1137 AppCache* cache = working_set_.GetCache(id); | 1145 AppCache* cache = working_set_.GetCache(id); |
| 1138 if (cache) { | 1146 if (cache) { |
| 1139 delegate->OnCacheLoaded(cache, id); | 1147 delegate->OnCacheLoaded(cache, id); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1187 delegate->OnGroupLoaded(group, manifest_url); | 1195 delegate->OnGroupLoaded(group, manifest_url); |
| 1188 return; | 1196 return; |
| 1189 } | 1197 } |
| 1190 | 1198 |
| 1191 task = new GroupLoadTask(manifest_url, this); | 1199 task = new GroupLoadTask(manifest_url, this); |
| 1192 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | 1200 task->AddDelegate(GetOrCreateDelegateReference(delegate)); |
| 1193 task->Schedule(); | 1201 task->Schedule(); |
| 1194 pending_group_loads_[manifest_url] = task.get(); | 1202 pending_group_loads_[manifest_url] = task.get(); |
| 1195 } | 1203 } |
| 1196 | 1204 |
| 1205 void AppCacheStorageImpl::SyncLoadOrCreateGroup( | |
| 1206 const GURL& manifest_url, Delegate* delegate) { | |
| 1207 DCHECK(delegate); | |
| 1208 if (is_disabled_) { | |
| 1209 delegate->OnGroupLoaded(NULL, manifest_url); | |
| 1210 return; | |
| 1211 } | |
| 1212 | |
| 1213 AppCacheGroup* group = working_set_.GetGroup(manifest_url); | |
| 1214 if (group) { | |
| 1215 delegate->OnGroupLoaded(group, manifest_url); | |
| 1216 scoped_refptr<DatabaseTask> update_task( | |
| 1217 new UpdateGroupLastAccessTimeTask( | |
| 1218 this, group, base::Time::Now())); | |
| 1219 update_task->Run(); | |
| 1220 update_task->RunCompleted(); | |
| 1221 return; | |
| 1222 } | |
| 1223 | |
| 1224 if (usage_map_.find(manifest_url.GetOrigin()) == usage_map_.end()) { | |
| 1225 // No need to query the database, return a new group immediately. | |
| 1226 scoped_refptr<AppCacheGroup> group(new AppCacheGroup( | |
| 1227 service_, manifest_url, NewGroupId())); | |
| 1228 delegate->OnGroupLoaded(group, manifest_url); | |
| 1229 return; | |
| 1230 } | |
| 1231 | |
| 1232 scoped_refptr<GroupLoadTask> task = new GroupLoadTask(manifest_url, this); | |
| 1233 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | |
| 1234 task->Run(); | |
| 1235 task->RunCompleted(); | |
| 1236 } | |
| 1237 | |
| 1197 void AppCacheStorageImpl::StoreGroupAndNewestCache( | 1238 void AppCacheStorageImpl::StoreGroupAndNewestCache( |
| 1198 AppCacheGroup* group, AppCache* newest_cache, Delegate* delegate) { | 1239 AppCacheGroup* group, AppCache* newest_cache, Delegate* delegate) { |
| 1199 // TODO(michaeln): distinguish between a simple update of an existing | 1240 // TODO(michaeln): distinguish between a simple update of an existing |
| 1200 // cache that just adds new master entry(s), and the insertion of a | 1241 // cache that just adds new master entry(s), and the insertion of a |
| 1201 // whole new cache. The StoreGroupAndCacheTask as written will handle | 1242 // whole new cache. The StoreGroupAndCacheTask as written will handle |
| 1202 // the simple update case in a very heavy weight way (delete all and | 1243 // the simple update case in a very heavy weight way (delete all and |
| 1203 // the reinsert all over again). | 1244 // the reinsert all over again). |
| 1204 DCHECK(group && delegate && newest_cache); | 1245 DCHECK(group && delegate && newest_cache); |
| 1205 scoped_refptr<StoreGroupAndCacheTask> task( | 1246 scoped_refptr<StoreGroupAndCacheTask> task( |
| 1206 new StoreGroupAndCacheTask(this, group, newest_cache)); | 1247 new StoreGroupAndCacheTask(this, group, newest_cache)); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1366 | 1407 |
| 1367 void AppCacheStorageImpl::MakeGroupObsolete( | 1408 void AppCacheStorageImpl::MakeGroupObsolete( |
| 1368 AppCacheGroup* group, Delegate* delegate) { | 1409 AppCacheGroup* group, Delegate* delegate) { |
| 1369 DCHECK(group && delegate); | 1410 DCHECK(group && delegate); |
| 1370 scoped_refptr<MakeGroupObsoleteTask> task( | 1411 scoped_refptr<MakeGroupObsoleteTask> task( |
| 1371 new MakeGroupObsoleteTask(this, group)); | 1412 new MakeGroupObsoleteTask(this, group)); |
| 1372 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | 1413 task->AddDelegate(GetOrCreateDelegateReference(delegate)); |
| 1373 task->Schedule(); | 1414 task->Schedule(); |
| 1374 } | 1415 } |
| 1375 | 1416 |
| 1417 void AppCacheStorageImpl::SyncMakeGroupObsolete( | |
| 1418 AppCacheGroup* group, Delegate* delegate) { | |
| 1419 DCHECK(group && delegate); | |
| 1420 scoped_refptr<MakeGroupObsoleteTask> task( | |
| 1421 new MakeGroupObsoleteTask(this, group)); | |
| 1422 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | |
| 1423 task->Run(); | |
| 1424 task->RunCompleted(); | |
| 1425 } | |
| 1426 | |
| 1376 AppCacheResponseReader* AppCacheStorageImpl::CreateResponseReader( | 1427 AppCacheResponseReader* AppCacheStorageImpl::CreateResponseReader( |
| 1377 const GURL& manifest_url, int64 response_id) { | 1428 const GURL& manifest_url, int64 response_id) { |
| 1378 return new AppCacheResponseReader(response_id, disk_cache()); | 1429 return new AppCacheResponseReader(response_id, disk_cache()); |
| 1379 } | 1430 } |
| 1380 | 1431 |
| 1381 AppCacheResponseWriter* AppCacheStorageImpl::CreateResponseWriter( | 1432 AppCacheResponseWriter* AppCacheStorageImpl::CreateResponseWriter( |
| 1382 const GURL& manifest_url) { | 1433 const GURL& manifest_url) { |
| 1383 return new AppCacheResponseWriter(NewResponseId(), disk_cache()); | 1434 return new AppCacheResponseWriter(NewResponseId(), disk_cache()); |
| 1384 } | 1435 } |
| 1385 | 1436 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1571 Disable(); | 1622 Disable(); |
| 1572 if (!is_incognito_) { | 1623 if (!is_incognito_) { |
| 1573 VLOG(1) << "Deleting existing appcache data and starting over."; | 1624 VLOG(1) << "Deleting existing appcache data and starting over."; |
| 1574 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, | 1625 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, |
| 1575 NewRunnableFunction(DeleteDirectory, cache_directory_)); | 1626 NewRunnableFunction(DeleteDirectory, cache_directory_)); |
| 1576 } | 1627 } |
| 1577 } | 1628 } |
| 1578 } | 1629 } |
| 1579 | 1630 |
| 1580 } // namespace appcache | 1631 } // namespace appcache |
| OLD | NEW |