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

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

Issue 2123813002: Report Precache.TimeSinceLastPrecache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: UMA_HISTOGRAM_CUSTOM_COUNTS for seconds since first minute 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_session_table.cc
diff --git a/components/precache/core/precache_session_table.cc b/components/precache/core/precache_session_table.cc
index 8537b199025d38aaa2a064d59fc60613989f581f..ee37eb700db2f5407aa48a05be9c1ad216bcb6dd 100644
--- a/components/precache/core/precache_session_table.cc
+++ b/components/precache/core/precache_session_table.cc
@@ -4,10 +4,13 @@
#include "components/precache/core/precache_session_table.h"
+#include <stdint.h>
#include <string>
#include "base/logging.h"
+#include "base/numerics/safe_conversions.h"
#include "base/time/time.h"
+#include "components/precache/core/proto/timestamp.pb.h"
#include "components/precache/core/proto/unfinished_work.pb.h"
#include "sql/connection.h"
#include "sql/statement.h"
@@ -27,6 +30,34 @@ bool PrecacheSessionTable::Init(sql::Connection* db) {
return CreateTableIfNonExistent();
}
+void PrecacheSessionTable::SetLastPrecacheTimestamp(const base::Time& time) {
+ Timestamp timestamp;
+ timestamp.set_seconds(base::saturated_cast<int64_t>(time.ToDoubleT()));
twifkak 2016/07/08 23:47:53 Nit: I think `(time - base::Time::UnixEpoch()).InS
jamartin 2016/07/12 14:18:44 Done.
+ Statement statement(db_->GetCachedStatement(
+ SQL_FROM_HERE,
+ "INSERT OR REPLACE INTO precache_session (type, value) VALUES(?,?)"));
+ statement.BindInt(0, static_cast<int>(LAST_PRECACHE_TIMESTAMP));
+ statement.BindString(1, timestamp.SerializeAsString());
+ statement.Run();
+}
+
+base::Time PrecacheSessionTable::GetLastPrecacheTimestamp() {
+ Statement statement(db_->GetCachedStatement(
+ SQL_FROM_HERE, "SELECT value from precache_session where type=?"));
+ statement.BindInt(0, static_cast<int>(LAST_PRECACHE_TIMESTAMP));
+ Timestamp timestamp;
+ if (statement.Step())
+ timestamp.ParseFromString(statement.ColumnString(0));
+ return base::Time::FromDoubleT(timestamp.seconds());
twifkak 2016/07/08 23:47:53 Likewise, this could become `base::Time::UnixEpoch
jamartin 2016/07/12 14:18:44 Done.
+}
+
+void PrecacheSessionTable::DeleteLastPrecacheTimestamp() {
+ Statement statement(db_->GetCachedStatement(
+ SQL_FROM_HERE, "DELETE FROM precache_session where type=?"));
+ statement.BindInt(0, static_cast<int>(LAST_PRECACHE_TIMESTAMP));
+ statement.Run();
+}
+
// Store unfinished work.
void PrecacheSessionTable::SaveUnfinishedWork(
std::unique_ptr<PrecacheUnfinishedWork> unfinished_work) {

Powered by Google App Engine
This is Rietveld 408576698