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

Unified Diff: components/payments/android/payment_method_manifest_table.cc

Issue 2845753003: [Payments] Set cached manifest expiration date (Closed)
Patch Set: improve comments Created 3 years, 8 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/payments/android/payment_method_manifest_table.cc
diff --git a/components/payments/android/payment_method_manifest_table.cc b/components/payments/android/payment_method_manifest_table.cc
index 8e7ac7f3d864516e3e0da6728e250fc8995d2f92..1c79556ed585be1a860027ccba7393fdee46959d 100644
--- a/components/payments/android/payment_method_manifest_table.cc
+++ b/components/payments/android/payment_method_manifest_table.cc
@@ -4,11 +4,17 @@
#include "components/payments/android/payment_method_manifest_table.h"
+#include <time.h>
+
+#include "base/time/time.h"
#include "sql/statement.h"
#include "sql/transaction.h"
namespace payments {
namespace {
+// Data valid duration in seconds.
+const time_t DATA_VALID_TIME_IN_SECONDS = 90 * 24 * 60 * 60;
+
WebDatabaseTable::TypeKey GetKey() {
// We just need a unique constant. Use the address of a static that
// COMDAT folding won't touch in an optimizing linker.
@@ -32,6 +38,7 @@ WebDatabaseTable::TypeKey PaymentMethodManifestTable::GetTypeKey() const {
bool PaymentMethodManifestTable::CreateTablesIfNecessary() {
if (!db_->Execute("CREATE TABLE IF NOT EXISTS payment_method_manifest ( "
+ "expire_date INTEGER NOT NULL DEFAULT 0, "
"method_name VARCHAR, "
"web_app_id VARCHAR) ")) {
NOTREACHED();
@@ -51,6 +58,14 @@ bool PaymentMethodManifestTable::MigrateToVersion(
return true;
}
+void PaymentMethodManifestTable::RemoveExpiredData() {
+ const time_t now_date_in_seconds = base::Time::NowFromSystemTime().ToTimeT();
+ sql::Statement s(db_->GetUniqueStatement(
+ "DELETE FROM payment_method_manifest WHERE expire_date < ? "));
+ s.BindInt64(0, now_date_in_seconds);
+ s.Run();
+}
+
bool PaymentMethodManifestTable::AddManifest(
const std::string& payment_method,
const std::vector<std::string>& web_app_ids) {
@@ -66,10 +81,13 @@ bool PaymentMethodManifestTable::AddManifest(
sql::Statement s2(
db_->GetUniqueStatement("INSERT INTO payment_method_manifest "
- "(method_name, web_app_id) "
- "VALUES (?, ?) "));
+ "(expire_date, method_name, web_app_id) "
+ "VALUES (?, ?, ?) "));
+ const time_t expire_date_in_seconds =
+ base::Time::NowFromSystemTime().ToTimeT() + DATA_VALID_TIME_IN_SECONDS;
for (const auto& id : web_app_ids) {
int index = 0;
+ s2.BindInt64(index++, expire_date_in_seconds);
s2.BindString(index++, payment_method);
s2.BindString(index, id);
if (!s2.Run())

Powered by Google App Engine
This is Rietveld 408576698