simple_dependency_manager.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2019 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 COMPONENTS_KEYED_SERVICE_CORE_SIMPLE_DEPENDENCY_MANAGER_H_
  5. #define COMPONENTS_KEYED_SERVICE_CORE_SIMPLE_DEPENDENCY_MANAGER_H_
  6. #include "components/keyed_service/core/dependency_manager.h"
  7. #include "components/keyed_service/core/keyed_service_export.h"
  8. class SimpleFactoryKey;
  9. // A singleton that listens for owners of SimpleFactoryKey' destruction
  10. // notifications and rebroadcasts them to each SimpleKeyedBaseFactory in a safe
  11. // order based on the stated dependencies by each service.
  12. class KEYED_SERVICE_EXPORT SimpleDependencyManager : public DependencyManager {
  13. public:
  14. SimpleDependencyManager();
  15. SimpleDependencyManager(const SimpleDependencyManager&) = delete;
  16. SimpleDependencyManager& operator=(const SimpleDependencyManager&) = delete;
  17. // Called by each owners of SimpleFactoryKey before it is destroyed in order
  18. // to destroy all services associated with |key|.
  19. void DestroyKeyedServices(SimpleFactoryKey* key);
  20. static SimpleDependencyManager* GetInstance();
  21. // Registers profile-specific preferences for all services via |registry|.
  22. // |key| is used to prevent multiple registrations on the same BrowserContext
  23. // in tests.
  24. void RegisterProfilePrefsForServices(
  25. user_prefs::PrefRegistrySyncable* pref_registry);
  26. // Create services for test BrowserContexts - these contexts will not create
  27. // services for any SimpleKeyedBaseFactories that return true from
  28. // ServiceIsNULLWhileTesting().
  29. void CreateServicesForTest(SimpleFactoryKey* key);
  30. // Marks |context| as live (i.e., not stale). This method can be called as a
  31. // safeguard against |AssertContextWasntDestroyed()| checks going off due to
  32. // |context| aliasing an instance from a prior construction.
  33. void MarkContextLive(SimpleFactoryKey* key);
  34. private:
  35. ~SimpleDependencyManager() override;
  36. #ifndef NDEBUG
  37. // DependencyManager:
  38. void DumpContextDependencies(void* context) const final;
  39. #endif // NDEBUG
  40. };
  41. #endif // COMPONENTS_KEYED_SERVICE_CORE_SIMPLE_DEPENDENCY_MANAGER_H_