Chromium Code Reviews| 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..40c2c730b008c992eecbba393abadb85e3d8b1ae 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 kSecondsInDay = kSecondsInMinute * 60 * 24; |
| + |
| } // namespace |
| namespace precache { |
| @@ -90,6 +93,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 (!last_precache_timestamp_.is_null() || !IsDatabaseAccessible()) { |
|
twifkak
2016/07/08 23:47:53
Nit: Can get rid of the redundant return statement
jamartin
2016/07/12 14:18:44
Good point.
|
| + // 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 +184,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 +230,26 @@ void PrecacheDatabase::RecordURLNonPrefetch(const GURL& url, |
| MaybePostFlush(); |
| } |
| +void PrecacheDatabase::RecordTimeSinceLastPrecache( |
| + const base::Time& fetch_time) { |
| + if (last_precache_timestamp_.is_null()) { |
|
twifkak
2016/07/08 23:47:53
Why don't you just call [this->]GetLastPrecacheTim
jamartin
2016/07/12 14:18:44
Good point.
This grew organically. This GetLastPr
|
| + 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 (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. |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + "Precache.TimeSinceLastPrecache", |
| + (fetch_time - last_precache_timestamp_).InSeconds(), |
| + kSecondsInMinute, kSecondsInDay, 100); |
|
rkaplow
2016/07/08 14:37:59
not really obvious to me you have a min of 60 - wh
rkaplow
2016/07/08 14:37:59
picking the max as a day seems fine though (respon
jamartin
2016/07/08 14:52:49
Thanks. Ideally I'd like more than a day, probably
jamartin
2016/07/08 14:52:49
0 is not a valid min as per Histogram::FactoryGet.
twifkak
2016/07/08 23:47:53
IIRC, the advice I was given a while back was to m
jamartin
2016/07/12 14:18:44
Done (max = 36h).
BTW, what do you think of the m
twifkak
2016/07/16 00:47:49
Oh yeah, good question.
Short: I think it's fine.
|
| + } |
| +} |
| + |
| bool PrecacheDatabase::IsDatabaseAccessible() const { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(db_); |