diff options
author | sdefresne <sdefresne@chromium.org> | 2014-10-08 05:31:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-08 12:32:14 +0000 |
commit | 2eb633d03c8465bca5dbc634431cd6fb1f20570a (patch) | |
tree | 20597cb2d10e6850b648b3d77342ea89ac119fa1 | |
parent | 53973860013e1f085b3eab6995afc542e77ee585 (diff) | |
download | chromium_src-2eb633d03c8465bca5dbc634431cd6fb1f20570a.zip chromium_src-2eb633d03c8465bca5dbc634431cd6fb1f20570a.tar.gz chromium_src-2eb633d03c8465bca5dbc634431cd6fb1f20570a.tar.bz2 |
Refactor RefcountedBrowserContextKeyedService to be usable on iOS
Remove the dependency from RefcountedBrowserContextKeyedService on //content
and move it to //components/keyed_service/core so that it can be used by iOS.
Change the class constructor to receive a base::SingleThreadTaskRunner
instead of a content::BrowserThread::ID.
Rename the class to RefcountedKeyedService since it has no dependency on
content::BrowserContext.
BUG=419366
Review URL: https://codereview.chromium.org/631843002
Cr-Commit-Position: refs/heads/master@{#298687}
30 files changed, 134 insertions, 134 deletions
diff --git a/chrome/browser/autocomplete/shortcuts_backend.h b/chrome/browser/autocomplete/shortcuts_backend.h index 7eceb58..2f44364 100644 --- a/chrome/browser/autocomplete/shortcuts_backend.h +++ b/chrome/browser/autocomplete/shortcuts_backend.h @@ -18,7 +18,7 @@ #include "base/synchronization/lock.h" #include "base/time/time.h" #include "chrome/browser/history/shortcuts_database.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/omnibox/autocomplete_match.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -32,7 +32,7 @@ class ShortcutsDatabase; // This class manages the shortcut provider backend - access to database on the // db thread, etc. -class ShortcutsBackend : public RefcountedBrowserContextKeyedService, +class ShortcutsBackend : public RefcountedKeyedService, public content::NotificationObserver { public: typedef std::multimap<base::string16, @@ -96,7 +96,7 @@ class ShortcutsBackend : public RefcountedBrowserContextKeyedService, static history::ShortcutsDatabase::Shortcut::MatchCore MatchToMatchCore( const AutocompleteMatch& match, Profile* profile); - // RefcountedBrowserContextKeyedService: + // RefcountedKeyedService: virtual void ShutdownOnUIThread() OVERRIDE; // content::NotificationObserver: diff --git a/chrome/browser/autocomplete/shortcuts_backend_factory.cc b/chrome/browser/autocomplete/shortcuts_backend_factory.cc index 5753446..c819239 100644 --- a/chrome/browser/autocomplete/shortcuts_backend_factory.cc +++ b/chrome/browser/autocomplete/shortcuts_backend_factory.cc @@ -30,7 +30,7 @@ ShortcutsBackendFactory* ShortcutsBackendFactory::GetInstance() { } // static -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> ShortcutsBackendFactory::BuildProfileForTesting( content::BrowserContext* profile) { scoped_refptr<ShortcutsBackend> backend( @@ -41,7 +41,7 @@ ShortcutsBackendFactory::BuildProfileForTesting( } // static -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> ShortcutsBackendFactory::BuildProfileNoDatabaseForTesting( content::BrowserContext* profile) { scoped_refptr<ShortcutsBackend> backend( @@ -59,7 +59,7 @@ ShortcutsBackendFactory::ShortcutsBackendFactory() ShortcutsBackendFactory::~ShortcutsBackendFactory() {} -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> ShortcutsBackendFactory::BuildServiceInstanceFor( content::BrowserContext* profile) const { scoped_refptr<ShortcutsBackend> backend( diff --git a/chrome/browser/autocomplete/shortcuts_backend_factory.h b/chrome/browser/autocomplete/shortcuts_backend_factory.h index f9bc830..4a0a545 100644 --- a/chrome/browser/autocomplete/shortcuts_backend_factory.h +++ b/chrome/browser/autocomplete/shortcuts_backend_factory.h @@ -26,13 +26,13 @@ class ShortcutsBackendFactory static ShortcutsBackendFactory* GetInstance(); // Creates and returns a backend for testing purposes. - static scoped_refptr<RefcountedBrowserContextKeyedService> - BuildProfileForTesting(content::BrowserContext* profile); + static scoped_refptr<RefcountedKeyedService> BuildProfileForTesting( + content::BrowserContext* profile); // Creates and returns a backend but without creating its persistent database // for testing purposes. - static scoped_refptr<RefcountedBrowserContextKeyedService> - BuildProfileNoDatabaseForTesting(content::BrowserContext* profile); + static scoped_refptr<RefcountedKeyedService> BuildProfileNoDatabaseForTesting( + content::BrowserContext* profile); private: friend struct DefaultSingletonTraits<ShortcutsBackendFactory>; @@ -41,8 +41,8 @@ class ShortcutsBackendFactory virtual ~ShortcutsBackendFactory(); // BrowserContextKeyedServiceFactory: - virtual scoped_refptr<RefcountedBrowserContextKeyedService> - BuildServiceInstanceFor(content::BrowserContext* profile) const OVERRIDE; + virtual scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor( + content::BrowserContext* profile) const OVERRIDE; virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; }; diff --git a/chrome/browser/browsing_data/cookies_tree_model_unittest.cc b/chrome/browser/browsing_data/cookies_tree_model_unittest.cc index 3e2f6db..f04e32d 100644 --- a/chrome/browser/browsing_data/cookies_tree_model_unittest.cc +++ b/chrome/browser/browsing_data/cookies_tree_model_unittest.cc @@ -23,6 +23,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/mock_settings_observer.h" #include "chrome/test/base/testing_profile.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_types.h" #include "content/public/test/test_browser_thread_bundle.h" diff --git a/chrome/browser/content_settings/cookie_settings.cc b/chrome/browser/content_settings/cookie_settings.cc index 3bde74d..fad0eca 100644 --- a/chrome/browser/content_settings/cookie_settings.cc +++ b/chrome/browser/content_settings/cookie_settings.cc @@ -77,7 +77,7 @@ content::BrowserContext* CookieSettings::Factory::GetBrowserContextToUse( return chrome::GetBrowserContextRedirectedInIncognito(context); } -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> CookieSettings::Factory::BuildServiceInstanceFor( content::BrowserContext* context) const { Profile* profile = static_cast<Profile*>(context); diff --git a/chrome/browser/content_settings/cookie_settings.h b/chrome/browser/content_settings/cookie_settings.h index ed8edba..448b87a 100644 --- a/chrome/browser/content_settings/cookie_settings.h +++ b/chrome/browser/content_settings/cookie_settings.h @@ -14,8 +14,8 @@ #include "base/synchronization/lock.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "components/content_settings/core/common/content_settings.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" #include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" class ContentSettingsPattern; class CookieSettingsWrapper; @@ -26,7 +26,7 @@ class Profile; // A frontend to the cookie settings of |HostContentSettingsMap|. Handles // cookie-specific logic such as blocking third-party cookies. Written on the UI // thread and read on any thread. One instance per profile. -class CookieSettings : public RefcountedBrowserContextKeyedService { +class CookieSettings : public RefcountedKeyedService { public: CookieSettings( HostContentSettingsMap* host_content_settings_map, @@ -121,9 +121,8 @@ class CookieSettings : public RefcountedBrowserContextKeyedService { user_prefs::PrefRegistrySyncable* registry) OVERRIDE; virtual content::BrowserContext* GetBrowserContextToUse( content::BrowserContext* context) const OVERRIDE; - virtual scoped_refptr<RefcountedBrowserContextKeyedService> - BuildServiceInstanceFor( - content::BrowserContext* context) const OVERRIDE; + virtual scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor( + content::BrowserContext* context) const OVERRIDE; }; private: diff --git a/chrome/browser/extensions/api/dial/dial_api.cc b/chrome/browser/extensions/api/dial/dial_api.cc index bcc1124..9d7714e 100644 --- a/chrome/browser/extensions/api/dial/dial_api.cc +++ b/chrome/browser/extensions/api/dial/dial_api.cc @@ -35,7 +35,8 @@ namespace extensions { namespace dial = api::dial; DialAPI::DialAPI(Profile* profile) - : RefcountedBrowserContextKeyedService(BrowserThread::IO), + : RefcountedKeyedService( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)), profile_(profile) { EventRouter::Get(profile) ->RegisterObserver(this, dial::OnDeviceList::kEventName); diff --git a/chrome/browser/extensions/api/dial/dial_api.h b/chrome/browser/extensions/api/dial/dial_api.h index cc56b84..3305253 100644 --- a/chrome/browser/extensions/api/dial/dial_api.h +++ b/chrome/browser/extensions/api/dial/dial_api.h @@ -9,7 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/extensions/api/dial/dial_device_data.h" #include "chrome/browser/extensions/api/dial/dial_registry.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" #include "extensions/browser/api/async_api_function.h" #include "extensions/browser/event_router.h" @@ -21,7 +21,7 @@ class DialRegistry; // the DIAL registry. It takes care of creating the registry on the IO thread // and is an observer of the registry. It makes sure devices events are sent out // to extension listeners on the right thread. -class DialAPI : public RefcountedBrowserContextKeyedService, +class DialAPI : public RefcountedKeyedService, public EventRouter::Observer, public DialRegistry::Observer { public: @@ -39,7 +39,7 @@ class DialAPI : public RefcountedBrowserContextKeyedService, private: virtual ~DialAPI(); - // RefcountedBrowserContextKeyedService: + // RefcountedKeyedService: virtual void ShutdownOnUIThread() override; // EventRouter::Observer: diff --git a/chrome/browser/extensions/api/dial/dial_api_factory.cc b/chrome/browser/extensions/api/dial/dial_api_factory.cc index 63e2f70..192f808 100644 --- a/chrome/browser/extensions/api/dial/dial_api_factory.cc +++ b/chrome/browser/extensions/api/dial/dial_api_factory.cc @@ -31,9 +31,8 @@ DialAPIFactory::DialAPIFactory() : RefcountedBrowserContextKeyedServiceFactory( DialAPIFactory::~DialAPIFactory() { } -scoped_refptr<RefcountedBrowserContextKeyedService> - DialAPIFactory::BuildServiceInstanceFor( - content::BrowserContext* profile) const { +scoped_refptr<RefcountedKeyedService> DialAPIFactory::BuildServiceInstanceFor( + content::BrowserContext* profile) const { return scoped_refptr<DialAPI>(new DialAPI(static_cast<Profile*>(profile))); } diff --git a/chrome/browser/extensions/api/dial/dial_api_factory.h b/chrome/browser/extensions/api/dial/dial_api_factory.h index 8d64203..7cf6dab 100644 --- a/chrome/browser/extensions/api/dial/dial_api_factory.h +++ b/chrome/browser/extensions/api/dial/dial_api_factory.h @@ -26,8 +26,8 @@ class DialAPIFactory : public RefcountedBrowserContextKeyedServiceFactory { virtual ~DialAPIFactory(); // BrowserContextKeyedServiceFactory: - virtual scoped_refptr<RefcountedBrowserContextKeyedService> - BuildServiceInstanceFor(content::BrowserContext* profile) const override; + virtual scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor( + content::BrowserContext* profile) const override; virtual bool ServiceIsCreatedWithBrowserContext() const override; virtual bool ServiceIsNULLWhileTesting() const override; diff --git a/chrome/browser/plugins/plugin_prefs.h b/chrome/browser/plugins/plugin_prefs.h index 95a8152..6813207 100644 --- a/chrome/browser/plugins/plugin_prefs.h +++ b/chrome/browser/plugins/plugin_prefs.h @@ -15,7 +15,7 @@ #include "base/prefs/pref_service.h" #include "base/synchronization/lock.h" #include "chrome/browser/plugins/plugin_finder.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" class Profile; @@ -30,7 +30,7 @@ struct WebPluginInfo; // This class stores information about whether a plug-in or a plug-in group is // enabled or disabled. // Except where otherwise noted, it can be used on every thread. -class PluginPrefs : public RefcountedBrowserContextKeyedService { +class PluginPrefs : public RefcountedKeyedService { public: enum PolicyStatus { NO_POLICY = 0, // Neither enabled or disabled by policy. diff --git a/chrome/browser/plugins/plugin_prefs_factory.cc b/chrome/browser/plugins/plugin_prefs_factory.cc index 8b4119e..22b0f56 100644 --- a/chrome/browser/plugins/plugin_prefs_factory.cc +++ b/chrome/browser/plugins/plugin_prefs_factory.cc @@ -28,7 +28,7 @@ scoped_refptr<PluginPrefs> PluginPrefsFactory::GetPrefsForProfile( } // static -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> PluginPrefsFactory::CreateForTestingProfile(content::BrowserContext* profile) { return static_cast<PluginPrefs*>( GetInstance()->BuildServiceInstanceFor(profile).get()); @@ -41,7 +41,7 @@ PluginPrefsFactory::PluginPrefsFactory() PluginPrefsFactory::~PluginPrefsFactory() {} -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> PluginPrefsFactory::BuildServiceInstanceFor( content::BrowserContext* context) const { Profile* profile = static_cast<Profile*>(context); diff --git a/chrome/browser/plugins/plugin_prefs_factory.h b/chrome/browser/plugins/plugin_prefs_factory.h index ed09efa..4ad3f48 100644 --- a/chrome/browser/plugins/plugin_prefs_factory.h +++ b/chrome/browser/plugins/plugin_prefs_factory.h @@ -23,15 +23,15 @@ class PluginPrefsFactory : public RefcountedBrowserContextKeyedServiceFactory { friend struct DefaultSingletonTraits<PluginPrefsFactory>; // Helper method for PluginPrefs::GetForTestingProfile. - static scoped_refptr<RefcountedBrowserContextKeyedService> - CreateForTestingProfile(content::BrowserContext* profile); + static scoped_refptr<RefcountedKeyedService> CreateForTestingProfile( + content::BrowserContext* profile); PluginPrefsFactory(); virtual ~PluginPrefsFactory(); // RefcountedBrowserContextKeyedServiceFactory methods: - virtual scoped_refptr<RefcountedBrowserContextKeyedService> - BuildServiceInstanceFor(content::BrowserContext* context) const override; + virtual scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor( + content::BrowserContext* context) const override; // BrowserContextKeyedServiceFactory methods: virtual void RegisterProfilePrefs( diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc index 0ed17e0..5468d20 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc @@ -23,7 +23,7 @@ #include "chrome/test/base/profile_mock.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/test/bookmark_test_helpers.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/sync_driver/change_processor_mock.h" #include "components/sync_driver/data_type_controller_mock.h" #include "components/sync_driver/model_associator_mock.h" diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index 4445809..3826287 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -47,7 +47,7 @@ #include "components/history/core/browser/history_types.h" #include "components/invalidation/invalidation_service.h" #include "components/invalidation/profile_invalidation_provider.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/signin/core/browser/signin_manager.h" #include "components/sync_driver/data_type_error_handler_mock.h" #include "content/public/browser/notification_service.h" diff --git a/chrome/browser/thumbnails/thumbnail_service.h b/chrome/browser/thumbnails/thumbnail_service.h index 4144436..688a50f 100644 --- a/chrome/browser/thumbnails/thumbnail_service.h +++ b/chrome/browser/thumbnails/thumbnail_service.h @@ -6,7 +6,7 @@ #define CHROME_BROWSER_THUMBNAILS_THUMBNAIL_SERVICE_H_ #include "components/history/core/common/thumbnail_score.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" #include "ui/gfx/image/image.h" class GURL; @@ -23,7 +23,7 @@ struct ThumbnailingContext; // An interface abstracting access to thumbnails. Intended as a temporary // bridge facilitating switch from TopSites as the thumbnail source to a more // robust way of handling these artefacts. -class ThumbnailService : public RefcountedBrowserContextKeyedService { +class ThumbnailService : public RefcountedKeyedService { public: // Sets the given thumbnail for the given URL. Returns true if the thumbnail // was updated. False means either the URL wasn't known to us, or we felt diff --git a/chrome/browser/thumbnails/thumbnail_service_factory.cc b/chrome/browser/thumbnails/thumbnail_service_factory.cc index dec7910..70a055d 100644 --- a/chrome/browser/thumbnails/thumbnail_service_factory.cc +++ b/chrome/browser/thumbnails/thumbnail_service_factory.cc @@ -33,9 +33,9 @@ ThumbnailServiceFactory* ThumbnailServiceFactory::GetInstance() { return Singleton<ThumbnailServiceFactory>::get(); } -scoped_refptr<RefcountedBrowserContextKeyedService> - ThumbnailServiceFactory::BuildServiceInstanceFor( - content::BrowserContext* profile) const { - return scoped_refptr<RefcountedBrowserContextKeyedService>( +scoped_refptr<RefcountedKeyedService> +ThumbnailServiceFactory::BuildServiceInstanceFor( + content::BrowserContext* profile) const { + return scoped_refptr<RefcountedKeyedService>( new ThumbnailServiceImpl(static_cast<Profile*>(profile))); } diff --git a/chrome/browser/thumbnails/thumbnail_service_factory.h b/chrome/browser/thumbnails/thumbnail_service_factory.h index 23596d0..0a27124 100644 --- a/chrome/browser/thumbnails/thumbnail_service_factory.h +++ b/chrome/browser/thumbnails/thumbnail_service_factory.h @@ -23,7 +23,7 @@ class ThumbnailServiceFactory // ThumbnailService (for example, if |profile| is incognito). // Depending on the settings, the implementation of the service interface // can be provided either by TopSites (stored in the profile itself) or - // be an instance of a real RefcountedBrowserContextKeyedService + // be an instance of a real RefcountedKeyedService // implementation. static scoped_refptr<thumbnails::ThumbnailService> GetForProfile( Profile* profile); @@ -37,8 +37,8 @@ class ThumbnailServiceFactory virtual ~ThumbnailServiceFactory(); // BrowserContextKeyedServiceFactory: - virtual scoped_refptr<RefcountedBrowserContextKeyedService> - BuildServiceInstanceFor(content::BrowserContext* profile) const override; + virtual scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor( + content::BrowserContext* profile) const override; DISALLOW_COPY_AND_ASSIGN(ThumbnailServiceFactory); }; diff --git a/chrome/browser/thumbnails/thumbnail_service_impl.cc b/chrome/browser/thumbnails/thumbnail_service_impl.cc index a9bc4d6..8f572d3 100644 --- a/chrome/browser/thumbnails/thumbnail_service_impl.cc +++ b/chrome/browser/thumbnails/thumbnail_service_impl.cc @@ -13,6 +13,7 @@ #include "chrome/browser/thumbnails/thumbnailing_context.h" #include "chrome/common/chrome_switches.h" #include "components/search/search.h" +#include "content/public/browser/browser_thread.h" #include "url/gurl.h" using content::BrowserThread; diff --git a/chrome/browser/thumbnails/thumbnail_service_impl.h b/chrome/browser/thumbnails/thumbnail_service_impl.h index 2dd3956..84067ec 100644 --- a/chrome/browser/thumbnails/thumbnail_service_impl.h +++ b/chrome/browser/thumbnails/thumbnail_service_impl.h @@ -33,7 +33,7 @@ class ThumbnailServiceImpl : public ThumbnailService { virtual void AddForcedURL(const GURL& url) override; virtual bool ShouldAcquirePageThumbnail(const GURL& url) override; - // Implementation of RefcountedBrowserContextKeyedService. + // Implementation of RefcountedKeyedService. virtual void ShutdownOnUIThread() override; private: diff --git a/chrome/browser/thumbnails/thumbnail_tab_helper.cc b/chrome/browser/thumbnails/thumbnail_tab_helper.cc index 30d692f..e360040 100644 --- a/chrome/browser/thumbnails/thumbnail_tab_helper.cc +++ b/chrome/browser/thumbnails/thumbnail_tab_helper.cc @@ -10,6 +10,7 @@ #include "chrome/browser/thumbnails/thumbnail_service_factory.h" #include "chrome/browser/thumbnails/thumbnailing_algorithm.h" #include "chrome/browser/thumbnails/thumbnailing_context.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.cc b/chrome/browser/ui/webui/ntp/thumbnail_source.cc index 64d6f96..d5c3268 100644 --- a/chrome/browser/ui/webui/ntp/thumbnail_source.cc +++ b/chrome/browser/ui/webui/ntp/thumbnail_source.cc @@ -15,8 +15,6 @@ #include "net/url_request/url_request.h" #include "url/gurl.h" -using content::BrowserThread; - // Set ThumbnailService now as Profile isn't thread safe. ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails) : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), diff --git a/components/keyed_service.gypi b/components/keyed_service.gypi index 2f0ceef..4a11114 100644 --- a/components/keyed_service.gypi +++ b/components/keyed_service.gypi @@ -26,6 +26,8 @@ 'keyed_service/core/keyed_service.cc', 'keyed_service/core/keyed_service.h', 'keyed_service/core/keyed_service_export.h', + 'keyed_service/core/refcounted_keyed_service.cc', + 'keyed_service/core/refcounted_keyed_service.h', ], }, ], @@ -59,9 +61,8 @@ '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.h', - 'keyed_service/content/refcounted_browser_context_keyed_service.cc', - 'keyed_service/content/refcounted_browser_context_keyed_service.h', 'keyed_service/content/refcounted_browser_context_keyed_service_factory.cc', + 'keyed_service/content/refcounted_browser_context_keyed_service_factory.h', ], }], }], diff --git a/components/keyed_service/content/BUILD.gn b/components/keyed_service/content/BUILD.gn index 91caa34..a445307 100644 --- a/components/keyed_service/content/BUILD.gn +++ b/components/keyed_service/content/BUILD.gn @@ -13,9 +13,8 @@ component("content") { "browser_context_keyed_base_factory.cc", "browser_context_keyed_service_factory.cc", "browser_context_keyed_service_factory.h", - "refcounted_browser_context_keyed_service.cc", - "refcounted_browser_context_keyed_service.h", "refcounted_browser_context_keyed_service_factory.cc", + "refcounted_browser_context_keyed_service_factory.h", ] defines = [ "KEYED_SERVICE_IMPLEMENTATION" ] diff --git a/components/keyed_service/content/refcounted_browser_context_keyed_service.cc b/components/keyed_service/content/refcounted_browser_context_keyed_service.cc deleted file mode 100644 index 6955846..0000000 --- a/components/keyed_service/content/refcounted_browser_context_keyed_service.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 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/refcounted_browser_context_keyed_service.h" - -namespace impl { - -// static -void RefcountedBrowserContextKeyedServiceTraits::Destruct( - const RefcountedBrowserContextKeyedService* obj) { - if (obj->requires_destruction_on_thread_ && - !content::BrowserThread::CurrentlyOn(obj->thread_id_)) { - content::BrowserThread::DeleteSoon(obj->thread_id_, FROM_HERE, obj); - } else { - delete obj; - } -} - -} // namespace impl - -RefcountedBrowserContextKeyedService::RefcountedBrowserContextKeyedService() - : requires_destruction_on_thread_(false), - thread_id_(content::BrowserThread::UI) {} - -RefcountedBrowserContextKeyedService::RefcountedBrowserContextKeyedService( - const content::BrowserThread::ID thread_id) - : requires_destruction_on_thread_(true), thread_id_(thread_id) {} - -RefcountedBrowserContextKeyedService::~RefcountedBrowserContextKeyedService() {} diff --git a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc index f3952bf..ac0926e 100644 --- a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc +++ b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc @@ -6,8 +6,8 @@ #include "base/logging.h" #include "base/stl_util.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" #include "components/keyed_service/core/keyed_service.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" #include "content/public/browser/browser_context.h" void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory( @@ -31,7 +31,7 @@ void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory( testing_factories_[context] = testing_factory; } -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> RefcountedBrowserContextKeyedServiceFactory::SetTestingFactoryAndUse( content::BrowserContext* context, TestingFactoryFunction testing_factory) { @@ -51,7 +51,7 @@ RefcountedBrowserContextKeyedServiceFactory:: DCHECK(mapping_.empty()); } -scoped_refptr<RefcountedBrowserContextKeyedService> +scoped_refptr<RefcountedKeyedService> RefcountedBrowserContextKeyedServiceFactory::GetServiceForBrowserContext( content::BrowserContext* context, bool create) { @@ -72,7 +72,7 @@ RefcountedBrowserContextKeyedServiceFactory::GetServiceForBrowserContext( // Create new object. // Check to see if we have a per-BrowserContext testing factory that we should // use instead of default behavior. - scoped_refptr<RefcountedBrowserContextKeyedService> service; + scoped_refptr<RefcountedKeyedService> service; BrowserContextOverriddenTestingFunctions::const_iterator jt = testing_factories_.find(context); if (jt != testing_factories_.end()) { @@ -91,7 +91,7 @@ RefcountedBrowserContextKeyedServiceFactory::GetServiceForBrowserContext( void RefcountedBrowserContextKeyedServiceFactory::Associate( content::BrowserContext* context, - const scoped_refptr<RefcountedBrowserContextKeyedService>& service) { + const scoped_refptr<RefcountedKeyedService>& service) { DCHECK(!ContainsKey(mapping_, context)); mapping_.insert(std::make_pair(context, service)); } diff --git a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h index 3898e20..22e7d6b 100644 --- a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h +++ b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h @@ -9,10 +9,10 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h" -#include "components/keyed_service/content/refcounted_browser_context_keyed_service.h" #include "components/keyed_service/core/keyed_service_export.h" +#include "components/keyed_service/core/refcounted_keyed_service.h" -class RefcountedBrowserContextKeyedService; +class RefcountedKeyedService; namespace content { class BrowserContext; @@ -24,17 +24,17 @@ class BrowserContext; // While the factory returns RefcountedThreadSafe<>s, the factory itself is a // base::NotThreadSafe. Only call methods on this object on the UI thread. // -// Implementers of RefcountedBrowserContextKeyedService should note that -// we guarantee that ShutdownOnUIThread() is called on the UI thread, but actual -// object destruction can happen anywhere. +// Implementers of RefcountedKeyedService should note that we guarantee that +// ShutdownOnUIThread() is called on the UI thread, but actual object +// destruction can happen anywhere. class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory : public BrowserContextKeyedBaseFactory { public: // A function that supplies the instance of a KeyedService for a given // BrowserContext. This is used primarily for testing, where we want to feed // a specific mock into the BCKSF system. - typedef scoped_refptr<RefcountedBrowserContextKeyedService>( - *TestingFactoryFunction)(content::BrowserContext* context); + typedef scoped_refptr<RefcountedKeyedService>(*TestingFactoryFunction)( + content::BrowserContext* context); // Associates |factory| with |context| so that |factory| is used to create // the KeyedService when requested. |factory| can be NULL to signal that @@ -46,7 +46,7 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory // Associates |factory| with |context| and immediately returns the created // KeyedService. Since the factory will be used immediately, it may not be // NULL. - scoped_refptr<RefcountedBrowserContextKeyedService> SetTestingFactoryAndUse( + scoped_refptr<RefcountedKeyedService> SetTestingFactoryAndUse( content::BrowserContext* context, TestingFactoryFunction factory); @@ -56,20 +56,19 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory BrowserContextDependencyManager* manager); virtual ~RefcountedBrowserContextKeyedServiceFactory(); - scoped_refptr<RefcountedBrowserContextKeyedService> - GetServiceForBrowserContext(content::BrowserContext* context, - bool create); + scoped_refptr<RefcountedKeyedService> GetServiceForBrowserContext( + content::BrowserContext* context, + bool create); // Maps |context| to |service| with debug checks to prevent duplication. - void Associate( - content::BrowserContext* context, - const scoped_refptr<RefcountedBrowserContextKeyedService>& service); + void Associate(content::BrowserContext* context, + const scoped_refptr<RefcountedKeyedService>& service); // All subclasses of RefcountedBrowserContextKeyedServiceFactory must return - // a RefcountedBrowserContextKeyedService instead of just + // a RefcountedKeyedService instead of just // a BrowserContextKeyedBase. - virtual scoped_refptr<RefcountedBrowserContextKeyedService> - BuildServiceInstanceFor(content::BrowserContext* context) const = 0; + virtual scoped_refptr<RefcountedKeyedService> BuildServiceInstanceFor( + content::BrowserContext* context) const = 0; virtual void BrowserContextShutdown(content::BrowserContext* context) override; @@ -82,8 +81,7 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory private: typedef std::map<content::BrowserContext*, - scoped_refptr<RefcountedBrowserContextKeyedService> > - RefCountedStorage; + scoped_refptr<RefcountedKeyedService>> RefCountedStorage; typedef std::map<content::BrowserContext*, TestingFactoryFunction> BrowserContextOverriddenTestingFunctions; diff --git a/components/keyed_service/core/BUILD.gn b/components/keyed_service/core/BUILD.gn index 4232619..bc36aaa 100644 --- a/components/keyed_service/core/BUILD.gn +++ b/components/keyed_service/core/BUILD.gn @@ -11,6 +11,8 @@ component("core") { "keyed_service.cc", "keyed_service.h", "keyed_service_export.h", + "refcounted_keyed_service.cc", + "refcounted_keyed_service.h", ] defines = [ "KEYED_SERVICE_IMPLEMENTATION" ] diff --git a/components/keyed_service/core/refcounted_keyed_service.cc b/components/keyed_service/core/refcounted_keyed_service.cc new file mode 100644 index 0000000..d5ff3f9 --- /dev/null +++ b/components/keyed_service/core/refcounted_keyed_service.cc @@ -0,0 +1,33 @@ +// Copyright 2014 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/refcounted_keyed_service.h" + +#include "base/location.h" +#include "base/thread_task_runner_handle.h" + +namespace impl { + +// static +void RefcountedKeyedServiceTraits::Destruct(const RefcountedKeyedService* obj) { + if (obj->task_runner_.get() != nullptr && + obj->task_runner_.get() != base::ThreadTaskRunnerHandle::Get()) { + obj->task_runner_->DeleteSoon(FROM_HERE, obj); + } else { + delete obj; + } +} + +} // namespace impl + +RefcountedKeyedService::RefcountedKeyedService() : task_runner_(nullptr) { +} + +RefcountedKeyedService::RefcountedKeyedService( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) + : task_runner_(task_runner) { +} + +RefcountedKeyedService::~RefcountedKeyedService() { +} diff --git a/components/keyed_service/content/refcounted_browser_context_keyed_service.h b/components/keyed_service/core/refcounted_keyed_service.h index 1382a87..31815d6 100644 --- a/components/keyed_service/content/refcounted_browser_context_keyed_service.h +++ b/components/keyed_service/core/refcounted_keyed_service.h @@ -2,20 +2,20 @@ // 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_REFCOUNTED_BROWSER_CONTEXT_KEYED_SERVICE_H_ -#define COMPONENTS_KEYED_SERVICE_CONTENT_REFCOUNTED_BROWSER_CONTEXT_KEYED_SERVICE_H_ +#ifndef COMPONENTS_KEYED_SERVICE_CORE_REFCOUNTED_KEYED_SERVICE_H_ +#define COMPONENTS_KEYED_SERVICE_CORE_REFCOUNTED_KEYED_SERVICE_H_ #include "base/memory/ref_counted.h" #include "base/sequenced_task_runner_helpers.h" +#include "base/single_thread_task_runner.h" #include "components/keyed_service/core/keyed_service_export.h" -#include "content/public/browser/browser_thread.h" -class RefcountedBrowserContextKeyedService; +class RefcountedKeyedService; namespace impl { -struct KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceTraits { - static void Destruct(const RefcountedBrowserContextKeyedService* obj); +struct KEYED_SERVICE_EXPORT RefcountedKeyedServiceTraits { + static void Destruct(const RefcountedKeyedService* obj); }; } // namespace impl @@ -29,14 +29,12 @@ struct KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceTraits { // be after the corresponding BrowserContext has been destroyed. // // Optionally, if you initialize your service with the constructor that takes a -// thread ID, your service will be deleted on that thread. We can't use -// content::DeleteOnThread<> directly because -// RefcountedBrowserContextKeyedService must be one type that -// RefcountedBrowserContextKeyedServiceFactory can use. -class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedService - : public base::RefCountedThreadSafe< - RefcountedBrowserContextKeyedService, - impl::RefcountedBrowserContextKeyedServiceTraits> { +// single thread task runner, your service will be deleted on that thread. We +// can't use content::DeleteOnThread<> directly because RefcountedKeyedService +// must not depend on //content. +class KEYED_SERVICE_EXPORT RefcountedKeyedService + : public base::RefCountedThreadSafe<RefcountedKeyedService, + impl::RefcountedKeyedServiceTraits> { public: // Unlike KeyedService, ShutdownOnUI is not optional. You must do something // to drop references during the first pass Shutdown() because this is the @@ -48,28 +46,27 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedService protected: // If your service does not need to be deleted on a specific thread, use the // default constructor. - RefcountedBrowserContextKeyedService(); + RefcountedKeyedService(); // If you need your service to be deleted on a specific thread (for example, // you're converting a service that used content::DeleteOnThread<IO>), then - // use this constructor with the ID of the thread. - explicit RefcountedBrowserContextKeyedService( - const content::BrowserThread::ID thread_id); + // use this constructor with a reference to the SingleThreadTaskRunner (you + // can get it from content::BrowserThread::GetMessageLoopProxyForThread). + explicit RefcountedKeyedService( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); // The second pass destruction can happen anywhere unless you specify which // thread this service must be destroyed on by using the second constructor. - virtual ~RefcountedBrowserContextKeyedService(); + virtual ~RefcountedKeyedService(); private: - friend struct impl::RefcountedBrowserContextKeyedServiceTraits; - friend class base::DeleteHelper<RefcountedBrowserContextKeyedService>; - friend class base::RefCountedThreadSafe< - RefcountedBrowserContextKeyedService, - impl::RefcountedBrowserContextKeyedServiceTraits>; + friend struct impl::RefcountedKeyedServiceTraits; + friend class base::DeleteHelper<RefcountedKeyedService>; + friend class base::RefCountedThreadSafe<RefcountedKeyedService, + impl::RefcountedKeyedServiceTraits>; // Do we have to delete this object on a specific thread? - bool requires_destruction_on_thread_; - content::BrowserThread::ID thread_id_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; }; -#endif // COMPONENTS_KEYED_SERVICE_CONTENT_REFCOUNTED_BROWSER_CONTEXT_KEYED_SERVICE_H_ +#endif // COMPONENTS_KEYED_SERVICE_CORE_REFCOUNTED_KEYED_SERVICE_H_ |