cert_verifier_service_factory.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2020 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. #ifndef SERVICES_CERT_VERIFIER_CERT_VERIFIER_SERVICE_FACTORY_H_
  5. #define SERVICES_CERT_VERIFIER_CERT_VERIFIER_SERVICE_FACTORY_H_
  6. #include "base/gtest_prod_util.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/scoped_refptr.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "mojo/public/cpp/bindings/pending_receiver.h"
  11. #include "mojo/public/cpp/bindings/pending_remote.h"
  12. #include "mojo/public/cpp/bindings/receiver_set.h"
  13. #include "net/net_buildflags.h"
  14. #include "services/cert_verifier/cert_net_url_loader/cert_net_fetcher_url_loader.h"
  15. #include "services/cert_verifier/cert_verifier_service.h"
  16. #include "services/cert_verifier/public/mojom/cert_verifier_service_factory.mojom.h"
  17. #include "services/network/public/mojom/cert_verifier_service.mojom.h"
  18. #if BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED)
  19. #include "net/cert/internal/trust_store_chrome.h"
  20. #include "third_party/abseil-cpp/absl/types/optional.h"
  21. #endif
  22. namespace cert_verifier {
  23. // Implements mojom::CertVerifierServiceFactory, and calls
  24. // network::CreateCertVerifier to instantiate the concrete net::CertVerifier
  25. // used to service requests.
  26. class CertVerifierServiceFactoryImpl
  27. : public mojom::CertVerifierServiceFactory {
  28. public:
  29. explicit CertVerifierServiceFactoryImpl(
  30. mojo::PendingReceiver<mojom::CertVerifierServiceFactory> receiver);
  31. ~CertVerifierServiceFactoryImpl() override;
  32. // mojom::CertVerifierServiceFactory implementation:
  33. void GetNewCertVerifier(
  34. mojo::PendingReceiver<mojom::CertVerifierService> receiver,
  35. mojom::CertVerifierCreationParamsPtr creation_params) override;
  36. // Performs the same function as above, but stores a ref to the new
  37. // CertNetFetcherURLLoader in |*cert_net_fetcher_ptr|, if the
  38. // CertNetFetcherURLLoader is in use.
  39. void GetNewCertVerifierForTesting(
  40. mojo::PendingReceiver<mojom::CertVerifierService> receiver,
  41. mojom::CertVerifierCreationParamsPtr creation_params,
  42. scoped_refptr<CertNetFetcherURLLoader>* cert_net_fetcher_ptr);
  43. #if BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED)
  44. // mojom::CertVerifierServiceFactory implementation:
  45. void UpdateChromeRootStore(mojom::ChromeRootStorePtr new_root_store) override;
  46. void GetChromeRootStoreInfo(GetChromeRootStoreInfoCallback callback) override;
  47. #endif
  48. // Remove a CertVerifyService from needing updates to the Chrome Root Store.
  49. void RemoveService(internal::CertVerifierServiceImpl* service_impl);
  50. private:
  51. #if BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED)
  52. // The most recent version of the Chrome Root Store that we've seen.
  53. absl::optional<net::ChromeRootStoreData> root_store_data_;
  54. #endif
  55. mojo::Receiver<mojom::CertVerifierServiceFactory> receiver_;
  56. // Services that we might need to send updates to.
  57. std::set<raw_ptr<internal::CertVerifierServiceImpl>> verifier_services_;
  58. base::WeakPtrFactory<CertVerifierServiceFactoryImpl> weak_factory_{this};
  59. };
  60. } // namespace cert_verifier
  61. #endif // SERVICES_CERT_VERIFIER_CERT_VERIFIER_SERVICE_FACTORY_H_