Index: components/payments/android/web_app_manifest_section_table.cc |
diff --git a/components/payments/android/web_app_manifest_section_table.cc b/components/payments/android/web_app_manifest_section_table.cc |
index 71f5664d3e5fe93fa7355eccac8a3f1e645e40a3..98347836791d5461b39fdb58c5bfd18def655102 100644 |
--- a/components/payments/android/web_app_manifest_section_table.cc |
+++ b/components/payments/android/web_app_manifest_section_table.cc |
@@ -8,11 +8,14 @@ |
#include <memory> |
+#include "base/time/time.h" |
#include "sql/statement.h" |
#include "sql/transaction.h" |
namespace payments { |
namespace { |
+// Data valid time in seconds. |
+const time_t DATA_VALID_TIME_IN_SECONDS = 90 * 24 * 60; |
// Note that the fingerprint is calculated with SHA-256. |
const size_t kFingerPrintLength = 32; |
@@ -72,6 +75,7 @@ WebDatabaseTable::TypeKey WebAppManifestSectionTable::GetTypeKey() const { |
bool WebAppManifestSectionTable::CreateTablesIfNecessary() { |
if (!db_->Execute("CREATE TABLE IF NOT EXISTS web_app_manifest_section ( " |
+ "expire_date INTEGER NOT NULL DEFAULT 0, " |
"id VARCHAR, " |
"min_version INTEGER NOT NULL DEFAULT 0, " |
"fingerprints BLOB) ")) { |
@@ -108,11 +112,14 @@ bool WebAppManifestSectionTable::AddWebAppManifest( |
sql::Statement s2( |
db_->GetUniqueStatement("INSERT INTO web_app_manifest_section " |
- "(id, min_version, fingerprints) " |
- "VALUES (?, ?, ?)")); |
+ "(expire_date, id, min_version, fingerprints) " |
+ "VALUES (?, ?, ?, ?)")); |
+ const time_t expire_date_in_seconds = |
+ base::Time::Now().ToTimeT() + DATA_VALID_TIME_IN_SECONDS; |
for (const auto& section : manifest) { |
DCHECK_EQ(manifest[0]->id, section->id); |
int index = 0; |
+ s2.BindInt64(index++, expire_date_in_seconds); |
s2.BindString(index++, section->id); |
s2.BindInt64(index++, section->min_version); |
std::unique_ptr<std::vector<uint8_t>> serialized_fingerprints = |
@@ -132,18 +139,24 @@ bool WebAppManifestSectionTable::AddWebAppManifest( |
std::vector<mojom::WebAppManifestSectionPtr> |
WebAppManifestSectionTable::GetWebAppManifest(const std::string& web_app) { |
- sql::Statement s( |
- db_->GetUniqueStatement("SELECT id, min_version, fingerprints " |
- "FROM web_app_manifest_section " |
- "WHERE id=?")); |
+ sql::Statement s(db_->GetUniqueStatement( |
+ "SELECT expire_date, id, min_version, fingerprints " |
+ "FROM web_app_manifest_section " |
+ "WHERE id=?")); |
s.BindString(0, web_app); |
+ const time_t now_time_in_seconds = base::Time::Now().ToTimeT(); |
std::vector<mojom::WebAppManifestSectionPtr> manifest; |
while (s.Step()) { |
+ int index = 0; |
+ if (now_time_in_seconds > s.ColumnInt64(index++)) { |
+ manifest.clear(); |
+ break; |
+ } |
+ |
mojom::WebAppManifestSectionPtr section = |
mojom::WebAppManifestSection::New(); |
- int index = 0; |
section->id = s.ColumnString(index++); |
section->min_version = s.ColumnInt64(index++); |