Skip to content

Commit

Permalink
Migration of chrome/ BrowserContextKeyedServiceFactory to ProfileKeye…
Browse files Browse the repository at this point in the history
…dServiceFactory Part 5

Bug: 1284664
Change-Id: I7a906be333448bd5c28801b0542db29bdae3c17a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3802733
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Ryan Sultanem <rsult@google.com>
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1034425}
  • Loading branch information
Ryan Sultanem authored and Chromium LUCI CQ committed Aug 12, 2022
1 parent b3b422e commit 2133889
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 122 deletions.
13 changes: 3 additions & 10 deletions chrome/browser/autofill/personal_data_manager_factory.cc
Expand Up @@ -9,15 +9,13 @@
#include "chrome/browser/autofill/strike_database_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/web_data_service_factory.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/strike_database.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/sync/base/command_line_switches.h"
#include "components/variations/service/variations_service.h"

Expand Down Expand Up @@ -57,9 +55,9 @@ PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
}

PersonalDataManagerFactory::PersonalDataManagerFactory()
: BrowserContextKeyedServiceFactory(
"PersonalDataManager",
BrowserContextDependencyManager::GetInstance()) {
: ProfileKeyedServiceFactory(
"PersonalDataManager",
ProfileSelections::BuildForRegularAndIncognito()) {
DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(HistoryServiceFactory::GetInstance());
DependsOn(WebDataServiceFactory::GetInstance());
Expand Down Expand Up @@ -100,9 +98,4 @@ KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor(
return BuildPersonalDataManager(context);
}

content::BrowserContext* PersonalDataManagerFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}

} // namespace autofill
8 changes: 3 additions & 5 deletions chrome/browser/autofill/personal_data_manager_factory.h
Expand Up @@ -5,13 +5,13 @@
#ifndef CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_FACTORY_H_
#define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_FACTORY_H_

#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

namespace base {
template <typename T> struct DefaultSingletonTraits;
}

class KeyedService;
class Profile;

namespace autofill {
Expand All @@ -22,7 +22,7 @@ class PersonalDataManager;
// Profiles.
// Listens for the Profile's destruction notification and cleans up the
// associated PersonalDataManager.
class PersonalDataManagerFactory : public BrowserContextKeyedServiceFactory {
class PersonalDataManagerFactory : public ProfileKeyedServiceFactory {
public:
// Returns the PersonalDataManager for |profile|, creating it if it is not
// yet created.
Expand All @@ -47,8 +47,6 @@ class PersonalDataManagerFactory : public BrowserContextKeyedServiceFactory {
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};

} // namespace autofill
Expand Down
7 changes: 1 addition & 6 deletions chrome/browser/autofill/strike_database_factory.cc
Expand Up @@ -5,10 +5,8 @@
#include "chrome/browser/autofill/strike_database_factory.h"

#include "base/memory/singleton.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/autofill/core/browser/strike_database.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/storage_partition.h"

namespace autofill {
Expand All @@ -25,10 +23,7 @@ StrikeDatabaseFactory* StrikeDatabaseFactory::GetInstance() {
}

StrikeDatabaseFactory::StrikeDatabaseFactory()
: BrowserContextKeyedServiceFactory(
"AutofillStrikeDatabase",
BrowserContextDependencyManager::GetInstance()) {
}
: ProfileKeyedServiceFactory("AutofillStrikeDatabase") {}

StrikeDatabaseFactory::~StrikeDatabaseFactory() = default;

Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/autofill/strike_database_factory.h
Expand Up @@ -5,8 +5,7 @@
#ifndef CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_
#define CHROME_BROWSER_AUTOFILL_STRIKE_DATABASE_FACTORY_H_

#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

namespace base {
template <typename T>
Expand All @@ -21,7 +20,7 @@ class StrikeDatabase;

// Singleton that owns all StrikeDatabases and associates them with
// Profiles.
class StrikeDatabaseFactory : public BrowserContextKeyedServiceFactory {
class StrikeDatabaseFactory : public ProfileKeyedServiceFactory {
public:
// Returns the StrikeDatabase for |profile|, creating it if it is not
// yet created.
Expand Down
Expand Up @@ -47,6 +47,9 @@ std::string CommonDependenciesChrome::GetCountryCode() const {

PersonalDataManager* CommonDependenciesChrome::GetPersonalDataManager(
content::BrowserContext* browser_context) const {
if (!browser_context)
return nullptr;

return autofill::PersonalDataManagerFactory::GetForBrowserContext(
browser_context);
}
Expand Down
12 changes: 2 additions & 10 deletions chrome/browser/background/background_contents_service_factory.cc
Expand Up @@ -7,10 +7,8 @@
#include "base/command_line.h"
#include "chrome/browser/background/background_contents_service.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "extensions/browser/extension_host_registry.h"
Expand All @@ -30,9 +28,9 @@ BackgroundContentsServiceFactory::GetInstance() {
}

BackgroundContentsServiceFactory::BackgroundContentsServiceFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"BackgroundContentsService",
BrowserContextDependencyManager::GetInstance()) {
ProfileSelections::BuildForRegularAndIncognito()) {
DependsOn(extensions::ExtensionRegistryFactory::GetInstance());
DependsOn(extensions::ExtensionSystemFactory::GetInstance());
DependsOn(extensions::ExtensionHostRegistry::GetFactory());
Expand All @@ -51,12 +49,6 @@ void BackgroundContentsServiceFactory::RegisterProfilePrefs(
user_prefs->RegisterDictionaryPref(prefs::kRegisteredBackgroundContents);
}

content::BrowserContext*
BackgroundContentsServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}

bool BackgroundContentsServiceFactory::ServiceIsCreatedWithBrowserContext()
const {
return true;
Expand Down
Expand Up @@ -6,16 +6,15 @@
#define CHROME_BROWSER_BACKGROUND_BACKGROUND_CONTENTS_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

class BackgroundContentsService;
class Profile;

// Singleton that owns all BackgroundContentsServices and associates them with
// Profiles. Listens for the Profile's destruction notification and cleans up
// the associated BackgroundContentsService.
class BackgroundContentsServiceFactory
: public BrowserContextKeyedServiceFactory {
class BackgroundContentsServiceFactory : public ProfileKeyedServiceFactory {
public:
static BackgroundContentsService* GetForProfile(Profile* profile);

Expand All @@ -37,8 +36,6 @@ class BackgroundContentsServiceFactory
content::BrowserContext* profile) const override;
void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
};

Expand Down
Expand Up @@ -10,9 +10,7 @@
#include "chrome/browser/download/background_download_service_factory.h"
#include "chrome/browser/metrics/ukm_background_recorder_service.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/background_fetch_delegate.h"

// static
Expand All @@ -28,9 +26,9 @@ BackgroundFetchDelegateFactory* BackgroundFetchDelegateFactory::GetInstance() {
}

BackgroundFetchDelegateFactory::BackgroundFetchDelegateFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"BackgroundFetchService",
BrowserContextDependencyManager::GetInstance()) {
ProfileSelections::BuildForRegularAndIncognito()) {
DependsOn(BackgroundDownloadServiceFactory::GetInstance());
DependsOn(HostContentSettingsMapFactory::GetInstance());
DependsOn(OfflineContentAggregatorFactory::GetInstance());
Expand All @@ -43,8 +41,3 @@ KeyedService* BackgroundFetchDelegateFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new BackgroundFetchDelegateImpl(Profile::FromBrowserContext(context));
}

content::BrowserContext* BackgroundFetchDelegateFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
Expand Up @@ -6,13 +6,12 @@
#define CHROME_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DELEGATE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

class BackgroundFetchDelegateImpl;
class Profile;

class BackgroundFetchDelegateFactory
: public BrowserContextKeyedServiceFactory {
class BackgroundFetchDelegateFactory : public ProfileKeyedServiceFactory {
public:
static BackgroundFetchDelegateImpl* GetForProfile(Profile* profile);
static BackgroundFetchDelegateFactory* GetInstance();
Expand All @@ -30,8 +29,6 @@ class BackgroundFetchDelegateFactory

KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};

#endif // CHROME_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DELEGATE_FACTORY_H_
Expand Up @@ -7,10 +7,8 @@
#include "chrome/browser/background_sync/background_sync_delegate_impl.h"
#include "chrome/browser/engagement/site_engagement_service_factory.h"
#include "chrome/browser/metrics/ukm_background_recorder_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/background_sync/background_sync_controller_impl.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

// static
BackgroundSyncControllerImpl* BackgroundSyncControllerFactory::GetForProfile(
Expand All @@ -26,9 +24,9 @@ BackgroundSyncControllerFactory::GetInstance() {
}

BackgroundSyncControllerFactory::BackgroundSyncControllerFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"BackgroundSyncService",
BrowserContextDependencyManager::GetInstance()) {
ProfileSelections::BuildForRegularAndIncognito()) {
DependsOn(ukm::UkmBackgroundRecorderFactory::GetInstance());
DependsOn(site_engagement::SiteEngagementServiceFactory::GetInstance());
}
Expand All @@ -41,9 +39,3 @@ KeyedService* BackgroundSyncControllerFactory::BuildServiceInstanceFor(
context, std::make_unique<BackgroundSyncDelegateImpl>(
Profile::FromBrowserContext(context)));
}

content::BrowserContext*
BackgroundSyncControllerFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
Expand Up @@ -6,13 +6,12 @@
#define CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

class BackgroundSyncControllerImpl;
class Profile;

class BackgroundSyncControllerFactory
: public BrowserContextKeyedServiceFactory {
class BackgroundSyncControllerFactory : public ProfileKeyedServiceFactory {
public:
static BackgroundSyncControllerImpl* GetForProfile(Profile* profile);
static BackgroundSyncControllerFactory* GetInstance();
Expand All @@ -31,8 +30,6 @@ class BackgroundSyncControllerFactory
// BrowserContextKeyedServiceFactory methods:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};

#endif // CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_FACTORY_H_
5 changes: 1 addition & 4 deletions chrome/browser/badging/badge_manager_factory.cc
Expand Up @@ -12,7 +12,6 @@
#include "chrome/browser/badging/badge_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/web_app_provider_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/prefs/pref_service.h"

namespace badging {
Expand All @@ -29,9 +28,7 @@ BadgeManagerFactory* BadgeManagerFactory::GetInstance() {
}

BadgeManagerFactory::BadgeManagerFactory()
: BrowserContextKeyedServiceFactory(
"BadgeManager",
BrowserContextDependencyManager::GetInstance()) {
: ProfileKeyedServiceFactory("BadgeManager") {
DependsOn(web_app::WebAppProviderFactory::GetInstance());
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/badging/badge_manager_factory.h
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_BADGING_BADGE_MANAGER_FACTORY_H_
#define CHROME_BROWSER_BADGING_BADGE_MANAGER_FACTORY_H_

#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

namespace base {
template <typename T>
Expand All @@ -19,7 +19,7 @@ namespace badging {
class BadgeManager;

// Singleton that provides access to Profile specific BadgeManagers.
class BadgeManagerFactory : public BrowserContextKeyedServiceFactory {
class BadgeManagerFactory : public ProfileKeyedServiceFactory {
public:
// Gets the BadgeManager for the current profile. |nullptr| for guest and
// incognito profiles.
Expand Down
Expand Up @@ -5,7 +5,6 @@

#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

/// Factory
BitmapFetcherService* BitmapFetcherServiceFactory::GetForBrowserContext(
Expand All @@ -20,10 +19,7 @@ BitmapFetcherServiceFactory* BitmapFetcherServiceFactory::GetInstance() {
}

BitmapFetcherServiceFactory::BitmapFetcherServiceFactory()
: BrowserContextKeyedServiceFactory(
"BitmapFetcherService",
BrowserContextDependencyManager::GetInstance()) {
}
: ProfileKeyedServiceFactory("BitmapFetcherService") {}

BitmapFetcherServiceFactory::~BitmapFetcherServiceFactory() {
}
Expand Down
Expand Up @@ -6,11 +6,11 @@
#define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

class BitmapFetcherService;

class BitmapFetcherServiceFactory : BrowserContextKeyedServiceFactory {
class BitmapFetcherServiceFactory : ProfileKeyedServiceFactory {
public:
// TODO(groby): Maybe make this GetForProfile?
static BitmapFetcherService* GetForBrowserContext(
Expand Down

0 comments on commit 2133889

Please sign in to comment.