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

Unified Diff: components/precache/core/precache_database.cc

Issue 1961153003: Add pause/resume functionality to precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/precache/core/precache_database.cc
diff --git a/components/precache/core/precache_database.cc b/components/precache/core/precache_database.cc
index 8cf4dac5b35466bc9d452d5a7f3da2e56c845282..0c03d28127414af9a459c7118066b9fb9744a973 100644
--- a/components/precache/core/precache_database.cc
+++ b/components/precache/core/precache_database.cc
@@ -26,6 +26,27 @@ const int kPrecacheHistoryExpiryPeriodDays = 60;
namespace precache {
+UnfinishedWork::UnfinishedWork(
+ const std::list<GURL>& manifest_urls_to_fetch,
+ const std::list<GURL>& resource_urls_to_fetch,
+ int64_t total_response_bytes,
+ int64_t network_response_bytes,
+ int64_t num_manifest_urls_to_fetch,
+ const base::TimeTicks& start_time_of_session)
+ : manifests(manifest_urls_to_fetch),
+ resources(resource_urls_to_fetch),
+ total_bytes(total_response_bytes),
+ network_bytes(network_response_bytes),
+ num_manifest_urls(num_manifest_urls_to_fetch),
+ start_time(start_time_of_session) {}
+
+UnfinishedWork::UnfinishedWork(
+ const base::TimeTicks& earliest_start_time_of_session)
+ : total_bytes(0), network_bytes(0), num_manifest_urls(0),
+ start_time(earliest_start_time_of_session) {}
+
+UnfinishedWork::~UnfinishedWork() {}
+
PrecacheDatabase::PrecacheDatabase()
: is_flush_posted_(false), weak_factory_(this) {
// A PrecacheDatabase can be constructed on any thread.
@@ -51,7 +72,8 @@ bool PrecacheDatabase::Init(const base::FilePath& db_path) {
return false;
}
- if (!precache_url_table_.Init(db_.get())) {
+ if (!precache_url_table_.Init(db_.get()) ||
+ !precache_session_tables_.Init(db_.get())) {
// Raze and close the database connection to indicate that it's not usable,
// and so that the database will be created anew next time, in case it's
// corrupted.
@@ -259,4 +281,37 @@ void PrecacheDatabase::MaybePostFlush() {
is_flush_posted_ = true;
}
+void PrecacheDatabase::GetUnfinishedWork(
+ scoped_refptr<UnfinishedWork> unfinished_work) {
+ base::TimeTicks earliest_start_time = unfinished_work->start_time;
+ precache_session_tables_.GetStatistics(
+ &unfinished_work->total_bytes,
+ &unfinished_work->network_bytes,
+ &unfinished_work->num_manifest_urls,
+ &unfinished_work->start_time);
+ if (unfinished_work->start_time >= earliest_start_time) {
+ precache_session_tables_.GetURLs(&unfinished_work->manifests,
+ &unfinished_work->resources);
+ }
+}
+
+void PrecacheDatabase::SaveUnfinishedWork(
+ scoped_refptr<UnfinishedWork> unfinished_work) {
+ precache_session_tables_.StoreURLs(unfinished_work->manifests,
+ unfinished_work->resources);
+ precache_session_tables_.StoreStatistics(
+ unfinished_work->total_bytes, unfinished_work->network_bytes,
+ unfinished_work->num_manifest_urls,
+ unfinished_work->start_time);
+}
+
+void PrecacheDatabase::ClearPrecacheSessionState() {
+ precache_session_tables_.ClearURLs();
+ precache_session_tables_.ClearStatistics();
+}
+
+base::WeakPtr<PrecacheDatabase> PrecacheDatabase::GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+}
+
} // namespace precache

Powered by Google App Engine
This is Rietveld 408576698