/chrome/browser/policy/networking/policy_cert_service_factory.h

https://github.com/chromium/chromium · C Header · 81 lines · 38 code · 17 blank · 26 comment · 0 complexity · 83733a0e6042a8b4e7145c42ba94b213 MD5 · raw file

  1. // Copyright 2013 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_POLICY_NETWORKING_POLICY_CERT_SERVICE_FACTORY_H_
  5. #define CHROME_BROWSER_POLICY_NETWORKING_POLICY_CERT_SERVICE_FACTORY_H_
  6. #include <memory>
  7. #include <string>
  8. #include "build/chromeos_buildflags.h"
  9. #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
  10. namespace base {
  11. template <typename T>
  12. struct DefaultSingletonTraits;
  13. } // namespace base
  14. class Profile;
  15. namespace policy {
  16. class PolicyCertService;
  17. // Factory to create PolicyCertServices.
  18. class PolicyCertServiceFactory : public BrowserContextKeyedServiceFactory {
  19. public:
  20. // Returns an existing PolicyCertService for |profile|. See
  21. // CreateForProfile.
  22. static PolicyCertService* GetForProfile(Profile* profile);
  23. // Creates (if it's not already created) a PolicyCertService and gets it to
  24. // start listening for trust anchors for the profile. Returns false if this
  25. // service isn't allowed for |profile|, i.e. if NetworkConfigurationUpdater
  26. // doesn't exist. This service is created separately for the original profile
  27. // and the incognito profile.
  28. // Note: NetworkConfigurationUpdater is currently only created for the primary
  29. // user's profile.
  30. // This should only be called if the network service is enabled.
  31. static bool CreateAndStartObservingForProfile(Profile* profile);
  32. static PolicyCertServiceFactory* GetInstance();
  33. PolicyCertServiceFactory(const PolicyCertServiceFactory&) = delete;
  34. PolicyCertServiceFactory& operator=(const PolicyCertServiceFactory&) = delete;
  35. #if BUILDFLAG(IS_CHROMEOS_ASH)
  36. // Migrates the `prefs::kUsedPolicyCertificates` preference from local state
  37. // into per-profile pref storage. Returns true if the local pref was present
  38. // and was successfully migrated.
  39. // TODO(b/202492163): The migration started in October 2021. According to
  40. // chrome/browser/prefs/README.md it should go for at least a year. Also note
  41. // that Lacros-Chrome can never have this preference in local state.
  42. static bool MigrateLocalStatePrefIntoProfilePref(
  43. const std::string& user_email,
  44. Profile* profile);
  45. // Used to clear |user_email| as having used certificates pushed by
  46. // policy before. Returns true if the flag was present and was successfully
  47. // cleared.
  48. // TODO(b/202492163) This can be deleted after the local state -> profile pref
  49. // migration is finished.
  50. static bool ClearUsedPolicyCertificates(const std::string& user_email);
  51. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  52. private:
  53. friend struct base::DefaultSingletonTraits<PolicyCertServiceFactory>;
  54. PolicyCertServiceFactory();
  55. ~PolicyCertServiceFactory() override;
  56. // BrowserContextKeyedServiceFactory:
  57. KeyedService* BuildServiceInstanceFor(
  58. content::BrowserContext* context) const override;
  59. content::BrowserContext* GetBrowserContextToUse(
  60. content::BrowserContext* context) const override;
  61. bool ServiceIsNULLWhileTesting() const override;
  62. };
  63. } // namespace policy
  64. #endif // CHROME_BROWSER_POLICY_NETWORKING_POLICY_CERT_SERVICE_FACTORY_H_