| 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() {
|
| + 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_);
|
|
|