simple_dependency_manager.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "components/keyed_service/core/simple_dependency_manager.h"
  5. #include "base/no_destructor.h"
  6. #include "base/trace_event/trace_event.h"
  7. #include "components/keyed_service/core/simple_factory_key.h"
  8. #ifndef NDEBUG
  9. #include "base/command_line.h"
  10. #include "base/files/file_util.h"
  11. namespace {
  12. // Dumps dependency information about our simple keyed services
  13. // into a dot file in the browser context directory.
  14. const char kDumpSimpleDependencyGraphFlag[] = "dump-simple-graph";
  15. } // namespace
  16. #endif // NDEBUG
  17. void SimpleDependencyManager::DestroyKeyedServices(SimpleFactoryKey* key) {
  18. DependencyManager::DestroyContextServices(key);
  19. }
  20. // static
  21. SimpleDependencyManager* SimpleDependencyManager::GetInstance() {
  22. static base::NoDestructor<SimpleDependencyManager> factory;
  23. return factory.get();
  24. }
  25. void SimpleDependencyManager::RegisterProfilePrefsForServices(
  26. user_prefs::PrefRegistrySyncable* pref_registry) {
  27. TRACE_EVENT0("browser",
  28. "SimpleDependencyManager::RegisterProfilePrefsForServices");
  29. RegisterPrefsForServices(pref_registry);
  30. }
  31. void SimpleDependencyManager::CreateServicesForTest(SimpleFactoryKey* key) {
  32. TRACE_EVENT0("browser", "SimpleDependencyManager::CreateServices");
  33. DependencyManager::CreateContextServices(key, true);
  34. }
  35. void SimpleDependencyManager::MarkContextLive(SimpleFactoryKey* key) {
  36. DependencyManager::MarkContextLive(key);
  37. }
  38. SimpleDependencyManager::SimpleDependencyManager() = default;
  39. SimpleDependencyManager::~SimpleDependencyManager() = default;
  40. #ifndef NDEBUG
  41. void SimpleDependencyManager::DumpContextDependencies(void* context) const {
  42. // Whenever we try to build a destruction ordering, we should also dump a
  43. // dependency graph to "/path/to/context/context-dependencies.dot".
  44. if (base::CommandLine::ForCurrentProcess()->HasSwitch(
  45. kDumpSimpleDependencyGraphFlag)) {
  46. base::FilePath dot_file =
  47. static_cast<const SimpleFactoryKey*>(context)->GetPath().AppendASCII(
  48. "simple-dependencies.dot");
  49. DumpDependenciesAsGraphviz("SimpleDependencyManager", dot_file);
  50. }
  51. }
  52. #endif // NDEBUG