Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: content/browser/appcache/appcache_storage_impl.cc

Issue 924723002: [appcache] Don't write during startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/appcache/appcache_storage_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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
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
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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 did_start_deleting_responses_ = true; 1730 did_start_deleting_responses_ = true;
1692 deletable_response_ids_.insert( 1731 deletable_response_ids_.insert(
1693 deletable_response_ids_.end(), 1732 deletable_response_ids_.end(),
1694 response_ids.begin(), response_ids.end()); 1733 response_ids.begin(), response_ids.end());
1695 if (!is_response_deletion_scheduled_) 1734 if (!is_response_deletion_scheduled_)
1696 ScheduleDeleteOneResponse(); 1735 ScheduleDeleteOneResponse();
1697 } 1736 }
1698 1737
1699 void AppCacheStorageImpl::ScheduleDeleteOneResponse() { 1738 void AppCacheStorageImpl::ScheduleDeleteOneResponse() {
1700 DCHECK(!is_response_deletion_scheduled_); 1739 DCHECK(!is_response_deletion_scheduled_);
1701 const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); 1740 const base::TimeDelta kBriefDelay = base::TimeDelta::FromMilliseconds(10);
1702 base::MessageLoop::current()->PostDelayedTask( 1741 base::MessageLoop::current()->PostDelayedTask(
1703 FROM_HERE, 1742 FROM_HERE,
1704 base::Bind(&AppCacheStorageImpl::DeleteOneResponse, 1743 base::Bind(&AppCacheStorageImpl::DeleteOneResponse,
1705 weak_factory_.GetWeakPtr()), 1744 weak_factory_.GetWeakPtr()),
1706 kDelay); 1745 kBriefDelay);
1707 is_response_deletion_scheduled_ = true; 1746 is_response_deletion_scheduled_ = true;
1708 } 1747 }
1709 1748
1710 void AppCacheStorageImpl::DeleteOneResponse() { 1749 void AppCacheStorageImpl::DeleteOneResponse() {
1711 DCHECK(is_response_deletion_scheduled_); 1750 DCHECK(is_response_deletion_scheduled_);
1712 DCHECK(!deletable_response_ids_.empty()); 1751 DCHECK(!deletable_response_ids_.empty());
1713 1752
1714 if (!disk_cache()) { 1753 if (!disk_cache()) {
1715 DCHECK(is_disabled_); 1754 DCHECK(is_disabled_);
1716 deletable_response_ids_.clear(); 1755 deletable_response_ids_.clear();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 base::Bind(base::IgnoreResult(&base::DeleteFile), cache_directory_, true), 1902 base::Bind(base::IgnoreResult(&base::DeleteFile), cache_directory_, true),
1864 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, 1903 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize,
1865 weak_factory_.GetWeakPtr())); 1904 weak_factory_.GetWeakPtr()));
1866 } 1905 }
1867 1906
1868 void AppCacheStorageImpl::CallScheduleReinitialize() { 1907 void AppCacheStorageImpl::CallScheduleReinitialize() {
1869 service_->ScheduleReinitialize(); 1908 service_->ScheduleReinitialize();
1870 // note: 'this' may be deleted at this point. 1909 // note: 'this' may be deleted at this point.
1871 } 1910 }
1872 1911
1912 void AppCacheStorageImpl::LazilyCommitLastAccessTimes() {
1913 if (lazy_commit_timer_.IsRunning())
1914 return;
1915 const base::TimeDelta kDelay = base::TimeDelta::FromMinutes(5);
1916 lazy_commit_timer_.Start(
1917 FROM_HERE, kDelay,
1918 base::Bind(&AppCacheStorageImpl::OnLazyCommitTimer,
1919 weak_factory_.GetWeakPtr()));
1920 }
1921
1922 void AppCacheStorageImpl::OnLazyCommitTimer() {
1923 lazy_commit_timer_.Stop();
1924 if (is_disabled())
1925 return;
1926 scoped_refptr<DatabaseTask> task(new CommitLastAccessTimesTask(this));
1927 task->Schedule();
1928 }
1929
1873 } // namespace content 1930 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_storage_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698