Chromium Code Reviews| 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/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/profiler/scoped_tracker.h" | |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 20 #include "content/browser/appcache/appcache.h" | 21 #include "content/browser/appcache/appcache.h" |
| 21 #include "content/browser/appcache/appcache_database.h" | 22 #include "content/browser/appcache/appcache_database.h" |
| 22 #include "content/browser/appcache/appcache_entry.h" | 23 #include "content/browser/appcache/appcache_entry.h" |
| 23 #include "content/browser/appcache/appcache_group.h" | 24 #include "content/browser/appcache/appcache_group.h" |
| 24 #include "content/browser/appcache/appcache_histograms.h" | 25 #include "content/browser/appcache/appcache_histograms.h" |
| 25 #include "content/browser/appcache/appcache_quota_client.h" | 26 #include "content/browser/appcache/appcache_quota_client.h" |
| 26 #include "content/browser/appcache/appcache_response.h" | 27 #include "content/browser/appcache/appcache_response.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 base::FilePath db_file_path_; | 279 base::FilePath db_file_path_; |
| 279 base::FilePath disk_cache_directory_; | 280 base::FilePath disk_cache_directory_; |
| 280 int64 last_group_id_; | 281 int64 last_group_id_; |
| 281 int64 last_cache_id_; | 282 int64 last_cache_id_; |
| 282 int64 last_response_id_; | 283 int64 last_response_id_; |
| 283 int64 last_deletable_response_rowid_; | 284 int64 last_deletable_response_rowid_; |
| 284 std::map<GURL, int64> usage_map_; | 285 std::map<GURL, int64> usage_map_; |
| 285 }; | 286 }; |
| 286 | 287 |
| 287 void AppCacheStorageImpl::InitTask::Run() { | 288 void AppCacheStorageImpl::InitTask::Run() { |
| 289 tracked_objects::ScopedTracker tracking_profile( | |
| 290 FROM_HERE_WITH_EXPLICIT_FUNCTION("AppCacheStorageImpl::InitTask")); | |
| 288 // If there is no sql database, ensure there is no disk cache either. | 291 // If there is no sql database, ensure there is no disk cache either. |
| 289 if (!db_file_path_.empty() && | 292 if (!db_file_path_.empty() && |
| 290 !base::PathExists(db_file_path_) && | 293 !base::PathExists(db_file_path_) && |
| 291 base::DirectoryExists(disk_cache_directory_)) { | 294 base::DirectoryExists(disk_cache_directory_)) { |
| 292 base::DeleteFile(disk_cache_directory_, true); | 295 base::DeleteFile(disk_cache_directory_, true); |
| 293 if (base::DirectoryExists(disk_cache_directory_)) { | 296 if (base::DirectoryExists(disk_cache_directory_)) { |
| 294 database_->Disable(); // This triggers OnFatalError handling. | 297 database_->Disable(); // This triggers OnFatalError handling. |
| 295 return; | 298 return; |
| 296 } | 299 } |
| 297 } | 300 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 | 508 |
| 506 protected: | 509 protected: |
| 507 ~CacheLoadTask() override {} | 510 ~CacheLoadTask() override {} |
| 508 | 511 |
| 509 private: | 512 private: |
| 510 int64 cache_id_; | 513 int64 cache_id_; |
| 511 bool success_; | 514 bool success_; |
| 512 }; | 515 }; |
| 513 | 516 |
| 514 void AppCacheStorageImpl::CacheLoadTask::Run() { | 517 void AppCacheStorageImpl::CacheLoadTask::Run() { |
| 518 tracked_objects::ScopedTracker tracking_profile( | |
| 519 FROM_HERE_WITH_EXPLICIT_FUNCTION("AppCacheStorageImpl::CacheLoadTask")); | |
| 515 success_ = | 520 success_ = |
| 516 database_->FindCache(cache_id_, &cache_record_) && | 521 database_->FindCache(cache_id_, &cache_record_) && |
| 517 database_->FindGroup(cache_record_.group_id, &group_record_) && | 522 database_->FindGroup(cache_record_.group_id, &group_record_) && |
| 518 FindRelatedCacheRecords(cache_id_); | 523 FindRelatedCacheRecords(cache_id_); |
| 519 | 524 |
| 520 if (success_) | 525 if (success_) |
| 521 database_->UpdateGroupLastAccessTime(group_record_.group_id, | 526 database_->LazyUpdateLastAccessTime(group_record_.group_id, |
| 522 base::Time::Now()); | 527 base::Time::Now()); |
| 523 } | 528 } |
| 524 | 529 |
| 525 void AppCacheStorageImpl::CacheLoadTask::RunCompleted() { | 530 void AppCacheStorageImpl::CacheLoadTask::RunCompleted() { |
| 526 storage_->pending_cache_loads_.erase(cache_id_); | 531 storage_->pending_cache_loads_.erase(cache_id_); |
| 527 scoped_refptr<AppCache> cache; | 532 scoped_refptr<AppCache> cache; |
| 528 scoped_refptr<AppCacheGroup> group; | 533 scoped_refptr<AppCacheGroup> group; |
| 529 if (success_ && !storage_->is_disabled()) { | 534 if (success_ && !storage_->is_disabled()) { |
| 535 storage_->LazilyCommitLastAccessTimes(); | |
| 530 DCHECK(cache_record_.cache_id == cache_id_); | 536 DCHECK(cache_record_.cache_id == cache_id_); |
| 531 CreateCacheAndGroupFromRecords(&cache, &group); | 537 CreateCacheAndGroupFromRecords(&cache, &group); |
| 532 } | 538 } |
| 533 FOR_EACH_DELEGATE(delegates_, OnCacheLoaded(cache.get(), cache_id_)); | 539 FOR_EACH_DELEGATE(delegates_, OnCacheLoaded(cache.get(), cache_id_)); |
| 534 } | 540 } |
| 535 | 541 |
| 536 // GroupLoadTask ------- | 542 // GroupLoadTask ------- |
| 537 | 543 |
| 538 class AppCacheStorageImpl::GroupLoadTask : public StoreOrLoadTask { | 544 class AppCacheStorageImpl::GroupLoadTask : public StoreOrLoadTask { |
| 539 public: | 545 public: |
| 540 GroupLoadTask(GURL manifest_url, AppCacheStorageImpl* storage) | 546 GroupLoadTask(GURL manifest_url, AppCacheStorageImpl* storage) |
| 541 : StoreOrLoadTask(storage), manifest_url_(manifest_url), | 547 : StoreOrLoadTask(storage), manifest_url_(manifest_url), |
| 542 success_(false) {} | 548 success_(false) {} |
| 543 | 549 |
| 544 // DatabaseTask: | 550 // DatabaseTask: |
| 545 void Run() override; | 551 void Run() override; |
| 546 void RunCompleted() override; | 552 void RunCompleted() override; |
| 547 | 553 |
| 548 protected: | 554 protected: |
| 549 ~GroupLoadTask() override {} | 555 ~GroupLoadTask() override {} |
| 550 | 556 |
| 551 private: | 557 private: |
| 552 GURL manifest_url_; | 558 GURL manifest_url_; |
| 553 bool success_; | 559 bool success_; |
| 554 }; | 560 }; |
| 555 | 561 |
| 556 void AppCacheStorageImpl::GroupLoadTask::Run() { | 562 void AppCacheStorageImpl::GroupLoadTask::Run() { |
| 563 tracked_objects::ScopedTracker tracking_profile( | |
| 564 FROM_HERE_WITH_EXPLICIT_FUNCTION("AppCacheStorageImpl::GroupLoadTask")); | |
| 557 success_ = | 565 success_ = |
| 558 database_->FindGroupForManifestUrl(manifest_url_, &group_record_) && | 566 database_->FindGroupForManifestUrl(manifest_url_, &group_record_) && |
| 559 database_->FindCacheForGroup(group_record_.group_id, &cache_record_) && | 567 database_->FindCacheForGroup(group_record_.group_id, &cache_record_) && |
| 560 FindRelatedCacheRecords(cache_record_.cache_id); | 568 FindRelatedCacheRecords(cache_record_.cache_id); |
| 561 | 569 |
| 562 if (success_) | 570 if (success_) |
| 563 database_->UpdateGroupLastAccessTime(group_record_.group_id, | 571 database_->LazyUpdateLastAccessTime(group_record_.group_id, |
| 564 base::Time::Now()); | 572 base::Time::Now()); |
| 565 } | 573 } |
| 566 | 574 |
| 567 void AppCacheStorageImpl::GroupLoadTask::RunCompleted() { | 575 void AppCacheStorageImpl::GroupLoadTask::RunCompleted() { |
| 568 storage_->pending_group_loads_.erase(manifest_url_); | 576 storage_->pending_group_loads_.erase(manifest_url_); |
| 569 scoped_refptr<AppCacheGroup> group; | 577 scoped_refptr<AppCacheGroup> group; |
| 570 scoped_refptr<AppCache> cache; | 578 scoped_refptr<AppCache> cache; |
| 571 if (!storage_->is_disabled()) { | 579 if (!storage_->is_disabled()) { |
| 572 if (success_) { | 580 if (success_) { |
| 581 storage_->LazilyCommitLastAccessTimes(); | |
| 573 DCHECK(group_record_.manifest_url == manifest_url_); | 582 DCHECK(group_record_.manifest_url == manifest_url_); |
| 574 CreateCacheAndGroupFromRecords(&cache, &group); | 583 CreateCacheAndGroupFromRecords(&cache, &group); |
| 575 } else { | 584 } else { |
| 576 group = storage_->working_set_.GetGroup(manifest_url_); | 585 group = storage_->working_set_.GetGroup(manifest_url_); |
| 577 if (!group.get()) { | 586 if (!group.get()) { |
| 578 group = | 587 group = |
| 579 new AppCacheGroup(storage_, manifest_url_, storage_->NewGroupId()); | 588 new AppCacheGroup(storage_, manifest_url_, storage_->NewGroupId()); |
| 580 } | 589 } |
| 581 } | 590 } |
| 582 } | 591 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 success_ = database_->FindGroup(group_record_.group_id, &existing_group); | 692 success_ = database_->FindGroup(group_record_.group_id, &existing_group); |
| 684 if (!success_) { | 693 if (!success_) { |
| 685 group_record_.creation_time = base::Time::Now(); | 694 group_record_.creation_time = base::Time::Now(); |
| 686 group_record_.last_access_time = base::Time::Now(); | 695 group_record_.last_access_time = base::Time::Now(); |
| 687 success_ = database_->InsertGroup(&group_record_); | 696 success_ = database_->InsertGroup(&group_record_); |
| 688 } else { | 697 } else { |
| 689 DCHECK(group_record_.group_id == existing_group.group_id); | 698 DCHECK(group_record_.group_id == existing_group.group_id); |
| 690 DCHECK(group_record_.manifest_url == existing_group.manifest_url); | 699 DCHECK(group_record_.manifest_url == existing_group.manifest_url); |
| 691 DCHECK(group_record_.origin == existing_group.origin); | 700 DCHECK(group_record_.origin == existing_group.origin); |
| 692 | 701 |
| 693 database_->UpdateGroupLastAccessTime(group_record_.group_id, | 702 database_->UpdateLastAccessTime(group_record_.group_id, |
| 694 base::Time::Now()); | 703 base::Time::Now()); |
| 695 | 704 |
| 696 AppCacheDatabase::CacheRecord cache; | 705 AppCacheDatabase::CacheRecord cache; |
| 697 if (database_->FindCacheForGroup(group_record_.group_id, &cache)) { | 706 if (database_->FindCacheForGroup(group_record_.group_id, &cache)) { |
| 698 // Get the set of response ids in the old cache. | 707 // Get the set of response ids in the old cache. |
| 699 std::set<int64> existing_response_ids; | 708 std::set<int64> existing_response_ids; |
| 700 database_->FindResponseIdsForCacheAsSet(cache.cache_id, | 709 database_->FindResponseIdsForCacheAsSet(cache.cache_id, |
| 701 &existing_response_ids); | 710 &existing_response_ids); |
| 702 | 711 |
| 703 // Remove those that remain in the new cache. | 712 // Remove those that remain in the new cache. |
| 704 std::vector<AppCacheDatabase::EntryRecord>::const_iterator entry_iter = | 713 std::vector<AppCacheDatabase::EntryRecord>::const_iterator entry_iter = |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 std::set<int64> cache_ids_in_use_; | 933 std::set<int64> cache_ids_in_use_; |
| 925 AppCacheEntry entry_; | 934 AppCacheEntry entry_; |
| 926 AppCacheEntry fallback_entry_; | 935 AppCacheEntry fallback_entry_; |
| 927 GURL namespace_entry_url_; | 936 GURL namespace_entry_url_; |
| 928 int64 cache_id_; | 937 int64 cache_id_; |
| 929 int64 group_id_; | 938 int64 group_id_; |
| 930 GURL manifest_url_; | 939 GURL manifest_url_; |
| 931 }; | 940 }; |
| 932 | 941 |
| 933 void AppCacheStorageImpl::FindMainResponseTask::Run() { | 942 void AppCacheStorageImpl::FindMainResponseTask::Run() { |
| 943 tracked_objects::ScopedTracker tracking_profile( | |
| 944 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 945 "AppCacheStorageImpl::FindMainResponseTask")); | |
| 934 // NOTE: The heuristics around choosing amoungst multiple candidates | 946 // NOTE: The heuristics around choosing amoungst multiple candidates |
| 935 // is underspecified, and just plain not fully understood. This needs | 947 // is underspecified, and just plain not fully understood. This needs |
| 936 // to be refined. | 948 // to be refined. |
| 937 | 949 |
| 938 // The 'preferred_manifest_url' is the url of the manifest associated | 950 // The 'preferred_manifest_url' is the url of the manifest associated |
| 939 // with the page that opened or embedded the page being loaded now. | 951 // with the page that opened or embedded the page being loaded now. |
| 940 // We have a strong preference to use resources from that cache. | 952 // We have a strong preference to use resources from that cache. |
| 941 // We also have a lesser bias to use resources from caches that are currently | 953 // We also have a lesser bias to use resources from caches that are currently |
| 942 // being used by other unrelated pages. | 954 // being used by other unrelated pages. |
| 943 // TODO(michaeln): come up with a 'preferred_manifest_url' in more cases | 955 // TODO(michaeln): come up with a 'preferred_manifest_url' in more cases |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 std::vector<int64> response_ids_; | 1291 std::vector<int64> response_ids_; |
| 1280 | 1292 |
| 1281 protected: | 1293 protected: |
| 1282 ~DeleteDeletableResponseIdsTask() override {} | 1294 ~DeleteDeletableResponseIdsTask() override {} |
| 1283 }; | 1295 }; |
| 1284 | 1296 |
| 1285 void AppCacheStorageImpl::DeleteDeletableResponseIdsTask::Run() { | 1297 void AppCacheStorageImpl::DeleteDeletableResponseIdsTask::Run() { |
| 1286 database_->DeleteDeletableResponseIds(response_ids_); | 1298 database_->DeleteDeletableResponseIds(response_ids_); |
| 1287 } | 1299 } |
| 1288 | 1300 |
| 1289 // UpdateGroupLastAccessTimeTask ------- | 1301 // LazyUpdateLastAccessTimeTask ------- |
| 1290 | 1302 |
| 1291 class AppCacheStorageImpl::UpdateGroupLastAccessTimeTask | 1303 class AppCacheStorageImpl::LazyUpdateLastAccessTimeTask |
| 1292 : public DatabaseTask { | 1304 : public DatabaseTask { |
| 1293 public: | 1305 public: |
| 1294 UpdateGroupLastAccessTimeTask( | 1306 LazyUpdateLastAccessTimeTask( |
| 1295 AppCacheStorageImpl* storage, AppCacheGroup* group, base::Time time) | 1307 AppCacheStorageImpl* storage, AppCacheGroup* group, base::Time time) |
| 1296 : DatabaseTask(storage), group_id_(group->group_id()), | 1308 : DatabaseTask(storage), group_id_(group->group_id()), |
| 1297 last_access_time_(time) { | 1309 last_access_time_(time) { |
| 1298 storage->NotifyStorageAccessed(group->manifest_url().GetOrigin()); | 1310 storage->NotifyStorageAccessed(group->manifest_url().GetOrigin()); |
| 1299 } | 1311 } |
| 1300 | 1312 |
| 1301 // DatabaseTask: | 1313 // DatabaseTask: |
| 1302 void Run() override; | 1314 void Run() override; |
| 1315 void RunCompleted() override; | |
| 1303 | 1316 |
| 1304 protected: | 1317 protected: |
| 1305 ~UpdateGroupLastAccessTimeTask() override {} | 1318 ~LazyUpdateLastAccessTimeTask() override {} |
| 1306 | 1319 |
| 1307 private: | 1320 private: |
| 1308 int64 group_id_; | 1321 int64 group_id_; |
| 1309 base::Time last_access_time_; | 1322 base::Time last_access_time_; |
| 1310 }; | 1323 }; |
| 1311 | 1324 |
| 1312 void AppCacheStorageImpl::UpdateGroupLastAccessTimeTask::Run() { | 1325 void AppCacheStorageImpl::LazyUpdateLastAccessTimeTask::Run() { |
| 1313 database_->UpdateGroupLastAccessTime(group_id_, last_access_time_); | 1326 tracked_objects::ScopedTracker tracking_profile( |
| 1327 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 1328 "AppCacheStorageImpl::LazyUpdateLastAccessTimeTask")); | |
| 1329 database_->LazyUpdateLastAccessTime(group_id_, last_access_time_); | |
| 1314 } | 1330 } |
| 1315 | 1331 |
| 1332 void AppCacheStorageImpl::LazyUpdateLastAccessTimeTask::RunCompleted() { | |
| 1333 storage_->LazilyCommitLastAccessTimes(); | |
| 1334 } | |
| 1335 | |
| 1336 // CommitLastAccessTimesTask ------- | |
| 1337 | |
| 1338 class AppCacheStorageImpl::CommitLastAccessTimesTask | |
| 1339 : public DatabaseTask { | |
| 1340 public: | |
| 1341 CommitLastAccessTimesTask(AppCacheStorageImpl* storage) | |
| 1342 : DatabaseTask(storage) {} | |
| 1343 | |
| 1344 // DatabaseTask: | |
| 1345 void Run() override { | |
| 1346 tracked_objects::ScopedTracker tracking_profile( | |
| 1347 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
| 1348 "AppCacheStorageImpl::CommitLastAccessTimesTask")); | |
| 1349 database_->CommitLazyLastAccessTimes(); | |
| 1350 } | |
| 1351 | |
| 1352 protected: | |
| 1353 ~CommitLastAccessTimesTask() override {} | |
| 1354 }; | |
| 1316 | 1355 |
| 1317 // AppCacheStorageImpl --------------------------------------------------- | 1356 // AppCacheStorageImpl --------------------------------------------------- |
| 1318 | 1357 |
| 1319 AppCacheStorageImpl::AppCacheStorageImpl(AppCacheServiceImpl* service) | 1358 AppCacheStorageImpl::AppCacheStorageImpl(AppCacheServiceImpl* service) |
| 1320 : AppCacheStorage(service), | 1359 : AppCacheStorage(service), |
| 1321 is_incognito_(false), | 1360 is_incognito_(false), |
| 1322 is_response_deletion_scheduled_(false), | 1361 is_response_deletion_scheduled_(false), |
| 1323 did_start_deleting_responses_(false), | 1362 did_start_deleting_responses_(false), |
| 1324 last_deletable_response_rowid_(0), | 1363 last_deletable_response_rowid_(0), |
| 1325 database_(NULL), | 1364 database_(NULL), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1393 if (is_disabled_) { | 1432 if (is_disabled_) { |
| 1394 delegate->OnCacheLoaded(NULL, id); | 1433 delegate->OnCacheLoaded(NULL, id); |
| 1395 return; | 1434 return; |
| 1396 } | 1435 } |
| 1397 | 1436 |
| 1398 AppCache* cache = working_set_.GetCache(id); | 1437 AppCache* cache = working_set_.GetCache(id); |
| 1399 if (cache) { | 1438 if (cache) { |
| 1400 delegate->OnCacheLoaded(cache, id); | 1439 delegate->OnCacheLoaded(cache, id); |
| 1401 if (cache->owning_group()) { | 1440 if (cache->owning_group()) { |
| 1402 scoped_refptr<DatabaseTask> update_task( | 1441 scoped_refptr<DatabaseTask> update_task( |
| 1403 new UpdateGroupLastAccessTimeTask( | 1442 new LazyUpdateLastAccessTimeTask( |
| 1404 this, cache->owning_group(), base::Time::Now())); | 1443 this, cache->owning_group(), base::Time::Now())); |
| 1405 update_task->Schedule(); | 1444 update_task->Schedule(); |
| 1406 } | 1445 } |
| 1407 return; | 1446 return; |
| 1408 } | 1447 } |
| 1409 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id)); | 1448 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id)); |
| 1410 if (task.get()) { | 1449 if (task.get()) { |
| 1411 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | 1450 task->AddDelegate(GetOrCreateDelegateReference(delegate)); |
| 1412 return; | 1451 return; |
| 1413 } | 1452 } |
| 1414 task = new CacheLoadTask(id, this); | 1453 task = new CacheLoadTask(id, this); |
| 1415 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | 1454 task->AddDelegate(GetOrCreateDelegateReference(delegate)); |
| 1416 task->Schedule(); | 1455 task->Schedule(); |
| 1417 pending_cache_loads_[id] = task.get(); | 1456 pending_cache_loads_[id] = task.get(); |
| 1418 } | 1457 } |
| 1419 | 1458 |
| 1420 void AppCacheStorageImpl::LoadOrCreateGroup( | 1459 void AppCacheStorageImpl::LoadOrCreateGroup( |
| 1421 const GURL& manifest_url, Delegate* delegate) { | 1460 const GURL& manifest_url, Delegate* delegate) { |
| 1422 DCHECK(delegate); | 1461 DCHECK(delegate); |
| 1423 if (is_disabled_) { | 1462 if (is_disabled_) { |
| 1424 delegate->OnGroupLoaded(NULL, manifest_url); | 1463 delegate->OnGroupLoaded(NULL, manifest_url); |
| 1425 return; | 1464 return; |
| 1426 } | 1465 } |
| 1427 | 1466 |
| 1428 AppCacheGroup* group = working_set_.GetGroup(manifest_url); | 1467 AppCacheGroup* group = working_set_.GetGroup(manifest_url); |
| 1429 if (group) { | 1468 if (group) { |
| 1430 delegate->OnGroupLoaded(group, manifest_url); | 1469 delegate->OnGroupLoaded(group, manifest_url); |
| 1431 scoped_refptr<DatabaseTask> update_task( | 1470 scoped_refptr<DatabaseTask> update_task( |
| 1432 new UpdateGroupLastAccessTimeTask( | 1471 new LazyUpdateLastAccessTimeTask( |
| 1433 this, group, base::Time::Now())); | 1472 this, group, base::Time::Now())); |
| 1434 update_task->Schedule(); | 1473 update_task->Schedule(); |
| 1435 return; | 1474 return; |
| 1436 } | 1475 } |
| 1437 | 1476 |
| 1438 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url)); | 1477 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url)); |
| 1439 if (task.get()) { | 1478 if (task.get()) { |
| 1440 task->AddDelegate(GetOrCreateDelegateReference(delegate)); | 1479 task->AddDelegate(GetOrCreateDelegateReference(delegate)); |
| 1441 return; | 1480 return; |
| 1442 } | 1481 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1684 did_start_deleting_responses_ = true; | 1723 did_start_deleting_responses_ = true; |
| 1685 deletable_response_ids_.insert( | 1724 deletable_response_ids_.insert( |
| 1686 deletable_response_ids_.end(), | 1725 deletable_response_ids_.end(), |
| 1687 response_ids.begin(), response_ids.end()); | 1726 response_ids.begin(), response_ids.end()); |
| 1688 if (!is_response_deletion_scheduled_) | 1727 if (!is_response_deletion_scheduled_) |
| 1689 ScheduleDeleteOneResponse(); | 1728 ScheduleDeleteOneResponse(); |
| 1690 } | 1729 } |
| 1691 | 1730 |
| 1692 void AppCacheStorageImpl::ScheduleDeleteOneResponse() { | 1731 void AppCacheStorageImpl::ScheduleDeleteOneResponse() { |
| 1693 DCHECK(!is_response_deletion_scheduled_); | 1732 DCHECK(!is_response_deletion_scheduled_); |
| 1694 const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); | 1733 const base::TimeDelta kBriefDelay = base::TimeDelta::FromMilliseconds(10); |
| 1695 base::MessageLoop::current()->PostDelayedTask( | 1734 base::MessageLoop::current()->PostDelayedTask( |
| 1696 FROM_HERE, | 1735 FROM_HERE, |
| 1697 base::Bind(&AppCacheStorageImpl::DeleteOneResponse, | 1736 base::Bind(&AppCacheStorageImpl::DeleteOneResponse, |
| 1698 weak_factory_.GetWeakPtr()), | 1737 weak_factory_.GetWeakPtr()), |
| 1699 kDelay); | 1738 kBriefDelay); |
| 1700 is_response_deletion_scheduled_ = true; | 1739 is_response_deletion_scheduled_ = true; |
| 1701 } | 1740 } |
| 1702 | 1741 |
| 1703 void AppCacheStorageImpl::DeleteOneResponse() { | 1742 void AppCacheStorageImpl::DeleteOneResponse() { |
| 1704 DCHECK(is_response_deletion_scheduled_); | 1743 DCHECK(is_response_deletion_scheduled_); |
| 1705 DCHECK(!deletable_response_ids_.empty()); | 1744 DCHECK(!deletable_response_ids_.empty()); |
| 1706 | 1745 |
| 1707 if (!disk_cache()) { | 1746 if (!disk_cache()) { |
| 1708 DCHECK(is_disabled_); | 1747 DCHECK(is_disabled_); |
| 1709 deletable_response_ids_.clear(); | 1748 deletable_response_ids_.clear(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1856 base::Bind(base::IgnoreResult(&base::DeleteFile), cache_directory_, true), | 1895 base::Bind(base::IgnoreResult(&base::DeleteFile), cache_directory_, true), |
| 1857 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, | 1896 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, |
| 1858 weak_factory_.GetWeakPtr())); | 1897 weak_factory_.GetWeakPtr())); |
| 1859 } | 1898 } |
| 1860 | 1899 |
| 1861 void AppCacheStorageImpl::CallScheduleReinitialize() { | 1900 void AppCacheStorageImpl::CallScheduleReinitialize() { |
| 1862 service_->ScheduleReinitialize(); | 1901 service_->ScheduleReinitialize(); |
| 1863 // note: 'this' may be deleted at this point. | 1902 // note: 'this' may be deleted at this point. |
| 1864 } | 1903 } |
| 1865 | 1904 |
| 1905 void AppCacheStorageImpl::LazilyCommitLastAccessTimes() { | |
| 1906 if (lazy_commit_timer_.IsRunning()) | |
| 1907 return; | |
| 1908 const base::TimeDelta kDelay = base::TimeDelta::FromMinutes(5); | |
| 1909 lazy_commit_timer_.Start( | |
| 1910 FROM_HERE, kDelay, | |
| 1911 base::Bind(&AppCacheStorageImpl::OnCommitLastAccessTimes, | |
| 1912 weak_factory_.GetWeakPtr())); | |
| 1913 } | |
| 1914 | |
| 1915 void AppCacheStorageImpl::OnCommitLastAccessTimes() { | |
|
dmurph
2015/02/20 00:04:45
This sounds like 'commit last action times' alread
michaeln
2015/02/20 20:24:39
Done.
| |
| 1916 lazy_commit_timer_.Stop(); | |
| 1917 if (is_disabled()) | |
| 1918 return; | |
| 1919 scoped_refptr<DatabaseTask> task(new CommitLastAccessTimesTask(this)); | |
| 1920 task->Schedule(); | |
| 1921 } | |
| 1922 | |
| 1866 } // namespace content | 1923 } // namespace content |
| OLD | NEW |