File: secure_payment_confirmation_credential_finder.h

package info (click to toggle)
chromium 141.0.7390.107-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,246,132 kB
  • sloc: cpp: 35,264,965; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,635; asm: 950,788; xml: 751,751; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,313; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (87 lines) | stat: -rw-r--r-- 3,322 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_CREDENTIAL_FINDER_H_
#define COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_CREDENTIAL_FINDER_H_

#include <map>
#include <string>

#include "base/memory/weak_ptr.h"
#include "components/webdata/common/web_data_service_consumer.h"

namespace url {
class Origin;
}

namespace webauthn {
class InternalAuthenticator;
}

namespace payments {

class WebPaymentsWebDataService;
struct SecurePaymentConfirmationCredential;

// Wraps retrieval and matching of SPC credentials, from either the user profile
// database or OS-level APIs.
class SecurePaymentConfirmationCredentialFinder
    : public WebDataServiceConsumer {
 public:
  SecurePaymentConfirmationCredentialFinder();
  ~SecurePaymentConfirmationCredentialFinder() override;

  using SecurePaymentConfirmationCredentialFinderCallback =
      base::OnceCallback<void(
          std::optional<
              std::vector<std::unique_ptr<SecurePaymentConfirmationCredential>>>
              credentials)>;

  // Retrieve available SPC credentials that match the input `credential_ids`
  // and `relying_party_id`, and which if necessary have the third-party payment
  // bit (i.e., if `relying_party_id` and `caller_origin` are different).
  //
  // The `callback` will be called with the resulting credentials, or
  // std::nullopt if an error was encountered. The callback may be called either
  // synchronously or asynchronously.
  virtual void GetMatchingCredentials(
      const std::vector<std::vector<uint8_t>>& credential_ids,
      const std::string& relying_party_id,
      const url::Origin& caller_origin,
      webauthn::InternalAuthenticator* authenticator,
      scoped_refptr<payments::WebPaymentsWebDataService> web_data_service,
      SecurePaymentConfirmationCredentialFinderCallback result_callback);

  // WebDataServiceConsumer:
  void OnWebDataServiceRequestDone(
      WebDataServiceBase::Handle handle,
      std::unique_ptr<WDTypedResult> result) override;

 private:
  // On platforms where we have credential-store level support for retrieving
  // credentials (i.e., rather than using the user profile database), this
  // callback will be called with the retrieved and matching credential ids.
  //
  // |relying_party_id| and |matching_credentials| are always std::move'd in,
  // and so are not const-ref.
  void OnGetMatchingCredentialIdsFromStore(
      SecurePaymentConfirmationCredentialFinderCallback callback,
      std::string relying_party_id,
      std::vector<std::vector<uint8_t>> matching_credentials);

  // On platforms where we are using the user profile database, this map holds
  // in-progress requests to the database mapped to the callback which should be
  // called with the result.
  std::map<WebDataServiceBase::Handle,
           std::pair<SecurePaymentConfirmationCredentialFinderCallback,
                     scoped_refptr<payments::WebPaymentsWebDataService>>>
      requests_;

  base::WeakPtrFactory<SecurePaymentConfirmationCredentialFinder>
      weak_ptr_factory_{this};
};

}  // namespace payments

#endif  // COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_CREDENTIAL_FINDER_H_