keyed_service.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2014 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_KEYED_SERVICE_H_
  5. #define COMPONENTS_KEYED_SERVICE_CORE_KEYED_SERVICE_H_
  6. #include "components/keyed_service/core/keyed_service_export.h"
  7. // Interface for keyed services that support two-phase destruction order.
  8. //
  9. // Two-phase shutdown allows keyed services to have a first pass shutdown phase
  10. // where they drop references. Not all services will need this, so there's a
  11. // default implementation. Only once every service has been given a chance to
  12. // drop references are services deleted. In a service's destructor the service
  13. // should *not* request other services from their factories via the relevant
  14. // Context object (e.g., Profile), as the association between that Context
  15. // object and its keyed services is dropped after the shutdown phase.
  16. // Shutdown of KeyedServices is generally initiated by the embedder's
  17. // destruction of Profile (or analogous object).
  18. // CAVEAT: Not all embedders destroy the Profiles (or Profile analogs) as part
  19. // of embedder shutdown, so it is not guaranteed that the keyed service shutdown
  20. // process will run at shutdown of a given embedder.
  21. class KEYED_SERVICE_EXPORT KeyedService {
  22. public:
  23. KeyedService() = default;
  24. KeyedService(const KeyedService&) = delete;
  25. KeyedService& operator=(const KeyedService&) = delete;
  26. KeyedService(KeyedService&&) = delete;
  27. KeyedService& operator=(KeyedService&&) = delete;
  28. // The second pass is the actual deletion of each object.
  29. virtual ~KeyedService() = default;
  30. // The first pass is to call Shutdown on a KeyedService.
  31. // Shutdown will be called automatically for you. Don't directly invoke
  32. // this unless you have a specific reason and understand the implications.
  33. virtual void Shutdown() {}
  34. };
  35. #endif // COMPONENTS_KEYED_SERVICE_CORE_KEYED_SERVICE_H_