blob: ed6640a47765e477b615f9c950d156b56583a734 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2019 The Chromium Authors
Matt Reynoldsb07027a2019-05-21 23:43:262// 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/hid/hid_chooser_context_factory.h"
6
David Sandersde533fce2021-12-15 14:59:437#include "base/no_destructor.h"
Matt Reynoldsb07027a2019-05-21 23:43:268#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9#include "chrome/browser/hid/hid_chooser_context.h"
Matt Reynoldsb07027a2019-05-21 23:43:2610#include "chrome/browser/profiles/profile.h"
Matt Reynoldsb07027a2019-05-21 23:43:2611
12// static
13HidChooserContextFactory* HidChooserContextFactory::GetInstance() {
14 static base::NoDestructor<HidChooserContextFactory> factory;
15 return factory.get();
16}
17
18// static
19HidChooserContext* HidChooserContextFactory::GetForProfile(Profile* profile) {
20 return static_cast<HidChooserContext*>(
21 GetInstance()->GetServiceForBrowserContext(profile, true));
22}
23
Andy Paicufa96c832021-06-24 16:17:1524// static
25HidChooserContext* HidChooserContextFactory::GetForProfileIfExists(
26 Profile* profile) {
27 return static_cast<HidChooserContext*>(
28 GetInstance()->GetServiceForBrowserContext(profile, /*create=*/false));
29}
30
Matt Reynoldsb07027a2019-05-21 23:43:2631HidChooserContextFactory::HidChooserContextFactory()
Ryan Sultanem66dded2b2022-08-22 10:34:1532 : ProfileKeyedServiceFactory(
Matt Reynoldsb07027a2019-05-21 23:43:2633 "HidChooserContext",
Ryan Sultanemd3d35682023-05-09 16:50:1334 ProfileSelections::Builder()
35 .WithRegular(ProfileSelection::kOwnInstance)
Alison Gale3f4203f72024-04-26 19:27:4236 // TODO(crbug.com/40257657): Check if this service is needed in
Ryan Sultanemd3d35682023-05-09 16:50:1337 // Guest mode.
38 .WithGuest(ProfileSelection::kOwnInstance)
Ryan Sultanem0f58fd92024-07-15 09:30:4239 // TODO(crbug.com/41488885): Check if this service is needed for
40 // Ash Internals.
41 .WithAshInternals(ProfileSelection::kOwnInstance)
Ryan Sultanemd3d35682023-05-09 16:50:1342 .Build()) {
Matt Reynoldsb07027a2019-05-21 23:43:2643 DependsOn(HostContentSettingsMapFactory::GetInstance());
44}
45
46HidChooserContextFactory::~HidChooserContextFactory() = default;
47
Arthur Milchior356d4d42023-08-22 17:55:3748std::unique_ptr<KeyedService>
49HidChooserContextFactory::BuildServiceInstanceForBrowserContext(
Matt Reynoldsb07027a2019-05-21 23:43:2650 content::BrowserContext* context) const {
Arthur Milchior356d4d42023-08-22 17:55:3751 return std::make_unique<HidChooserContext>(
52 Profile::FromBrowserContext(context));
Matt Reynoldsb07027a2019-05-21 23:43:2653}