Skip to content

Commit

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

Bug: 1284664
Change-Id: Ief187d7d9943b9405e01fc38c48442b5718f680b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3805659
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Ryan Sultanem <rsult@google.com>
Cr-Commit-Position: refs/heads/main@{#1037860}
  • Loading branch information
Ryan Sultanem authored and Chromium LUCI CQ committed Aug 22, 2022
1 parent 9142caa commit 4f357b6
Show file tree
Hide file tree
Showing 38 changed files with 74 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/ash/calendar/calendar_keyed_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_manager/user.h"

namespace ash {
Expand All @@ -21,9 +20,7 @@ CalendarKeyedServiceFactory* CalendarKeyedServiceFactory::GetInstance() {
}

CalendarKeyedServiceFactory::CalendarKeyedServiceFactory()
: BrowserContextKeyedServiceFactory(
"CalendarKeyedService",
BrowserContextDependencyManager::GetInstance()) {
: ProfileKeyedServiceFactory("CalendarKeyedService") {
DependsOn(IdentityManagerFactory::GetInstance());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define CHROME_BROWSER_UI_ASH_CALENDAR_CALENDAR_KEYED_SERVICE_FACTORY_H_

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

namespace content {
class BrowserContext;
Expand All @@ -19,7 +19,7 @@ class CalendarKeyedService;
// Factory class for browser context keyed calendar services. Only builds
// service instance for `user->HasGaiaAccount()` and returns `nullptr` for the
// other user types.
class CalendarKeyedServiceFactory : public BrowserContextKeyedServiceFactory {
class CalendarKeyedServiceFactory : public ProfileKeyedServiceFactory {
public:
static CalendarKeyedServiceFactory* GetInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/global_media_controls/cast_media_notification_producer_keyed_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_manager/user_manager.h"
#include "media/base/media_switches.h"

CastMediaNotificationProducerKeyedServiceFactory::
CastMediaNotificationProducerKeyedServiceFactory()
: BrowserContextKeyedServiceFactory(
"CastMediaNotificationProducerKeyedService",
BrowserContextDependencyManager::GetInstance()) {
: ProfileKeyedServiceFactory("CastMediaNotificationProducerKeyedService") {
DependsOn(media_router::ChromeMediaRouterFactory::GetInstance());
}
CastMediaNotificationProducerKeyedServiceFactory::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#ifndef CHROME_BROWSER_UI_ASH_GLOBAL_MEDIA_CONTROLS_CAST_MEDIA_NOTIFICATION_PRODUCER_KEYED_SERVICE_FACTORY_H_
#define CHROME_BROWSER_UI_ASH_GLOBAL_MEDIA_CONTROLS_CAST_MEDIA_NOTIFICATION_PRODUCER_KEYED_SERVICE_FACTORY_H_

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

namespace content {
class BrowserContext;
}

class CastMediaNotificationProducerKeyedServiceFactory
: public BrowserContextKeyedServiceFactory {
: public ProfileKeyedServiceFactory {
public:
CastMediaNotificationProducerKeyedServiceFactory();
CastMediaNotificationProducerKeyedServiceFactory(
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/cocoa/screentime/history_bridge_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#ifndef CHROME_BROWSER_UI_COCOA_SCREENTIME_HISTORY_BRIDGE_FACTORY_H_
#define CHROME_BROWSER_UI_COCOA_SCREENTIME_HISTORY_BRIDGE_FACTORY_H_

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

namespace screentime {

// A BrowserContextKeyedServiceFactory that is responsible for creating a
// HistoryBridge instance for each loaded Profile. The HistoryBridge instance is
// created when the Profile is initially created, so there's no explicit
// creation step.
class HistoryBridgeFactory : public BrowserContextKeyedServiceFactory {
class HistoryBridgeFactory : public ProfileKeyedServiceFactory {
public:
HistoryBridgeFactory();
~HistoryBridgeFactory() override;
Expand Down
5 changes: 1 addition & 4 deletions chrome/browser/ui/cocoa/screentime/history_bridge_factory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "chrome/browser/ui/cocoa/screentime/history_bridge.h"
#include "chrome/browser/ui/cocoa/screentime/history_deleter_impl.h"
#include "chrome/browser/ui/cocoa/screentime/screentime_features.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

namespace screentime {

Expand All @@ -21,9 +20,7 @@
}

HistoryBridgeFactory::HistoryBridgeFactory()
: BrowserContextKeyedServiceFactory(
"screentime::HistoryBridge",
BrowserContextDependencyManager::GetInstance()) {}
: ProfileKeyedServiceFactory("screentime::HistoryBridge") {}
HistoryBridgeFactory::~HistoryBridgeFactory() = default;

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

#include "chrome/browser/ui/cookie_controls/cookie_controls_service_factory.h"

#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/cookie_controls/cookie_controls_service.h"
#include "components/content_settings/core/common/cookie_controls_enforcement.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

// static
CookieControlsService* CookieControlsServiceFactory::GetForProfile(
Expand All @@ -28,19 +26,14 @@ KeyedService* CookieControlsServiceFactory::BuildInstanceFor(Profile* profile) {
}

CookieControlsServiceFactory::CookieControlsServiceFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"CookieControlsService",
BrowserContextDependencyManager::GetInstance()) {}
// The incognito profile has its own CookieSettings. Therefore, it
// should get its own CookieControlsService.
ProfileSelections::BuildForRegularAndIncognito()) {}

CookieControlsServiceFactory::~CookieControlsServiceFactory() = default;

content::BrowserContext* CookieControlsServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
// The incognito profile has its own CookieSettings. Therefore, it should
// get its own CookieControlsService.
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}

KeyedService* CookieControlsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
return BuildInstanceFor(Profile::FromBrowserContext(profile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#define CHROME_BROWSER_UI_COOKIE_CONTROLS_COOKIE_CONTROLS_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 Profile;
class CookieControlsService;

// Factory to get or create an instance of CookieControlsService from
// a Profile.
class CookieControlsServiceFactory : public BrowserContextKeyedServiceFactory {
class CookieControlsServiceFactory : public ProfileKeyedServiceFactory {
public:
static CookieControlsService* GetForProfile(Profile* profile);

Expand All @@ -29,8 +29,6 @@ class CookieControlsServiceFactory : public BrowserContextKeyedServiceFactory {
~CookieControlsServiceFactory() override;

// BrowserContextKeyedServiceFactory:
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
};
Expand Down
12 changes: 3 additions & 9 deletions chrome/browser/ui/find_bar/find_bar_state_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "chrome/browser/ui/find_bar/find_bar_state_factory.h"

#include "chrome/browser/ui/find_bar/find_bar_state.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

// static
FindBarState* FindBarStateFactory::GetForBrowserContext(
Expand All @@ -20,19 +19,14 @@ FindBarStateFactory* FindBarStateFactory::GetInstance() {
}

FindBarStateFactory::FindBarStateFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"FindBarState",
BrowserContextDependencyManager::GetInstance()) {}
// Separate instance in incognito.
ProfileSelections::BuildForRegularAndIncognito()) {}

FindBarStateFactory::~FindBarStateFactory() = default;

KeyedService* FindBarStateFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new FindBarState(context);
}

content::BrowserContext* FindBarStateFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
// Separate instance in incognito.
return context;
}
6 changes: 2 additions & 4 deletions chrome/browser/ui/find_bar/find_bar_state_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#define CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_STATE_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 FindBarState;

class FindBarStateFactory : public BrowserContextKeyedServiceFactory {
class FindBarStateFactory : public ProfileKeyedServiceFactory {
public:
FindBarStateFactory(const FindBarStateFactory&) = delete;
FindBarStateFactory& operator=(const FindBarStateFactory&) = delete;
Expand All @@ -28,8 +28,6 @@ class FindBarStateFactory : public BrowserContextKeyedServiceFactory {
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};

#endif // CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_STATE_FACTORY_H_
11 changes: 2 additions & 9 deletions chrome/browser/ui/global_error/global_error_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

#include "chrome/browser/ui/global_error/global_error_service_factory.h"

#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

// static
GlobalErrorService* GlobalErrorServiceFactory::GetForProfile(Profile* profile) {
Expand All @@ -21,18 +19,13 @@ GlobalErrorServiceFactory* GlobalErrorServiceFactory::GetInstance() {
}

GlobalErrorServiceFactory::GlobalErrorServiceFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"GlobalErrorService",
BrowserContextDependencyManager::GetInstance()) {}
ProfileSelections::BuildRedirectedInIncognito()) {}

GlobalErrorServiceFactory::~GlobalErrorServiceFactory() = default;

KeyedService* GlobalErrorServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
return new GlobalErrorService();
}

content::BrowserContext* GlobalErrorServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
6 changes: 2 additions & 4 deletions chrome/browser/ui/global_error/global_error_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#define CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_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 GlobalErrorService;
class Profile;

// Singleton that owns all GlobalErrorService and associates them with
// Profiles. Listens for the Profile's destruction notification and cleans up
// the associated GlobalErrorService.
class GlobalErrorServiceFactory : public BrowserContextKeyedServiceFactory {
class GlobalErrorServiceFactory : public ProfileKeyedServiceFactory {
public:
GlobalErrorServiceFactory(const GlobalErrorServiceFactory&) = delete;
GlobalErrorServiceFactory& operator=(const GlobalErrorServiceFactory&) =
Expand All @@ -33,8 +33,6 @@ class GlobalErrorServiceFactory : public BrowserContextKeyedServiceFactory {
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};

#endif // CHROME_BROWSER_UI_GLOBAL_ERROR_GLOBAL_ERROR_SERVICE_FACTORY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

#include "base/memory/singleton.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/global_media_controls/media_notification_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

MediaNotificationServiceFactory::MediaNotificationServiceFactory()
: BrowserContextKeyedServiceFactory(
: ProfileKeyedServiceFactory(
"MediaNotificationService",
BrowserContextDependencyManager::GetInstance()) {}
ProfileSelections::BuildForRegularAndIncognito()) {}

MediaNotificationServiceFactory::~MediaNotificationServiceFactory() {}

Expand All @@ -42,9 +40,3 @@ KeyedService* MediaNotificationServiceFactory::BuildServiceInstanceFor(
return new MediaNotificationService(Profile::FromBrowserContext(context),
show_from_all_profiles);
}

content::BrowserContext*
MediaNotificationServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_UI_GLOBAL_MEDIA_CONTROLS_MEDIA_NOTIFICATION_SERVICE_FACTORY_H_
#define CHROME_BROWSER_UI_GLOBAL_MEDIA_CONTROLS_MEDIA_NOTIFICATION_SERVICE_FACTORY_H_

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

class Profile;

Expand All @@ -20,8 +20,7 @@ class BrowserContext;

class MediaNotificationService;

class MediaNotificationServiceFactory
: public BrowserContextKeyedServiceFactory {
class MediaNotificationServiceFactory : public ProfileKeyedServiceFactory {
public:
MediaNotificationServiceFactory(const MediaNotificationServiceFactory&) =
delete;
Expand All @@ -41,8 +40,6 @@ class MediaNotificationServiceFactory
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};

#endif // CHROME_BROWSER_UI_GLOBAL_MEDIA_CONTROLS_MEDIA_NOTIFICATION_SERVICE_FACTORY_H_
12 changes: 3 additions & 9 deletions chrome/browser/ui/hats/hats_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/hats/hats_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

// static
HatsService* HatsServiceFactory::GetForProfile(Profile* profile,
Expand All @@ -23,20 +22,15 @@ HatsServiceFactory* HatsServiceFactory::GetInstance() {
}

HatsServiceFactory::HatsServiceFactory()
: BrowserContextKeyedServiceFactory(
"HatsService",
BrowserContextDependencyManager::GetInstance()) {
: ProfileKeyedServiceFactory("HatsService",
ProfileSelections::BuildForRegularProfile()) {
DependsOn(IdentityManagerFactory::GetInstance());
}

KeyedService* HatsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);

return (profile->IsOffTheRecord() || profile->IsGuestSession() ||
profile->IsSystemProfile())
? nullptr
: new HatsService(profile);
return new HatsService(profile);
}

HatsServiceFactory::~HatsServiceFactory() = default;
4 changes: 2 additions & 2 deletions chrome/browser/ui/hats/hats_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#define CHROME_BROWSER_UI_HATS_HATS_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 HatsService;
class Profile;

class HatsServiceFactory : public BrowserContextKeyedServiceFactory {
class HatsServiceFactory : public ProfileKeyedServiceFactory {
public:
HatsServiceFactory(const HatsServiceFactory&) = delete;
HatsServiceFactory& operator=(const HatsServiceFactory&) = delete;
Expand Down
Loading

0 comments on commit 4f357b6

Please sign in to comment.