| 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..c8ebe9d8ac83082162908482d339e99d1e7f9212 100644
|
| --- a/components/payments/android/web_app_manifest_section_table.cc
|
| +++ b/components/payments/android/web_app_manifest_section_table.cc
|
| @@ -5,14 +5,17 @@
|
| #include "components/payments/android/web_app_manifest_section_table.h"
|
|
|
| #include <stdint.h>
|
| -
|
| +#include <time.h>
|
| #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 * 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) ")) {
|
| @@ -92,6 +96,14 @@ bool WebAppManifestSectionTable::MigrateToVersion(
|
| return true;
|
| }
|
|
|
| +void WebAppManifestSectionTable::RemoveExpiredData() {
|
| + const time_t now_date_in_seconds = base::Time::NowFromSystemTime().ToTimeT();
|
| + sql::Statement s(db_->GetUniqueStatement(
|
| + "DELETE FROM web_app_manifest_section WHERE expire_date < ? "));
|
| + s.BindInt64(0, now_date_in_seconds);
|
| + s.Run();
|
| +}
|
| +
|
| bool WebAppManifestSectionTable::AddWebAppManifest(
|
| const std::vector<mojom::WebAppManifestSectionPtr>& manifest) {
|
| DCHECK_LT(0U, manifest.size());
|
| @@ -108,11 +120,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::NowFromSystemTime().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 =
|
|
|