blob: 85fb4045bde7cc3bbf673aa6738f4ebac398f60f [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2022 The Chromium Authors
Kamila1c047fd2022-05-13 17:20:362// 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 Astiz8dec7932023-06-02 12:26:107#include "base/no_destructor.h"
Kamila1c047fd2022-05-13 17:20:368#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9#include "chrome/browser/profiles/profile.h"
Kamila1c047fd2022-05-13 17:20:3610#include "components/permissions/notifications_engagement_service.h"
11
12// static
13NotificationsEngagementServiceFactory*
14NotificationsEngagementServiceFactory::GetInstance() {
Mikel Astiz8dec7932023-06-02 12:26:1015 static base::NoDestructor<NotificationsEngagementServiceFactory> instance;
16 return instance.get();
Kamila1c047fd2022-05-13 17:20:3617}
18
19// static
20permissions::NotificationsEngagementService*
21NotificationsEngagementServiceFactory::GetForProfile(Profile* profile) {
22 return static_cast<permissions::NotificationsEngagementService*>(
23 GetInstance()->GetServiceForBrowserContext(profile, true));
24}
25
26NotificationsEngagementServiceFactory::NotificationsEngagementServiceFactory()
Ryan Sultanem9cc258162023-02-24 11:18:3427 : ProfileKeyedServiceFactory(
28 "NotificationsEngagementService",
29 ProfileSelections::Builder()
30 .WithRegular(ProfileSelection::kOriginalOnly)
Alison Gale3f4203f72024-04-26 19:27:4231 // TODO(crbug.com/40257657): Check if this service is needed in
Ryan Sultanem9cc258162023-02-24 11:18:3432 // Guest mode.
33 .WithGuest(ProfileSelection::kOriginalOnly)
Ryan Sultanem0f58fd92024-07-15 09:30:4234 // TODO(crbug.com/41488885): Check if this service is needed for
35 // Ash Internals.
36 .WithAshInternals(ProfileSelection::kOriginalOnly)
Ryan Sultanem9cc258162023-02-24 11:18:3437 .Build()) {
Kamila1c047fd2022-05-13 17:20:3638 DependsOn(HostContentSettingsMapFactory::GetInstance());
39}
40
41NotificationsEngagementServiceFactory::
42 ~NotificationsEngagementServiceFactory() = default;
43
Arthur Milchior0fbaf542024-11-02 06:15:4444std::unique_ptr<KeyedService>
45NotificationsEngagementServiceFactory::BuildServiceInstanceForBrowserContext(
Kamila1c047fd2022-05-13 17:20:3646 content::BrowserContext* context) const {
47 Profile* profile = Profile::FromBrowserContext(context);
Arthur Milchior0fbaf542024-11-02 06:15:4448 return std::make_unique<permissions::NotificationsEngagementService>(
49 context, profile->GetPrefs());
Kamila1c047fd2022-05-13 17:20:3650}