OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/sql/connection.h" | 7 #include "app/sql/connection.h" |
8 #include "app/sql/transaction.h" | 8 #include "app/sql/transaction.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 origin != origins.end(); ++origin) { | 214 origin != origins.end(); ++origin) { |
215 AppCacheInfoVector& infos = | 215 AppCacheInfoVector& infos = |
216 info_collection_->infos_by_origin[*origin]; | 216 info_collection_->infos_by_origin[*origin]; |
217 std::vector<AppCacheDatabase::GroupRecord> groups; | 217 std::vector<AppCacheDatabase::GroupRecord> groups; |
218 database_->FindGroupsForOrigin(*origin, &groups); | 218 database_->FindGroupsForOrigin(*origin, &groups); |
219 for (std::vector<AppCacheDatabase::GroupRecord>::const_iterator | 219 for (std::vector<AppCacheDatabase::GroupRecord>::const_iterator |
220 group = groups.begin(); | 220 group = groups.begin(); |
221 group != groups.end(); ++group) { | 221 group != groups.end(); ++group) { |
222 AppCacheDatabase::CacheRecord cache_record; | 222 AppCacheDatabase::CacheRecord cache_record; |
223 database_->FindCacheForGroup(group->group_id, &cache_record); | 223 database_->FindCacheForGroup(group->group_id, &cache_record); |
224 infos.push_back( | 224 AppCacheInfo info; |
225 AppCacheInfo( | 225 info.manifest_url = group->manifest_url; |
226 group->manifest_url, cache_record.cache_size, | 226 info.creation_time = group->creation_time; |
227 group->creation_time, group->last_access_time, | 227 info.size = cache_record.cache_size; |
228 cache_record.update_time)); | 228 info.last_access_time = group->last_access_time; |
229 info.last_update_time = cache_record.update_time; | |
230 info.cache_id = cache_record.cache_id; | |
231 info.is_complete = true; | |
michaeln
2010/07/27 19:10:50
did you intend to set status here too?
| |
232 infos.push_back(info); | |
229 } | 233 } |
230 } | 234 } |
231 } | 235 } |
232 | 236 |
233 void AppCacheStorageImpl::GetAllInfoTask::RunCompleted() { | 237 void AppCacheStorageImpl::GetAllInfoTask::RunCompleted() { |
234 DCHECK(delegates_.size() == 1); | 238 DCHECK(delegates_.size() == 1); |
235 FOR_EACH_DELEGATE(delegates_, OnAllInfo(info_collection_)); | 239 FOR_EACH_DELEGATE(delegates_, OnAllInfo(info_collection_)); |
236 } | 240 } |
237 | 241 |
238 // StoreOrLoadTask ------- | 242 // StoreOrLoadTask ------- |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 cache->get()->set_complete(true); | 279 cache->get()->set_complete(true); |
276 | 280 |
277 (*group) = storage_->working_set_.GetGroup(group_record_.manifest_url); | 281 (*group) = storage_->working_set_.GetGroup(group_record_.manifest_url); |
278 if (group->get()) { | 282 if (group->get()) { |
279 DCHECK(group_record_.group_id == group->get()->group_id()); | 283 DCHECK(group_record_.group_id == group->get()->group_id()); |
280 group->get()->AddCache(cache->get()); | 284 group->get()->AddCache(cache->get()); |
281 } else { | 285 } else { |
282 (*group) = new AppCacheGroup( | 286 (*group) = new AppCacheGroup( |
283 storage_->service_, group_record_.manifest_url, | 287 storage_->service_, group_record_.manifest_url, |
284 group_record_.group_id); | 288 group_record_.group_id); |
289 group->get()->set_creation_time(group_record_.creation_time); | |
285 group->get()->AddCache(cache->get()); | 290 group->get()->AddCache(cache->get()); |
286 } | 291 } |
287 DCHECK(group->get()->newest_complete_cache() == cache->get()); | 292 DCHECK(group->get()->newest_complete_cache() == cache->get()); |
288 | 293 |
289 // We have to update foriegn entries if MarkEntryAsForeignTasks | 294 // We have to update foriegn entries if MarkEntryAsForeignTasks |
290 // are in flight. | 295 // are in flight. |
291 std::vector<GURL> urls; | 296 std::vector<GURL> urls; |
292 storage_->GetPendingForeignMarkingsForCache(cache->get()->cache_id(), &urls); | 297 storage_->GetPendingForeignMarkingsForCache(cache->get()->cache_id(), &urls); |
293 for (std::vector<GURL>::iterator iter = urls.begin(); | 298 for (std::vector<GURL>::iterator iter = urls.begin(); |
294 iter != urls.end(); ++iter) { | 299 iter != urls.end(); ++iter) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 scoped_refptr<AppCacheGroup> group; | 374 scoped_refptr<AppCacheGroup> group; |
370 scoped_refptr<AppCache> cache; | 375 scoped_refptr<AppCache> cache; |
371 if (!storage_->is_disabled()) { | 376 if (!storage_->is_disabled()) { |
372 if (success_) { | 377 if (success_) { |
373 DCHECK(group_record_.manifest_url == manifest_url_); | 378 DCHECK(group_record_.manifest_url == manifest_url_); |
374 DCHECK(!storage_->working_set_.GetGroup(manifest_url_)); | 379 DCHECK(!storage_->working_set_.GetGroup(manifest_url_)); |
375 DCHECK(!storage_->working_set_.GetCache(cache_record_.cache_id)); | 380 DCHECK(!storage_->working_set_.GetCache(cache_record_.cache_id)); |
376 CreateCacheAndGroupFromRecords(&cache, &group); | 381 CreateCacheAndGroupFromRecords(&cache, &group); |
377 } else { | 382 } else { |
378 group = new AppCacheGroup( | 383 group = new AppCacheGroup( |
379 storage_->service_, manifest_url_, | 384 storage_->service_, manifest_url_, storage_->NewGroupId()); |
380 storage_->NewGroupId()); | |
381 } | 385 } |
382 } | 386 } |
383 FOR_EACH_DELEGATE(delegates_, OnGroupLoaded(group, manifest_url_)); | 387 FOR_EACH_DELEGATE(delegates_, OnGroupLoaded(group, manifest_url_)); |
384 } | 388 } |
385 | 389 |
386 // StoreGroupAndCacheTask ------- | 390 // StoreGroupAndCacheTask ------- |
387 | 391 |
388 class AppCacheStorageImpl::StoreGroupAndCacheTask : public StoreOrLoadTask { | 392 class AppCacheStorageImpl::StoreGroupAndCacheTask : public StoreOrLoadTask { |
389 public: | 393 public: |
390 StoreGroupAndCacheTask(AppCacheStorageImpl* storage, AppCacheGroup* group, | 394 StoreGroupAndCacheTask(AppCacheStorageImpl* storage, AppCacheGroup* group, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 database_->InsertEntryRecords(entry_records_) && | 480 database_->InsertEntryRecords(entry_records_) && |
477 database_->InsertFallbackNameSpaceRecords(fallback_namespace_records_)&& | 481 database_->InsertFallbackNameSpaceRecords(fallback_namespace_records_)&& |
478 database_->InsertOnlineWhiteListRecords(online_whitelist_records_) && | 482 database_->InsertOnlineWhiteListRecords(online_whitelist_records_) && |
479 (database_->GetOriginUsage(group_record_.origin) <= | 483 (database_->GetOriginUsage(group_record_.origin) <= |
480 database_->GetOriginQuota(group_record_.origin)) && | 484 database_->GetOriginQuota(group_record_.origin)) && |
481 transaction.Commit(); | 485 transaction.Commit(); |
482 } | 486 } |
483 | 487 |
484 void AppCacheStorageImpl::StoreGroupAndCacheTask::RunCompleted() { | 488 void AppCacheStorageImpl::StoreGroupAndCacheTask::RunCompleted() { |
485 if (success_) { | 489 if (success_) { |
490 // TODO(kkanetkar): Add to creation time when that's enabled. | |
486 storage_->origins_with_groups_.insert(group_->manifest_url().GetOrigin()); | 491 storage_->origins_with_groups_.insert(group_->manifest_url().GetOrigin()); |
487 if (cache_ != group_->newest_complete_cache()) { | 492 if (cache_ != group_->newest_complete_cache()) { |
488 cache_->set_complete(true); | 493 cache_->set_complete(true); |
489 group_->AddCache(cache_); | 494 group_->AddCache(cache_); |
490 } | 495 } |
491 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); | 496 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); |
492 } | 497 } |
493 FOR_EACH_DELEGATE(delegates_, | 498 FOR_EACH_DELEGATE(delegates_, |
494 OnGroupAndNewestCacheStored(group_, cache_, success_)); | 499 OnGroupAndNewestCacheStored(group_, cache_, success_)); |
495 group_ = NULL; | 500 group_ = NULL; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 | 534 |
530 GURL url_; | 535 GURL url_; |
531 std::set<int64> cache_ids_in_use_; | 536 std::set<int64> cache_ids_in_use_; |
532 AppCacheEntry entry_; | 537 AppCacheEntry entry_; |
533 AppCacheEntry fallback_entry_; | 538 AppCacheEntry fallback_entry_; |
534 int64 cache_id_; | 539 int64 cache_id_; |
535 GURL manifest_url_; | 540 GURL manifest_url_; |
536 }; | 541 }; |
537 | 542 |
538 namespace { | 543 namespace { |
539 | |
540 bool SortByLength( | 544 bool SortByLength( |
541 const AppCacheDatabase::FallbackNameSpaceRecord& lhs, | 545 const AppCacheDatabase::FallbackNameSpaceRecord& lhs, |
542 const AppCacheDatabase::FallbackNameSpaceRecord& rhs) { | 546 const AppCacheDatabase::FallbackNameSpaceRecord& rhs) { |
543 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); | 547 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); |
544 } | 548 } |
545 | |
546 } | 549 } |
547 | 550 |
548 void AppCacheStorageImpl::FindMainResponseTask::Run() { | 551 void AppCacheStorageImpl::FindMainResponseTask::Run() { |
549 // We have a bias for hits from caches that are in use. | 552 // We have a bias for hits from caches that are in use. |
550 | 553 |
551 // TODO(michaeln): The heuristics around choosing amoungst | 554 // TODO(michaeln): The heuristics around choosing amoungst |
552 // multiple candidates is under specified, and just plain | 555 // multiple candidates is under specified, and just plain |
553 // not fully understood. Refine these over time. In particular, | 556 // not fully understood. Refine these over time. In particular, |
554 // * prefer candidates from newer caches | 557 // * prefer candidates from newer caches |
555 // * take into account the cache associated with the document | 558 // * take into account the cache associated with the document |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 Disable(); | 1302 Disable(); |
1300 if (!is_incognito_) { | 1303 if (!is_incognito_) { |
1301 LOG(INFO) << "Deleting existing appcache data and starting over."; | 1304 LOG(INFO) << "Deleting existing appcache data and starting over."; |
1302 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, | 1305 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, |
1303 NewRunnableFunction(DeleteDirectory, cache_directory_)); | 1306 NewRunnableFunction(DeleteDirectory, cache_directory_)); |
1304 } | 1307 } |
1305 } | 1308 } |
1306 } | 1309 } |
1307 | 1310 |
1308 } // namespace appcache | 1311 } // namespace appcache |
OLD | NEW |