blob: f2eadb731247f413cefba74b064c25cdf3c880f3 [file] [log] [blame]
gogerald6d16ea52017-04-13 20:43:281// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Rouslan Solomakhinde012532017-09-20 15:18:345#ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_
6#define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_
gogerald6d16ea52017-04-13 20:43:287
Rouslan Solomakhinebf9f162020-08-27 15:28:138#include <memory>
gogerald6d16ea52017-04-13 20:43:289#include <string>
10#include <vector>
11
Rouslan Solomakhinebf9f162020-08-27 15:28:1312#include "base/strings/string16.h"
gogerald6d16ea52017-04-13 20:43:2813#include "components/webdata/common/web_database_table.h"
14
Rouslan Solomakhinde012532017-09-20 15:18:3415class WebDatabase;
16
gogerald6d16ea52017-04-13 20:43:2817namespace payments {
18
Rouslan Solomakhinebf9f162020-08-27 15:28:1319struct SecurePaymentConfirmationInstrument;
20
21// This class manages Web Payment tables in SQLite database. It expects the
22// following schema.
gogerald6d16ea52017-04-13 20:43:2823//
Rouslan Solomakhinebf9f162020-08-27 15:28:1324// payment_method_manifest This table stores WebAppManifestSection.id of the
gogerald6d16ea52017-04-13 20:43:2825// supported web app in this payment method manifest.
26// Note that a payment method manifest might contain
27// multiple supported web apps ids.
gogerald69a1f752017-04-27 21:18:0728//
Rouslan Solomakhinebf9f162020-08-27 15:28:1329// expire_date The expire date in seconds from 1601-01-01 00:00:00
gogerald69a1f752017-04-27 21:18:0730// UTC.
Rouslan Solomakhinebf9f162020-08-27 15:28:1331// method_name The method name.
32// web_app_id The supported web app id.
gogerald6d16ea52017-04-13 20:43:2833// (WebAppManifestSection.id).
34//
Rouslan Solomakhinebf9f162020-08-27 15:28:1335// secure_payment_confirmation_instrument
36// This table stores instrument information for secure
37// payment confirmation method.
38//
39// credential_id The WebAuthn credential identifier blob. Primary key.
40// relying_party_id The relying party identifier string.
41// label The instrument human-readable label string.
42// icon The serialized SkBitmap blob.
gogerald6d16ea52017-04-13 20:43:2843class PaymentMethodManifestTable : public WebDatabaseTable {
44 public:
45 PaymentMethodManifestTable();
46 ~PaymentMethodManifestTable() override;
47
Rouslan Solomakhinebf9f162020-08-27 15:28:1348 PaymentMethodManifestTable(const PaymentMethodManifestTable& other) = delete;
49 PaymentMethodManifestTable& operator=(
50 const PaymentMethodManifestTable& other) = delete;
51
52 // Retrieves the PaymentMethodManifestTable* owned by `db`.
gogerald6d16ea52017-04-13 20:43:2853 static PaymentMethodManifestTable* FromWebDatabase(WebDatabase* db);
54
55 // WebDatabaseTable:
56 WebDatabaseTable::TypeKey GetTypeKey() const override;
57 bool CreateTablesIfNecessary() override;
58 bool IsSyncable() override;
59 bool MigrateToVersion(int version, bool* update_compatible_version) override;
60
gogerald69a1f752017-04-27 21:18:0761 // Remove expired data.
62 void RemoveExpiredData();
63
Rouslan Solomakhinebf9f162020-08-27 15:28:1364 // Adds `payment_method`'s manifest. `web_app_ids` contains supported web apps
gogerald6d16ea52017-04-13 20:43:2865 // ids.
66 bool AddManifest(const std::string& payment_method,
67 const std::vector<std::string>& web_app_ids);
68
Rouslan Solomakhinebf9f162020-08-27 15:28:1369 // Gets manifest for `payment_method`. Return empty vector if no manifest
gogerald6d16ea52017-04-13 20:43:2870 // exists for this method.
71 std::vector<std::string> GetManifest(const std::string& payment_method);
72
Rouslan Solomakhinebf9f162020-08-27 15:28:1373 // Adds a secure payment confirmation `instrument`. All existing data for the
74 // instrument's (relying_party_id, credential_id) tuple is erased before the
75 // new data is added.
76 //
77 // Each field in the `instrument` should be non-empty and `relying_party_id`
78 // field should be a valid domain string. See:
79 // https://url.spec.whatwg.org/#valid-domain-string
80 //
81 // Returns false for invalid data, e.g., credential reuse between relying
82 // parties, or on failure.
83 bool AddSecurePaymentConfirmationInstrument(
84 const SecurePaymentConfirmationInstrument& instrument);
85
86 // Gets the list of secure payment confirmation instruments for the given list
87 // of `credential_ids`.
88 //
89 // Returns an empty vector when no data is found or when a read error occurs.
90 // Does not return invalid instruments.
91 //
92 // Please use `std::move()` for `credential_ids` parameter to avoid extra
93 // copies.
94 std::vector<std::unique_ptr<SecurePaymentConfirmationInstrument>>
95 GetSecurePaymentConfirmationInstruments(
96 std::vector<std::vector<uint8_t>> credential_ids);
gogerald6d16ea52017-04-13 20:43:2897};
98
99} // namespace payments
100
Rouslan Solomakhinde012532017-09-20 15:18:34101#endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_