Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/permissions/notifications_engagement_service_factory.h" |
| 6 | |
| 7 | #include "base/memory/singleton.h" |
| 8 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 | #include "chrome/browser/profiles/profile.h" |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 10 | #include "components/permissions/notifications_engagement_service.h" |
| 11 | |
| 12 | // static |
| 13 | NotificationsEngagementServiceFactory* |
| 14 | NotificationsEngagementServiceFactory::GetInstance() { |
| 15 | return base::Singleton<NotificationsEngagementServiceFactory>::get(); |
| 16 | } |
| 17 | |
| 18 | // static |
| 19 | permissions::NotificationsEngagementService* |
| 20 | NotificationsEngagementServiceFactory::GetForProfile(Profile* profile) { |
| 21 | return static_cast<permissions::NotificationsEngagementService*>( |
| 22 | GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 23 | } |
| 24 | |
| 25 | NotificationsEngagementServiceFactory::NotificationsEngagementServiceFactory() |
Ryan Sultanem | 9cc25816 | 2023-02-24 11:18:34 | [diff] [blame^] | 26 | : ProfileKeyedServiceFactory( |
| 27 | "NotificationsEngagementService", |
| 28 | ProfileSelections::Builder() |
| 29 | .WithRegular(ProfileSelection::kOriginalOnly) |
| 30 | // TODO(crbug.com/1418376): Check if this service is needed in |
| 31 | // Guest mode. |
| 32 | .WithGuest(ProfileSelection::kOriginalOnly) |
| 33 | .Build()) { |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 34 | DependsOn(HostContentSettingsMapFactory::GetInstance()); |
| 35 | } |
| 36 | |
| 37 | NotificationsEngagementServiceFactory:: |
| 38 | ~NotificationsEngagementServiceFactory() = default; |
| 39 | |
| 40 | KeyedService* NotificationsEngagementServiceFactory::BuildServiceInstanceFor( |
| 41 | content::BrowserContext* context) const { |
| 42 | Profile* profile = Profile::FromBrowserContext(context); |
| 43 | return new permissions::NotificationsEngagementService(context, |
| 44 | profile->GetPrefs()); |
| 45 | } |