/chrome/browser/lacros/cert/cert_db_initializer_factory.h

https://github.com/chromium/chromium · C Header · 59 lines · 24 code · 10 blank · 25 comment · 0 complexity · 6a1ba733584b16ded63fab9a261b1d13 MD5 · raw file

  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 CHROME_BROWSER_LACROS_CERT_CERT_DB_INITIALIZER_FACTORY_H_
  5. #define CHROME_BROWSER_LACROS_CERT_CERT_DB_INITIALIZER_FACTORY_H_
  6. #include "base/no_destructor.h"
  7. #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
  8. class CertDbInitializer;
  9. // Factory that manages creation of CertDbInitializer. The initialization is
  10. // handled differently depending on the environment:
  11. // * On real ChromeOS devices with TPMs:
  12. // ** if the user is affiliated: CertDbInitializer is automatically
  13. // created right after its profile is created. It receives a path to software
  14. // cert database and slot IDs for Chaps from Ash and uses them.
  15. // ** if the user is not affiliated: TODO(b/197082753): not officially supported
  16. // yet, handled as if there's no TPM.
  17. // * In emulated environments (e.g. when running ChromeOS on Linux) and in the
  18. // future on ChromeOS without TPMs: Same as real ChromeOS, but Ash only sends
  19. // the software database path.
  20. // * In browsertests: CertDbInitializer is not created by default because it
  21. // requires crosapi mojo interface. It is configured through the
  22. // `SetCreateWithBrowserContextForTesting()` method. This can be overridden by
  23. // individual tests or they can create their own instances of the service.
  24. // * In unittests: CertDbInitializer is not created by default (see
  25. // `ServiceIsNULLWhileTesting()`).
  26. class CertDbInitializerFactory : public BrowserContextKeyedServiceFactory {
  27. public:
  28. static CertDbInitializerFactory* GetInstance();
  29. static CertDbInitializer* GetForBrowserContext(
  30. content::BrowserContext* context);
  31. // Configures whether CertDbInitializer should be automatically created on
  32. // profile creation in browser tests.
  33. // Currently it is configured that in browser tests the service is not created
  34. // by default. Individual tests can override it when needed.
  35. void SetCreateWithBrowserContextForTesting(bool should_create);
  36. private:
  37. friend class base::NoDestructor<CertDbInitializerFactory>;
  38. CertDbInitializerFactory();
  39. ~CertDbInitializerFactory() override = default;
  40. // BrowserStateKeyedServiceFactory
  41. bool ServiceIsCreatedWithBrowserContext() const override;
  42. KeyedService* BuildServiceInstanceFor(
  43. content::BrowserContext* context) const override;
  44. bool ServiceIsNULLWhileTesting() const override;
  45. content::BrowserContext* GetBrowserContextToUse(
  46. content::BrowserContext* context) const override;
  47. bool should_create_with_browser_context_ = true;
  48. };
  49. #endif // CHROME_BROWSER_LACROS_CERT_CERT_DB_INITIALIZER_FACTORY_H_