Chromium Code Reviews| 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..efb84b66b90bb1183313de58f3d8ab1f710eb6fb 100644 |
| --- a/components/payments/android/payment_method_manifest_table.cc |
| +++ b/components/payments/android/payment_method_manifest_table.cc |
| @@ -4,11 +4,15 @@ |
| #include "components/payments/android/payment_method_manifest_table.h" |
| +#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; |
|
please use gerrit instead
2017/04/27 15:45:17
That's 1.5 days. You're missing an extra "* 60".
please use gerrit instead
2017/04/27 15:45:18
#include <time.h>
gogerald1
2017/04/27 18:08:39
Done.
gogerald1
2017/04/27 18:08:39
Done. Good catch
|
| + |
| 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 +36,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(); |
| @@ -66,10 +71,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::Now().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()) |
| @@ -87,13 +95,19 @@ std::vector<std::string> PaymentMethodManifestTable::GetManifest( |
| const std::string& payment_method) { |
| std::vector<std::string> web_app_ids; |
| sql::Statement s( |
| - db_->GetUniqueStatement("SELECT web_app_id " |
| + db_->GetUniqueStatement("SELECT expire_date, web_app_id " |
| "FROM payment_method_manifest " |
| "WHERE method_name=?")); |
| s.BindString(0, payment_method); |
| + const time_t now_date_in_seconds = base::Time::Now().ToTimeT(); |
| while (s.Step()) { |
| - web_app_ids.emplace_back(s.ColumnString(0)); |
| + int index = 0; |
| + if (now_date_in_seconds > s.ColumnInt64(index++)) { |
| + web_app_ids.clear(); |
|
please use gerrit instead
2017/04/27 15:45:18
You're leaving the stale data in the table, which
gogerald1
2017/04/27 18:08:39
Thought about this, but we have two tables, we mig
|
| + break; |
| + } |
| + web_app_ids.emplace_back(s.ColumnString(index)); |
| } |
| return web_app_ids; |