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

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: Raj's comments 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..878072ac8741d6f8c88df102ffb2f7d79cc42702 100644
--- a/components/precache/core/precache_database.cc
+++ b/components/precache/core/precache_database.cc
@@ -90,6 +90,30 @@ 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() {
Raj 2016/07/06 17:16:46 nit: Can we check if the cached last_precache_time
jamartin 2016/07/07 12:12:36 Done. Anyway, I think I put this function here on
+ if (!IsDatabaseAccessible()) {
+ // Use the cached value, possibly not initialized (and hence is_null()).
+ return last_precache_timestamp_;
+ }
+
+ 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 +181,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 +227,24 @@ void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url,
MaybePostFlush();
}
+void PrecacheDatabase::RecordTimeSinceLastPrecache(
+ const base::Time& fetch_time) {
+ if (last_precache_timestamp_.is_null()) {
+ last_precache_timestamp_ =
+ precache_session_table_.GetLastPrecacheTimestamp();
+ }
+ // It could still be null if the DB was not accessible.
+ if (!last_precache_timestamp_.is_null()) {
+ // This is the timespan 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.
+ UMA_HISTOGRAM_TIMES("Precache.TimeSinceLastPrecache",
+ fetch_time - last_precache_timestamp_);
+ }
+}
+
bool PrecacheDatabase::IsDatabaseAccessible() const {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(db_);

Powered by Google App Engine
This is Rietveld 408576698