Chromium Code Reviews| 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 f7a06580fd8065f7091da11884f869efffca8953..9f98e5ec66590f11183aa18c1a262d9be7937512 100644 |
| --- a/components/payments/android/web_app_manifest_section_table.cc |
| +++ b/components/payments/android/web_app_manifest_section_table.cc |
| @@ -9,6 +9,7 @@ |
| #include <memory> |
| #include "sql/statement.h" |
| +#include "sql/transaction.h" |
| namespace payments { |
| namespace { |
| @@ -71,7 +72,7 @@ WebDatabaseTable::TypeKey WebAppManifestSectionTable::GetTypeKey() const { |
| bool WebAppManifestSectionTable::CreateTablesIfNecessary() { |
| if (!db_->Execute("CREATE TABLE IF NOT EXISTS web_app_manifest_section ( " |
| - "id VARCHAR PRIMARY KEY, " |
| + "id VARCHAR, " |
|
please use gerrit instead
2017/04/24 18:22:32
What happened to the primary key?
gogerald1
2017/04/26 13:46:33
id is not unique since an app may have multiple We
|
| "min_version INTEGER NOT NULL DEFAULT 0, " |
| "fingerprints BLOB) ")) { |
| NOTREACHED(); |
| @@ -92,51 +93,68 @@ bool WebAppManifestSectionTable::MigrateToVersion( |
| } |
| bool WebAppManifestSectionTable::AddWebAppManifest( |
| - mojom::WebAppManifestSection* manifest) { |
| - DCHECK(manifest); |
| - DCHECK(!manifest->id.empty()); |
| + const std::vector<mojom::WebAppManifestSectionPtr>& manifest) { |
| + DCHECK(manifest.size() > 0); |
|
please use gerrit instead
2017/04/24 18:22:33
DCHECK_LT(0U, manifest.size());
gogerald1
2017/04/26 13:46:33
Done.
|
| - sql::Statement s( |
| - db_->GetUniqueStatement("INSERT OR REPLACE INTO web_app_manifest_section " |
| + sql::Transaction transaction(db_); |
| + if (!transaction.Begin()) |
| + return false; |
| + |
| + sql::Statement s1(db_->GetUniqueStatement( |
| + "DELETE FROM web_app_manifest_section WHERE id=? ")); |
| + s1.BindString(0, manifest[0]->id); |
| + if (!s1.Run()) |
| + return false; |
| + |
| + sql::Statement s2( |
| + db_->GetUniqueStatement("INSERT INTO web_app_manifest_section " |
| "(id, min_version, fingerprints) " |
| "VALUES (?, ?, ?)")); |
| - int index = 0; |
| - s.BindString(index++, manifest->id); |
| - s.BindInt64(index++, manifest->min_version); |
| - std::unique_ptr<std::vector<uint8_t>> serialized_fingerprints = |
| - SerializeFingerPrints(manifest->fingerprints); |
| - s.BindBlob(index, serialized_fingerprints->data(), |
| - serialized_fingerprints->size()); |
| - if (!s.Run()) |
| + for (const auto& section : manifest) { |
|
please use gerrit instead
2017/04/24 18:22:32
DCHECK_EQ(manifest[0]->id, section->id);
gogerald1
2017/04/26 13:46:33
Done.
|
| + int index = 0; |
| + s2.BindString(index++, section->id); |
| + s2.BindInt64(index++, section->min_version); |
| + std::unique_ptr<std::vector<uint8_t>> serialized_fingerprints = |
| + SerializeFingerPrints(section->fingerprints); |
| + s2.BindBlob(index, serialized_fingerprints->data(), |
| + serialized_fingerprints->size()); |
| + if (!s2.Run()) |
| + return false; |
| + s2.Reset(true); |
| + } |
| + |
| + if (!transaction.Commit()) |
| return false; |
| return true; |
| } |
| -mojom::WebAppManifestSectionPtr WebAppManifestSectionTable::GetWebAppManifest( |
| - const std::string& web_app) { |
| +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=?")); |
| s.BindString(0, web_app); |
| - if (!s.Step()) |
| - return nullptr; |
| + std::vector<mojom::WebAppManifestSectionPtr> manifest; |
| + while (s.Step()) { |
| + mojom::WebAppManifestSectionPtr section = |
| + mojom::WebAppManifestSection::New(); |
| - mojom::WebAppManifestSectionPtr manifest = |
| - mojom::WebAppManifestSection::New(); |
| + int index = 0; |
| + section->id = s.ColumnString(index++); |
| + section->min_version = s.ColumnInt64(index++); |
| - int index = 0; |
| - manifest->id = s.ColumnString(index++); |
| - manifest->min_version = s.ColumnInt64(index++); |
| + std::vector<uint8_t> fingerprints; |
| + if (!s.ColumnBlobAsVector(index, &fingerprints)) |
|
please use gerrit instead
2017/04/24 18:22:32
This is an error condition, so you should signal a
gogerald1
2017/04/26 13:46:33
Done.
|
| + break; |
| - std::vector<uint8_t> fingerprints; |
| - if (!s.ColumnBlobAsVector(index, &fingerprints)) |
| - return nullptr; |
| + if (!DeserializeFingerPrints(fingerprints, section->fingerprints)) |
| + break; |
| - if (!DeserializeFingerPrints(fingerprints, manifest->fingerprints)) |
| - return nullptr; |
| + manifest.emplace_back(std::move(section)); |
| + } |
| return manifest; |
| } |