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 | |
Mikel Astiz | 8dec793 | 2023-06-02 12:26:10 | [diff] [blame] | 7 | #include "base/no_destructor.h" |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 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() { |
Mikel Astiz | 8dec793 | 2023-06-02 12:26:10 | [diff] [blame] | 15 | static base::NoDestructor<NotificationsEngagementServiceFactory> instance; |
| 16 | return instance.get(); |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | // static |
| 20 | permissions::NotificationsEngagementService* |
| 21 | NotificationsEngagementServiceFactory::GetForProfile(Profile* profile) { |
| 22 | return static_cast<permissions::NotificationsEngagementService*>( |
| 23 | GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 24 | } |
| 25 | |
| 26 | NotificationsEngagementServiceFactory::NotificationsEngagementServiceFactory() |
Ryan Sultanem | 9cc25816 | 2023-02-24 11:18:34 | [diff] [blame] | 27 | : ProfileKeyedServiceFactory( |
| 28 | "NotificationsEngagementService", |
| 29 | ProfileSelections::Builder() |
| 30 | .WithRegular(ProfileSelection::kOriginalOnly) |
Alison Gale | 3f4203f7 | 2024-04-26 19:27:42 | [diff] [blame] | 31 | // TODO(crbug.com/40257657): Check if this service is needed in |
Ryan Sultanem | 9cc25816 | 2023-02-24 11:18:34 | [diff] [blame] | 32 | // Guest mode. |
| 33 | .WithGuest(ProfileSelection::kOriginalOnly) |
Ryan Sultanem | 0f58fd9 | 2024-07-15 09:30:42 | [diff] [blame] | 34 | // TODO(crbug.com/41488885): Check if this service is needed for |
| 35 | // Ash Internals. |
| 36 | .WithAshInternals(ProfileSelection::kOriginalOnly) |
Ryan Sultanem | 9cc25816 | 2023-02-24 11:18:34 | [diff] [blame] | 37 | .Build()) { |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 38 | DependsOn(HostContentSettingsMapFactory::GetInstance()); |
| 39 | } |
| 40 | |
| 41 | NotificationsEngagementServiceFactory:: |
| 42 | ~NotificationsEngagementServiceFactory() = default; |
| 43 | |
Arthur Milchior | 0fbaf54 | 2024-11-02 06:15:44 | [diff] [blame] | 44 | std::unique_ptr<KeyedService> |
| 45 | NotificationsEngagementServiceFactory::BuildServiceInstanceForBrowserContext( |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 46 | content::BrowserContext* context) const { |
| 47 | Profile* profile = Profile::FromBrowserContext(context); |
Arthur Milchior | 0fbaf54 | 2024-11-02 06:15:44 | [diff] [blame] | 48 | return std::make_unique<permissions::NotificationsEngagementService>( |
| 49 | context, profile->GetPrefs()); |
Kamila | 1c047fd | 2022-05-13 17:20:36 | [diff] [blame] | 50 | } |