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

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 }
298 301
299 database_->FindLastStorageIds( 302 database_->FindLastStorageIds(
300 &last_group_id_, &last_cache_id_, &last_response_id_, 303 &last_group_id_, &last_cache_id_, &last_response_id_,
301 &last_deletable_response_rowid_); 304 &last_deletable_response_rowid_);
302 database_->GetAllOriginUsage(&usage_map_); 305 database_->GetAllOriginUsage(&usage_map_);
303 } 306 }
304 307
305 void AppCacheStorageImpl::InitTask::RunCompleted() { 308 void AppCacheStorageImpl::InitTask::RunCompleted() {
306 storage_->last_group_id_ = last_group_id_; 309 storage_->last_group_id_ = last_group_id_;
307 storage_->last_cache_id_ = last_cache_id_; 310 storage_->last_cache_id_ = last_cache_id_;
308 storage_->last_response_id_ = last_response_id_; 311 storage_->last_response_id_ = last_response_id_;
309 storage_->last_deletable_response_rowid_ = last_deletable_response_rowid_; 312 storage_->last_deletable_response_rowid_ = last_deletable_response_rowid_;
310 313
311 if (!storage_->is_disabled()) { 314 if (!storage_->is_disabled()) {
312 storage_->usage_map_.swap(usage_map_); 315 storage_->usage_map_.swap(usage_map_);
313 const base::TimeDelta kDelay = base::TimeDelta::FromMinutes(5); 316 const base::TimeDelta k5Minutes = base::TimeDelta::FromMinutes(5);
cmumford 2015/02/17 19:26:39 My preference would be to have a name that describ
michaeln 2015/02/17 19:46:26 Done.
314 base::MessageLoop::current()->PostDelayedTask( 317 base::MessageLoop::current()->PostDelayedTask(
315 FROM_HERE, 318 FROM_HERE,
316 base::Bind(&AppCacheStorageImpl::DelayedStartDeletingUnusedResponses, 319 base::Bind(&AppCacheStorageImpl::DelayedStartDeletingUnusedResponses,
317 storage_->weak_factory_.GetWeakPtr()), 320 storage_->weak_factory_.GetWeakPtr()),
318 kDelay); 321 k5Minutes);
319 } 322 }
320 323
321 if (storage_->service()->quota_client()) 324 if (storage_->service()->quota_client())
322 storage_->service()->quota_client()->NotifyAppCacheReady(); 325 storage_->service()->quota_client()->NotifyAppCacheReady();
323 } 326 }
324 327
325 // DisableDatabaseTask ------- 328 // DisableDatabaseTask -------
326 329
327 class AppCacheStorageImpl::DisableDatabaseTask : public DatabaseTask { 330 class AppCacheStorageImpl::DisableDatabaseTask : public DatabaseTask {
328 public: 331 public:
(...skipping 21 matching lines...) Expand all
350 void RunCompleted() override; 353 void RunCompleted() override;
351 354
352 protected: 355 protected:
353 ~GetAllInfoTask() override {} 356 ~GetAllInfoTask() override {}
354 357
355 private: 358 private:
356 scoped_refptr<AppCacheInfoCollection> info_collection_; 359 scoped_refptr<AppCacheInfoCollection> info_collection_;
357 }; 360 };
358 361
359 void AppCacheStorageImpl::GetAllInfoTask::Run() { 362 void AppCacheStorageImpl::GetAllInfoTask::Run() {
363 tracked_objects::ScopedTracker tracking_profile(
364 FROM_HERE_WITH_EXPLICIT_FUNCTION("AppCacheStorageImpl::GetAllInfoTask"));
360 std::set<GURL> origins; 365 std::set<GURL> origins;
361 database_->FindOriginsWithGroups(&origins); 366 database_->FindOriginsWithGroups(&origins);
362 for (std::set<GURL>::const_iterator origin = origins.begin(); 367 for (std::set<GURL>::const_iterator origin = origins.begin();
363 origin != origins.end(); ++origin) { 368 origin != origins.end(); ++origin) {
364 AppCacheInfoVector& infos = 369 AppCacheInfoVector& infos =
365 info_collection_->infos_by_origin[*origin]; 370 info_collection_->infos_by_origin[*origin];
366 std::vector<AppCacheDatabase::GroupRecord> groups; 371 std::vector<AppCacheDatabase::GroupRecord> groups;
367 database_->FindGroupsForOrigin(*origin, &groups); 372 database_->FindGroupsForOrigin(*origin, &groups);
368 for (std::vector<AppCacheDatabase::GroupRecord>::const_iterator 373 for (std::vector<AppCacheDatabase::GroupRecord>::const_iterator
369 group = groups.begin(); 374 group = groups.begin();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 510
506 protected: 511 protected:
507 ~CacheLoadTask() override {} 512 ~CacheLoadTask() override {}
508 513
509 private: 514 private:
510 int64 cache_id_; 515 int64 cache_id_;
511 bool success_; 516 bool success_;
512 }; 517 };
513 518
514 void AppCacheStorageImpl::CacheLoadTask::Run() { 519 void AppCacheStorageImpl::CacheLoadTask::Run() {
520 tracked_objects::ScopedTracker tracking_profile(
521 FROM_HERE_WITH_EXPLICIT_FUNCTION("AppCacheStorageImpl::CacheLoadTask"));
515 success_ = 522 success_ =
516 database_->FindCache(cache_id_, &cache_record_) && 523 database_->FindCache(cache_id_, &cache_record_) &&
517 database_->FindGroup(cache_record_.group_id, &group_record_) && 524 database_->FindGroup(cache_record_.group_id, &group_record_) &&
518 FindRelatedCacheRecords(cache_id_); 525 FindRelatedCacheRecords(cache_id_);
519 526
520 if (success_) 527 if (success_)
521 database_->UpdateGroupLastAccessTime(group_record_.group_id, 528 database_->LazyUpdateLastAccessTime(group_record_.group_id,
522 base::Time::Now()); 529 base::Time::Now());
523 } 530 }
524 531
525 void AppCacheStorageImpl::CacheLoadTask::RunCompleted() { 532 void AppCacheStorageImpl::CacheLoadTask::RunCompleted() {
526 storage_->pending_cache_loads_.erase(cache_id_); 533 storage_->pending_cache_loads_.erase(cache_id_);
527 scoped_refptr<AppCache> cache; 534 scoped_refptr<AppCache> cache;
528 scoped_refptr<AppCacheGroup> group; 535 scoped_refptr<AppCacheGroup> group;
529 if (success_ && !storage_->is_disabled()) { 536 if (success_ && !storage_->is_disabled()) {
537 storage_->LazilyCommitLastAccessTimes();
530 DCHECK(cache_record_.cache_id == cache_id_); 538 DCHECK(cache_record_.cache_id == cache_id_);
531 CreateCacheAndGroupFromRecords(&cache, &group); 539 CreateCacheAndGroupFromRecords(&cache, &group);
532 } 540 }
533 FOR_EACH_DELEGATE(delegates_, OnCacheLoaded(cache.get(), cache_id_)); 541 FOR_EACH_DELEGATE(delegates_, OnCacheLoaded(cache.get(), cache_id_));
534 } 542 }
535 543
536 // GroupLoadTask ------- 544 // GroupLoadTask -------
537 545
538 class AppCacheStorageImpl::GroupLoadTask : public StoreOrLoadTask { 546 class AppCacheStorageImpl::GroupLoadTask : public StoreOrLoadTask {
539 public: 547 public:
540 GroupLoadTask(GURL manifest_url, AppCacheStorageImpl* storage) 548 GroupLoadTask(GURL manifest_url, AppCacheStorageImpl* storage)
541 : StoreOrLoadTask(storage), manifest_url_(manifest_url), 549 : StoreOrLoadTask(storage), manifest_url_(manifest_url),
542 success_(false) {} 550 success_(false) {}
543 551
544 // DatabaseTask: 552 // DatabaseTask:
545 void Run() override; 553 void Run() override;
546 void RunCompleted() override; 554 void RunCompleted() override;
547 555
548 protected: 556 protected:
549 ~GroupLoadTask() override {} 557 ~GroupLoadTask() override {}
550 558
551 private: 559 private:
552 GURL manifest_url_; 560 GURL manifest_url_;
553 bool success_; 561 bool success_;
554 }; 562 };
555 563
556 void AppCacheStorageImpl::GroupLoadTask::Run() { 564 void AppCacheStorageImpl::GroupLoadTask::Run() {
565 tracked_objects::ScopedTracker tracking_profile(
566 FROM_HERE_WITH_EXPLICIT_FUNCTION("AppCacheStorageImpl::GroupLoadTask"));
557 success_ = 567 success_ =
558 database_->FindGroupForManifestUrl(manifest_url_, &group_record_) && 568 database_->FindGroupForManifestUrl(manifest_url_, &group_record_) &&
559 database_->FindCacheForGroup(group_record_.group_id, &cache_record_) && 569 database_->FindCacheForGroup(group_record_.group_id, &cache_record_) &&
560 FindRelatedCacheRecords(cache_record_.cache_id); 570 FindRelatedCacheRecords(cache_record_.cache_id);
561 571
562 if (success_) 572 if (success_)
563 database_->UpdateGroupLastAccessTime(group_record_.group_id, 573 database_->LazyUpdateLastAccessTime(group_record_.group_id,
564 base::Time::Now()); 574 base::Time::Now());
565 } 575 }
566 576
567 void AppCacheStorageImpl::GroupLoadTask::RunCompleted() { 577 void AppCacheStorageImpl::GroupLoadTask::RunCompleted() {
568 storage_->pending_group_loads_.erase(manifest_url_); 578 storage_->pending_group_loads_.erase(manifest_url_);
569 scoped_refptr<AppCacheGroup> group; 579 scoped_refptr<AppCacheGroup> group;
570 scoped_refptr<AppCache> cache; 580 scoped_refptr<AppCache> cache;
571 if (!storage_->is_disabled()) { 581 if (!storage_->is_disabled()) {
572 if (success_) { 582 if (success_) {
583 storage_->LazilyCommitLastAccessTimes();
573 DCHECK(group_record_.manifest_url == manifest_url_); 584 DCHECK(group_record_.manifest_url == manifest_url_);
574 CreateCacheAndGroupFromRecords(&cache, &group); 585 CreateCacheAndGroupFromRecords(&cache, &group);
575 } else { 586 } else {
576 group = storage_->working_set_.GetGroup(manifest_url_); 587 group = storage_->working_set_.GetGroup(manifest_url_);
577 if (!group.get()) { 588 if (!group.get()) {
578 group = 589 group =
579 new AppCacheGroup(storage_, manifest_url_, storage_->NewGroupId()); 590 new AppCacheGroup(storage_, manifest_url_, storage_->NewGroupId());
580 } 591 }
581 } 592 }
582 } 593 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 if (status == storage::kQuotaStatusOk) 672 if (status == storage::kQuotaStatusOk)
662 space_available_ = std::max(static_cast<int64>(0), quota - usage); 673 space_available_ = std::max(static_cast<int64>(0), quota - usage);
663 else 674 else
664 space_available_ = 0; 675 space_available_ = 0;
665 storage_->pending_quota_queries_.erase(this); 676 storage_->pending_quota_queries_.erase(this);
666 Schedule(); 677 Schedule();
667 } 678 }
668 } 679 }
669 680
670 void AppCacheStorageImpl::StoreGroupAndCacheTask::Run() { 681 void AppCacheStorageImpl::StoreGroupAndCacheTask::Run() {
682 tracked_objects::ScopedTracker tracking_profile(
683 FROM_HERE_WITH_EXPLICIT_FUNCTION(
684 "AppCacheStorageImpl::StoreGroupAndCacheTask"));
671 DCHECK(!success_); 685 DCHECK(!success_);
672 sql::Connection* connection = database_->db_connection(); 686 sql::Connection* connection = database_->db_connection();
673 if (!connection) 687 if (!connection)
674 return; 688 return;
675 689
676 sql::Transaction transaction(connection); 690 sql::Transaction transaction(connection);
677 if (!transaction.Begin()) 691 if (!transaction.Begin())
678 return; 692 return;
679 693
680 int64 old_origin_usage = database_->GetOriginUsage(group_record_.origin); 694 int64 old_origin_usage = database_->GetOriginUsage(group_record_.origin);
681 695
682 AppCacheDatabase::GroupRecord existing_group; 696 AppCacheDatabase::GroupRecord existing_group;
683 success_ = database_->FindGroup(group_record_.group_id, &existing_group); 697 success_ = database_->FindGroup(group_record_.group_id, &existing_group);
684 if (!success_) { 698 if (!success_) {
685 group_record_.creation_time = base::Time::Now(); 699 group_record_.creation_time = base::Time::Now();
686 group_record_.last_access_time = base::Time::Now(); 700 group_record_.last_access_time = base::Time::Now();
687 success_ = database_->InsertGroup(&group_record_); 701 success_ = database_->InsertGroup(&group_record_);
688 } else { 702 } else {
689 DCHECK(group_record_.group_id == existing_group.group_id); 703 DCHECK(group_record_.group_id == existing_group.group_id);
690 DCHECK(group_record_.manifest_url == existing_group.manifest_url); 704 DCHECK(group_record_.manifest_url == existing_group.manifest_url);
691 DCHECK(group_record_.origin == existing_group.origin); 705 DCHECK(group_record_.origin == existing_group.origin);
692 706
693 database_->UpdateGroupLastAccessTime(group_record_.group_id, 707 database_->UpdateLastAccessTime(group_record_.group_id,
694 base::Time::Now()); 708 base::Time::Now());
695 709
696 AppCacheDatabase::CacheRecord cache; 710 AppCacheDatabase::CacheRecord cache;
697 if (database_->FindCacheForGroup(group_record_.group_id, &cache)) { 711 if (database_->FindCacheForGroup(group_record_.group_id, &cache)) {
698 // Get the set of response ids in the old cache. 712 // Get the set of response ids in the old cache.
699 std::set<int64> existing_response_ids; 713 std::set<int64> existing_response_ids;
700 database_->FindResponseIdsForCacheAsSet(cache.cache_id, 714 database_->FindResponseIdsForCacheAsSet(cache.cache_id,
701 &existing_response_ids); 715 &existing_response_ids);
702 716
703 // Remove those that remain in the new cache. 717 // Remove those that remain in the new cache.
704 std::vector<AppCacheDatabase::EntryRecord>::const_iterator entry_iter = 718 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_; 938 std::set<int64> cache_ids_in_use_;
925 AppCacheEntry entry_; 939 AppCacheEntry entry_;
926 AppCacheEntry fallback_entry_; 940 AppCacheEntry fallback_entry_;
927 GURL namespace_entry_url_; 941 GURL namespace_entry_url_;
928 int64 cache_id_; 942 int64 cache_id_;
929 int64 group_id_; 943 int64 group_id_;
930 GURL manifest_url_; 944 GURL manifest_url_;
931 }; 945 };
932 946
933 void AppCacheStorageImpl::FindMainResponseTask::Run() { 947 void AppCacheStorageImpl::FindMainResponseTask::Run() {
948 tracked_objects::ScopedTracker tracking_profile(
949 FROM_HERE_WITH_EXPLICIT_FUNCTION(
950 "AppCacheStorageImpl::FindMainResponseTask"));
934 // NOTE: The heuristics around choosing amoungst multiple candidates 951 // NOTE: The heuristics around choosing amoungst multiple candidates
935 // is underspecified, and just plain not fully understood. This needs 952 // is underspecified, and just plain not fully understood. This needs
936 // to be refined. 953 // to be refined.
937 954
938 // The 'preferred_manifest_url' is the url of the manifest associated 955 // The 'preferred_manifest_url' is the url of the manifest associated
939 // with the page that opened or embedded the page being loaded now. 956 // with the page that opened or embedded the page being loaded now.
940 // We have a strong preference to use resources from that cache. 957 // 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 958 // We also have a lesser bias to use resources from caches that are currently
942 // being used by other unrelated pages. 959 // being used by other unrelated pages.
943 // TODO(michaeln): come up with a 'preferred_manifest_url' in more cases 960 // TODO(michaeln): come up with a 'preferred_manifest_url' in more cases
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 1124
1108 protected: 1125 protected:
1109 ~MarkEntryAsForeignTask() override {} 1126 ~MarkEntryAsForeignTask() override {}
1110 1127
1111 private: 1128 private:
1112 int64 cache_id_; 1129 int64 cache_id_;
1113 GURL entry_url_; 1130 GURL entry_url_;
1114 }; 1131 };
1115 1132
1116 void AppCacheStorageImpl::MarkEntryAsForeignTask::Run() { 1133 void AppCacheStorageImpl::MarkEntryAsForeignTask::Run() {
1134 tracked_objects::ScopedTracker tracking_profile(
1135 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1136 "AppCacheStorageImpl::MarkEntryAsForeignTask"));
1117 database_->AddEntryFlags(entry_url_, cache_id_, AppCacheEntry::FOREIGN); 1137 database_->AddEntryFlags(entry_url_, cache_id_, AppCacheEntry::FOREIGN);
1118 } 1138 }
1119 1139
1120 void AppCacheStorageImpl::MarkEntryAsForeignTask::RunCompleted() { 1140 void AppCacheStorageImpl::MarkEntryAsForeignTask::RunCompleted() {
1121 DCHECK(storage_->pending_foreign_markings_.front().first == entry_url_ && 1141 DCHECK(storage_->pending_foreign_markings_.front().first == entry_url_ &&
1122 storage_->pending_foreign_markings_.front().second == cache_id_); 1142 storage_->pending_foreign_markings_.front().second == cache_id_);
1123 storage_->pending_foreign_markings_.pop_front(); 1143 storage_->pending_foreign_markings_.pop_front();
1124 } 1144 }
1125 1145
1126 // MakeGroupObsoleteTask ------- 1146 // MakeGroupObsoleteTask -------
(...skipping 28 matching lines...) Expand all
1155 int response_code) 1175 int response_code)
1156 : DatabaseTask(storage), 1176 : DatabaseTask(storage),
1157 group_(group), 1177 group_(group),
1158 group_id_(group->group_id()), 1178 group_id_(group->group_id()),
1159 origin_(group->manifest_url().GetOrigin()), 1179 origin_(group->manifest_url().GetOrigin()),
1160 success_(false), 1180 success_(false),
1161 response_code_(response_code), 1181 response_code_(response_code),
1162 new_origin_usage_(-1) {} 1182 new_origin_usage_(-1) {}
1163 1183
1164 void AppCacheStorageImpl::MakeGroupObsoleteTask::Run() { 1184 void AppCacheStorageImpl::MakeGroupObsoleteTask::Run() {
1185 tracked_objects::ScopedTracker tracking_profile(
1186 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1187 "AppCacheStorageImpl::MakeGroupObsoleteTask"));
1165 DCHECK(!success_); 1188 DCHECK(!success_);
1166 sql::Connection* connection = database_->db_connection(); 1189 sql::Connection* connection = database_->db_connection();
1167 if (!connection) 1190 if (!connection)
1168 return; 1191 return;
1169 1192
1170 sql::Transaction transaction(connection); 1193 sql::Transaction transaction(connection);
1171 if (!transaction.Begin()) 1194 if (!transaction.Begin())
1172 return; 1195 return;
1173 1196
1174 AppCacheDatabase::GroupRecord group_record; 1197 AppCacheDatabase::GroupRecord group_record;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 1249
1227 protected: 1250 protected:
1228 ~GetDeletableResponseIdsTask() override {} 1251 ~GetDeletableResponseIdsTask() override {}
1229 1252
1230 private: 1253 private:
1231 int64 max_rowid_; 1254 int64 max_rowid_;
1232 std::vector<int64> response_ids_; 1255 std::vector<int64> response_ids_;
1233 }; 1256 };
1234 1257
1235 void AppCacheStorageImpl::GetDeletableResponseIdsTask::Run() { 1258 void AppCacheStorageImpl::GetDeletableResponseIdsTask::Run() {
1259 tracked_objects::ScopedTracker tracking_profile(
1260 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1261 "AppCacheStorageImpl::GetDeletableResponseIdsTask"));
1236 const int kSqlLimit = 1000; 1262 const int kSqlLimit = 1000;
1237 database_->GetDeletableResponseIds(&response_ids_, max_rowid_, kSqlLimit); 1263 database_->GetDeletableResponseIds(&response_ids_, max_rowid_, kSqlLimit);
1238 // TODO(michaeln): retrieve group_ids too 1264 // TODO(michaeln): retrieve group_ids too
1239 } 1265 }
1240 1266
1241 void AppCacheStorageImpl::GetDeletableResponseIdsTask::RunCompleted() { 1267 void AppCacheStorageImpl::GetDeletableResponseIdsTask::RunCompleted() {
1242 if (!response_ids_.empty()) 1268 if (!response_ids_.empty())
1243 storage_->StartDeletingResponses(response_ids_); 1269 storage_->StartDeletingResponses(response_ids_);
1244 } 1270 }
1245 1271
1246 // InsertDeletableResponseIdsTask ------- 1272 // InsertDeletableResponseIdsTask -------
1247 1273
1248 class AppCacheStorageImpl::InsertDeletableResponseIdsTask 1274 class AppCacheStorageImpl::InsertDeletableResponseIdsTask
1249 : public DatabaseTask { 1275 : public DatabaseTask {
1250 public: 1276 public:
1251 explicit InsertDeletableResponseIdsTask(AppCacheStorageImpl* storage) 1277 explicit InsertDeletableResponseIdsTask(AppCacheStorageImpl* storage)
1252 : DatabaseTask(storage) {} 1278 : DatabaseTask(storage) {}
1253 1279
1254 // DatabaseTask: 1280 // DatabaseTask:
1255 void Run() override; 1281 void Run() override;
1256 1282
1257 std::vector<int64> response_ids_; 1283 std::vector<int64> response_ids_;
1258 1284
1259 protected: 1285 protected:
1260 ~InsertDeletableResponseIdsTask() override {} 1286 ~InsertDeletableResponseIdsTask() override {}
1261 }; 1287 };
1262 1288
1263 void AppCacheStorageImpl::InsertDeletableResponseIdsTask::Run() { 1289 void AppCacheStorageImpl::InsertDeletableResponseIdsTask::Run() {
1290 tracked_objects::ScopedTracker tracking_profile(
1291 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1292 "AppCacheStorageImpl::InsertDeletableResponseIdsTask"));
1264 database_->InsertDeletableResponseIds(response_ids_); 1293 database_->InsertDeletableResponseIds(response_ids_);
1265 // TODO(michaeln): store group_ids too 1294 // TODO(michaeln): store group_ids too
1266 } 1295 }
1267 1296
1268 // DeleteDeletableResponseIdsTask ------- 1297 // DeleteDeletableResponseIdsTask -------
1269 1298
1270 class AppCacheStorageImpl::DeleteDeletableResponseIdsTask 1299 class AppCacheStorageImpl::DeleteDeletableResponseIdsTask
1271 : public DatabaseTask { 1300 : public DatabaseTask {
1272 public: 1301 public:
1273 explicit DeleteDeletableResponseIdsTask(AppCacheStorageImpl* storage) 1302 explicit DeleteDeletableResponseIdsTask(AppCacheStorageImpl* storage)
1274 : DatabaseTask(storage) {} 1303 : DatabaseTask(storage) {}
1275 1304
1276 // DatabaseTask: 1305 // DatabaseTask:
1277 void Run() override; 1306 void Run() override;
1278 1307
1279 std::vector<int64> response_ids_; 1308 std::vector<int64> response_ids_;
1280 1309
1281 protected: 1310 protected:
1282 ~DeleteDeletableResponseIdsTask() override {} 1311 ~DeleteDeletableResponseIdsTask() override {}
1283 }; 1312 };
1284 1313
1285 void AppCacheStorageImpl::DeleteDeletableResponseIdsTask::Run() { 1314 void AppCacheStorageImpl::DeleteDeletableResponseIdsTask::Run() {
1315 tracked_objects::ScopedTracker tracking_profile(
1316 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1317 "AppCacheStorageImpl::DeleteDeletableResponseIdsTask"));
1286 database_->DeleteDeletableResponseIds(response_ids_); 1318 database_->DeleteDeletableResponseIds(response_ids_);
1287 } 1319 }
1288 1320
1289 // UpdateGroupLastAccessTimeTask ------- 1321 // LazyUpdateLastAccessTimeTask -------
1290 1322
1291 class AppCacheStorageImpl::UpdateGroupLastAccessTimeTask 1323 class AppCacheStorageImpl::LazyUpdateLastAccessTimeTask
1292 : public DatabaseTask { 1324 : public DatabaseTask {
1293 public: 1325 public:
1294 UpdateGroupLastAccessTimeTask( 1326 LazyUpdateLastAccessTimeTask(
1295 AppCacheStorageImpl* storage, AppCacheGroup* group, base::Time time) 1327 AppCacheStorageImpl* storage, AppCacheGroup* group, base::Time time)
1296 : DatabaseTask(storage), group_id_(group->group_id()), 1328 : DatabaseTask(storage), group_id_(group->group_id()),
1297 last_access_time_(time) { 1329 last_access_time_(time) {
1298 storage->NotifyStorageAccessed(group->manifest_url().GetOrigin()); 1330 storage->NotifyStorageAccessed(group->manifest_url().GetOrigin());
1299 } 1331 }
1300 1332
1301 // DatabaseTask: 1333 // DatabaseTask:
1302 void Run() override; 1334 void Run() override;
1335 void RunCompleted() override;
1303 1336
1304 protected: 1337 protected:
1305 ~UpdateGroupLastAccessTimeTask() override {} 1338 ~LazyUpdateLastAccessTimeTask() override {}
1306 1339
1307 private: 1340 private:
1308 int64 group_id_; 1341 int64 group_id_;
1309 base::Time last_access_time_; 1342 base::Time last_access_time_;
1310 }; 1343 };
1311 1344
1312 void AppCacheStorageImpl::UpdateGroupLastAccessTimeTask::Run() { 1345 void AppCacheStorageImpl::LazyUpdateLastAccessTimeTask::Run() {
1313 database_->UpdateGroupLastAccessTime(group_id_, last_access_time_); 1346 tracked_objects::ScopedTracker tracking_profile(
1347 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1348 "AppCacheStorageImpl::UpdateGroupLastAccessTimeTask"));
1349 database_->LazyUpdateLastAccessTime(group_id_, last_access_time_);
1314 } 1350 }
1315 1351
1352 void AppCacheStorageImpl::LazyUpdateLastAccessTimeTask::RunCompleted() {
1353 storage_->LazilyCommitLastAccessTimes();
1354 }
1355
1356 // CommitLastAccessTimesTask -------
1357
1358 class AppCacheStorageImpl::CommitLastAccessTimesTask
1359 : public DatabaseTask {
1360 public:
1361 CommitLastAccessTimesTask(AppCacheStorageImpl* storage)
1362 : DatabaseTask(storage) {}
1363
1364 // DatabaseTask:
1365 void Run() override {
1366 database_->CommitLazyLastAccessTimes();
1367 }
1368
1369 protected:
1370 ~CommitLastAccessTimesTask() override {}
1371 };
1316 1372
1317 // AppCacheStorageImpl --------------------------------------------------- 1373 // AppCacheStorageImpl ---------------------------------------------------
1318 1374
1319 AppCacheStorageImpl::AppCacheStorageImpl(AppCacheServiceImpl* service) 1375 AppCacheStorageImpl::AppCacheStorageImpl(AppCacheServiceImpl* service)
1320 : AppCacheStorage(service), 1376 : AppCacheStorage(service),
1321 is_incognito_(false), 1377 is_incognito_(false),
1322 is_response_deletion_scheduled_(false), 1378 is_response_deletion_scheduled_(false),
1323 did_start_deleting_responses_(false), 1379 did_start_deleting_responses_(false),
1324 last_deletable_response_rowid_(0), 1380 last_deletable_response_rowid_(0),
1325 database_(NULL), 1381 database_(NULL),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 if (is_disabled_) { 1449 if (is_disabled_) {
1394 delegate->OnCacheLoaded(NULL, id); 1450 delegate->OnCacheLoaded(NULL, id);
1395 return; 1451 return;
1396 } 1452 }
1397 1453
1398 AppCache* cache = working_set_.GetCache(id); 1454 AppCache* cache = working_set_.GetCache(id);
1399 if (cache) { 1455 if (cache) {
1400 delegate->OnCacheLoaded(cache, id); 1456 delegate->OnCacheLoaded(cache, id);
1401 if (cache->owning_group()) { 1457 if (cache->owning_group()) {
1402 scoped_refptr<DatabaseTask> update_task( 1458 scoped_refptr<DatabaseTask> update_task(
1403 new UpdateGroupLastAccessTimeTask( 1459 new LazyUpdateLastAccessTimeTask(
1404 this, cache->owning_group(), base::Time::Now())); 1460 this, cache->owning_group(), base::Time::Now()));
1405 update_task->Schedule(); 1461 update_task->Schedule();
1406 } 1462 }
1407 return; 1463 return;
1408 } 1464 }
1409 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id)); 1465 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id));
1410 if (task.get()) { 1466 if (task.get()) {
1411 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1467 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1412 return; 1468 return;
1413 } 1469 }
1414 task = new CacheLoadTask(id, this); 1470 task = new CacheLoadTask(id, this);
1415 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1471 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1416 task->Schedule(); 1472 task->Schedule();
1417 pending_cache_loads_[id] = task.get(); 1473 pending_cache_loads_[id] = task.get();
1418 } 1474 }
1419 1475
1420 void AppCacheStorageImpl::LoadOrCreateGroup( 1476 void AppCacheStorageImpl::LoadOrCreateGroup(
1421 const GURL& manifest_url, Delegate* delegate) { 1477 const GURL& manifest_url, Delegate* delegate) {
1422 DCHECK(delegate); 1478 DCHECK(delegate);
1423 if (is_disabled_) { 1479 if (is_disabled_) {
1424 delegate->OnGroupLoaded(NULL, manifest_url); 1480 delegate->OnGroupLoaded(NULL, manifest_url);
1425 return; 1481 return;
1426 } 1482 }
1427 1483
1428 AppCacheGroup* group = working_set_.GetGroup(manifest_url); 1484 AppCacheGroup* group = working_set_.GetGroup(manifest_url);
1429 if (group) { 1485 if (group) {
1430 delegate->OnGroupLoaded(group, manifest_url); 1486 delegate->OnGroupLoaded(group, manifest_url);
1431 scoped_refptr<DatabaseTask> update_task( 1487 scoped_refptr<DatabaseTask> update_task(
1432 new UpdateGroupLastAccessTimeTask( 1488 new LazyUpdateLastAccessTimeTask(
1433 this, group, base::Time::Now())); 1489 this, group, base::Time::Now()));
1434 update_task->Schedule(); 1490 update_task->Schedule();
1435 return; 1491 return;
1436 } 1492 }
1437 1493
1438 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url)); 1494 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url));
1439 if (task.get()) { 1495 if (task.get()) {
1440 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1496 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1441 return; 1497 return;
1442 } 1498 }
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 did_start_deleting_responses_ = true; 1740 did_start_deleting_responses_ = true;
1685 deletable_response_ids_.insert( 1741 deletable_response_ids_.insert(
1686 deletable_response_ids_.end(), 1742 deletable_response_ids_.end(),
1687 response_ids.begin(), response_ids.end()); 1743 response_ids.begin(), response_ids.end());
1688 if (!is_response_deletion_scheduled_) 1744 if (!is_response_deletion_scheduled_)
1689 ScheduleDeleteOneResponse(); 1745 ScheduleDeleteOneResponse();
1690 } 1746 }
1691 1747
1692 void AppCacheStorageImpl::ScheduleDeleteOneResponse() { 1748 void AppCacheStorageImpl::ScheduleDeleteOneResponse() {
1693 DCHECK(!is_response_deletion_scheduled_); 1749 DCHECK(!is_response_deletion_scheduled_);
1694 const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); 1750 const base::TimeDelta k10Millis = base::TimeDelta::FromMilliseconds(10);
1695 base::MessageLoop::current()->PostDelayedTask( 1751 base::MessageLoop::current()->PostDelayedTask(
1696 FROM_HERE, 1752 FROM_HERE,
1697 base::Bind(&AppCacheStorageImpl::DeleteOneResponse, 1753 base::Bind(&AppCacheStorageImpl::DeleteOneResponse,
1698 weak_factory_.GetWeakPtr()), 1754 weak_factory_.GetWeakPtr()),
1699 kDelay); 1755 k10Millis);
1700 is_response_deletion_scheduled_ = true; 1756 is_response_deletion_scheduled_ = true;
1701 } 1757 }
1702 1758
1703 void AppCacheStorageImpl::DeleteOneResponse() { 1759 void AppCacheStorageImpl::DeleteOneResponse() {
1704 DCHECK(is_response_deletion_scheduled_); 1760 DCHECK(is_response_deletion_scheduled_);
1705 DCHECK(!deletable_response_ids_.empty()); 1761 DCHECK(!deletable_response_ids_.empty());
1706 1762
1707 if (!disk_cache()) { 1763 if (!disk_cache()) {
1708 DCHECK(is_disabled_); 1764 DCHECK(is_disabled_);
1709 deletable_response_ids_.clear(); 1765 deletable_response_ids_.clear();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 base::Bind(base::IgnoreResult(&base::DeleteFile), cache_directory_, true), 1912 base::Bind(base::IgnoreResult(&base::DeleteFile), cache_directory_, true),
1857 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, 1913 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize,
1858 weak_factory_.GetWeakPtr())); 1914 weak_factory_.GetWeakPtr()));
1859 } 1915 }
1860 1916
1861 void AppCacheStorageImpl::CallScheduleReinitialize() { 1917 void AppCacheStorageImpl::CallScheduleReinitialize() {
1862 service_->ScheduleReinitialize(); 1918 service_->ScheduleReinitialize();
1863 // note: 'this' may be deleted at this point. 1919 // note: 'this' may be deleted at this point.
1864 } 1920 }
1865 1921
1922 void AppCacheStorageImpl::LazilyCommitLastAccessTimes() {
1923 if (lazy_commit_timer_.IsRunning())
1924 return;
1925 const int k10Minutes = 10;
1926 lazy_commit_timer_.Start(
1927 FROM_HERE, base::TimeDelta::FromMinutes(k10Minutes),
1928 base::Bind(&AppCacheStorageImpl::OnCommitLastAccessTimes,
1929 weak_factory_.GetWeakPtr()));
1930 }
1931
1932 void AppCacheStorageImpl::OnCommitLastAccessTimes() {
1933 lazy_commit_timer_.Stop();
1934 if (is_disabled())
1935 return;
1936 scoped_refptr<DatabaseTask> task(new CommitLastAccessTimesTask(this));
1937 task->Schedule();
1938 }
cmumford 2015/02/17 19:26:39 Space
michaeln 2015/02/17 19:46:26 Done.
1866 } // namespace content 1939 } // 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