Commit 76e4425f authored by bauerb's avatar bauerb Committed by Commit bot

Add KeyedServiceShutdownNotifier for classes that depend on keyed services but...

Add KeyedServiceShutdownNotifier for classes that depend on keyed services but can't be keyed services themselves.

BUG=395391

Review URL: https://codereview.chromium.org/905703002

Cr-Commit-Position: refs/heads/master@{#315234}
parent a4820e5d
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
'keyed_service/core/keyed_service_export.h', 'keyed_service/core/keyed_service_export.h',
'keyed_service/core/keyed_service_factory.cc', 'keyed_service/core/keyed_service_factory.cc',
'keyed_service/core/keyed_service_factory.h', 'keyed_service/core/keyed_service_factory.h',
'keyed_service/core/keyed_service_shutdown_notifier.cc',
'keyed_service/core/keyed_service_shutdown_notifier.h',
'keyed_service/core/refcounted_keyed_service.cc', 'keyed_service/core/refcounted_keyed_service.cc',
'keyed_service/core/refcounted_keyed_service.h', 'keyed_service/core/refcounted_keyed_service.h',
'keyed_service/core/refcounted_keyed_service_factory.cc', 'keyed_service/core/refcounted_keyed_service_factory.cc',
...@@ -70,6 +72,8 @@ ...@@ -70,6 +72,8 @@
'keyed_service/content/browser_context_keyed_base_factory.cc', 'keyed_service/content/browser_context_keyed_base_factory.cc',
'keyed_service/content/browser_context_keyed_service_factory.cc', 'keyed_service/content/browser_context_keyed_service_factory.cc',
'keyed_service/content/browser_context_keyed_service_factory.h', 'keyed_service/content/browser_context_keyed_service_factory.h',
'keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.cc',
'keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h',
'keyed_service/content/refcounted_browser_context_keyed_service_factory.cc', 'keyed_service/content/refcounted_browser_context_keyed_service_factory.cc',
'keyed_service/content/refcounted_browser_context_keyed_service_factory.h', 'keyed_service/content/refcounted_browser_context_keyed_service_factory.h',
], ],
......
...@@ -13,6 +13,8 @@ component("content") { ...@@ -13,6 +13,8 @@ component("content") {
"browser_context_keyed_base_factory.cc", "browser_context_keyed_base_factory.cc",
"browser_context_keyed_service_factory.cc", "browser_context_keyed_service_factory.cc",
"browser_context_keyed_service_factory.h", "browser_context_keyed_service_factory.h",
"browser_context_keyed_service_shutdown_notifier_factory.cc",
"browser_context_keyed_service_shutdown_notifier_factory.h",
"refcounted_browser_context_keyed_service_factory.cc", "refcounted_browser_context_keyed_service_factory.cc",
"refcounted_browser_context_keyed_service_factory.h", "refcounted_browser_context_keyed_service_factory.h",
] ]
......
// 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.
#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
BrowserContextKeyedServiceShutdownNotifierFactory::
BrowserContextKeyedServiceShutdownNotifierFactory(const char* name)
: BrowserContextKeyedServiceFactory(
name,
BrowserContextDependencyManager::GetInstance()) {
}
BrowserContextKeyedServiceShutdownNotifierFactory::
~BrowserContextKeyedServiceShutdownNotifierFactory() {
}
KeyedServiceShutdownNotifier*
BrowserContextKeyedServiceShutdownNotifierFactory::Get(
content::BrowserContext* context) {
return static_cast<KeyedServiceShutdownNotifier*>(
GetServiceForBrowserContext(context, true));
}
KeyedService*
BrowserContextKeyedServiceShutdownNotifierFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new KeyedServiceShutdownNotifier;
}
content::BrowserContext*
BrowserContextKeyedServiceShutdownNotifierFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return context;
}
// 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_CONTENT_BROWSER_CONTEXT_KEYED_SERVICE_SHUTDOWN_NOTIFIER_FACTORY_H_
#define COMPONENTS_KEYED_SERVICE_CONTENT_BROWSER_CONTEXT_KEYED_SERVICE_SHUTDOWN_NOTIFIER_FACTORY_H_
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service_export.h"
class KeyedServiceShutdownNotifier;
// A base class for factories for KeyedServiceShutdownNotifier objects that are
// keyed on a BrowserContext.
// To use this class, create a singleton subclass and declare its dependencies
// in the constructor.
class KEYED_SERVICE_EXPORT BrowserContextKeyedServiceShutdownNotifierFactory
: public BrowserContextKeyedServiceFactory {
public:
KeyedServiceShutdownNotifier* Get(content::BrowserContext* context);
protected:
explicit BrowserContextKeyedServiceShutdownNotifierFactory(const char* name);
~BrowserContextKeyedServiceShutdownNotifierFactory() override;
private:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedServiceShutdownNotifierFactory);
};
#endif // COMPONENTS_KEYED_SERVICE_CONTENT_BROWSER_CONTEXT_KEYED_SERVICE_SHUTDOWN_NOTIFIER_FACTORY_H_
...@@ -17,6 +17,8 @@ component("core") { ...@@ -17,6 +17,8 @@ component("core") {
"keyed_service_export.h", "keyed_service_export.h",
"keyed_service_factory.cc", "keyed_service_factory.cc",
"keyed_service_factory.h", "keyed_service_factory.h",
"keyed_service_shutdown_notifier.cc",
"keyed_service_shutdown_notifier.h",
"refcounted_keyed_service.cc", "refcounted_keyed_service.cc",
"refcounted_keyed_service.h", "refcounted_keyed_service.h",
"refcounted_keyed_service_factory.cc", "refcounted_keyed_service_factory.cc",
......
// 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.
#include "components/keyed_service/core/keyed_service_export.h"
#include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
KeyedServiceShutdownNotifier::KeyedServiceShutdownNotifier() {
}
KeyedServiceShutdownNotifier::~KeyedServiceShutdownNotifier() {
}
scoped_ptr<base::CallbackList<void()>::Subscription>
KeyedServiceShutdownNotifier::Subscribe(const base::Closure& callback) {
return callback_list_.Add(callback);
}
void KeyedServiceShutdownNotifier::Shutdown() {
callback_list_.Notify();
}
// 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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment