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

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: 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_session_table.cc
diff --git a/components/precache/core/precache_session_table.cc b/components/precache/core/precache_session_table.cc
index 8537b199025d38aaa2a064d59fc60613989f581f..9993c069bbe72ef3de7d9384c6bd79b3d25042b4 100644
--- a/components/precache/core/precache_session_table.cc
+++ b/components/precache/core/precache_session_table.cc
@@ -4,10 +4,12 @@
#include "components/precache/core/precache_session_table.h"
+#include <stdint.h>
#include <string>
#include "base/logging.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 +29,38 @@ bool PrecacheSessionTable::Init(sql::Connection* db) {
return CreateTableIfNonExistent();
}
+void PrecacheSessionTable::SetLastPrecacheTimestamp(const base::Time& time) {
+ DCHECK(!time.is_null());
+ Timestamp timestamp;
+ timestamp.set_seconds((time - base::Time::UnixEpoch()).InSeconds());
+ 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 timestamp.has_seconds()
+ ? base::Time::UnixEpoch() +
+ base::TimeDelta::FromSeconds(timestamp.seconds())
+ : base::Time();
+}
+
+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) {
« no previous file with comments | « components/precache/core/precache_session_table.h ('k') | components/precache/core/precache_session_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698