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

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

Issue 2123813002: Report Precache.TimeSinceLastPrecache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gclient sync Created 4 years, 5 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 e9d53ecad16d8bc30ebd4415013430d1bd131dda..269eded59dc1da3031a31610d56265cfe8372458 100644
--- a/components/precache/core/precache_database.cc
+++ b/components/precache/core/precache_database.cc
@@ -23,6 +23,9 @@ namespace {
// it is considered "old" and is removed from the table.
const int kPrecacheHistoryExpiryPeriodDays = 60;
+const int kSecondsInMinute = 60;
+const int kSecondsInHour = kSecondsInMinute * 60;
+
} // namespace
namespace precache {
@@ -90,6 +93,28 @@ void PrecacheDatabase::ClearHistory() {
Flush();
}
+void PrecacheDatabase::SetLastPrecacheTimestamp(const base::Time& time) {
+ last_precache_timestamp_ = time;
+
+ if (!IsDatabaseAccessible()) {
+ // Do nothing if unable to access the database.
+ return;
+ }
+
+ buffered_writes_.push_back(
+ base::Bind(&PrecacheSessionTable::SetLastPrecacheTimestamp,
+ base::Unretained(&precache_session_table_), time));
+ MaybePostFlush();
+}
+
+base::Time PrecacheDatabase::GetLastPrecacheTimestamp() {
+ if (last_precache_timestamp_.is_null() && IsDatabaseAccessible()) {
+ last_precache_timestamp_ =
+ precache_session_table_.GetLastPrecacheTimestamp();
+ }
+ return last_precache_timestamp_;
+}
+
void PrecacheDatabase::RecordURLPrefetch(const GURL& url,
const base::TimeDelta& latency,
const base::Time& fetch_time,
@@ -157,6 +182,8 @@ void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url,
return;
}
+ RecordTimeSinceLastPrecache(fetch_time);
+
if (buffered_urls_.find(url.spec()) != buffered_urls_.end()) {
// If the URL for this fetch is in the write buffer, then flush the write
// buffer.
@@ -201,6 +228,25 @@ void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url,
MaybePostFlush();
}
+void PrecacheDatabase::RecordTimeSinceLastPrecache(
+ const base::Time& fetch_time) {
+ const base::Time& last_precache_timestamp = GetLastPrecacheTimestamp();
+ // It could still be null if the DB was not accessible.
+ if (!last_precache_timestamp.is_null()) {
+ // This is the timespan (in seconds) between the last call to
+ // PrecacheManager::StartPrecaching and the fetch time of a non-precache
+ // URL. Please note that the session started by that call to
+ // PrecacheManager::StartPrecaching may not have precached this particular
+ // URL or even any URL for that matter.
+ // The range was estimated to have the 95 percentile within the last bounded
+ // bucket.
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Precache.TimeSinceLastPrecache",
+ (fetch_time - last_precache_timestamp).InSeconds(), kSecondsInMinute,
+ kSecondsInHour * 36, 100);
+ }
+}
+
bool PrecacheDatabase::IsDatabaseAccessible() const {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(db_);
« no previous file with comments | « components/precache/core/precache_database.h ('k') | components/precache/core/precache_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698