Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: components/keyed_service/core/keyed_service_shutdown_notifier.h

Issue 905703002: Add KeyedServiceShutdownNotifier for classes that depend on keyed services but can't be keyed servi… (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/keyed_service/core/keyed_service_shutdown_notifier.h
diff --git a/components/keyed_service/core/keyed_service_shutdown_notifier.h b/components/keyed_service/core/keyed_service_shutdown_notifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..2f2ca294a76b5dcaf1ef287a1ff4460e7ad3aac5
--- /dev/null
+++ b/components/keyed_service/core/keyed_service_shutdown_notifier.h
@@ -0,0 +1,39 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_KEYED_SERVICE_CORE_KEYED_SERVICE_SHUTDOWN_NOTIFIER_H_
+#define COMPONENTS_KEYED_SERVICE_CORE_KEYED_SERVICE_SHUTDOWN_NOTIFIER_H_
+
+#include "base/callback_list.h"
+#include "components/keyed_service/core/keyed_service.h"
+
+// This is a helper class for objects that depend on one or more keyed services,
+// but which cannot be keyed services themselves, for example because they don't
+// correspond 1:1 to a context, or because they have a different lifetime.
+//
+// To use this class, add a factory class and declare the dependencies there.
+// This class (being a KeyedService itself) will be shut down before its
+// dependencies and notify its observers.
+class KEYED_SERVICE_EXPORT KeyedServiceShutdownNotifier : public KeyedService {
+ public:
+ using Subscription = base::CallbackList<void()>::Subscription;
+
+ KeyedServiceShutdownNotifier();
+ ~KeyedServiceShutdownNotifier() override;
+
+ // Subscribe for a notification when the keyed services this object depends on
+ // (as defined by its factory) are shut down. The subscription object can be
+ // destroyed to unsubscribe.
+ scoped_ptr<Subscription> Subscribe(const base::Closure& callback);
+
+ private:
+ // KeyedService implementation:
+ void Shutdown() override;
+
+ base::CallbackList<void()> callback_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(KeyedServiceShutdownNotifier);
+};
+
+#endif // COMPONENTS_KEYED_SERVICE_CORE_KEYED_SERVICE_SHUTDOWN_NOTIFIER_H_
« no previous file with comments | « components/keyed_service/core/BUILD.gn ('k') | components/keyed_service/core/keyed_service_shutdown_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698