Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [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/hid/hid_chooser_context_factory.h" |
| 6 | |
David Sanders | de533fce | 2021-12-15 14:59:43 | [diff] [blame] | 7 | #include "base/no_destructor.h" |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 8 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 | #include "chrome/browser/hid/hid_chooser_context.h" |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile.h" |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 11 | |
| 12 | // static |
| 13 | HidChooserContextFactory* HidChooserContextFactory::GetInstance() { |
| 14 | static base::NoDestructor<HidChooserContextFactory> factory; |
| 15 | return factory.get(); |
| 16 | } |
| 17 | |
| 18 | // static |
| 19 | HidChooserContext* HidChooserContextFactory::GetForProfile(Profile* profile) { |
| 20 | return static_cast<HidChooserContext*>( |
| 21 | GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 22 | } |
| 23 | |
Andy Paicu | fa96c83 | 2021-06-24 16:17:15 | [diff] [blame] | 24 | // static |
| 25 | HidChooserContext* HidChooserContextFactory::GetForProfileIfExists( |
| 26 | Profile* profile) { |
| 27 | return static_cast<HidChooserContext*>( |
| 28 | GetInstance()->GetServiceForBrowserContext(profile, /*create=*/false)); |
| 29 | } |
| 30 | |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 31 | HidChooserContextFactory::HidChooserContextFactory() |
Ryan Sultanem | 66dded2b | 2022-08-22 10:34:15 | [diff] [blame] | 32 | : ProfileKeyedServiceFactory( |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 33 | "HidChooserContext", |
Ryan Sultanem | d3d3568 | 2023-05-09 16:50:13 | [diff] [blame] | 34 | ProfileSelections::Builder() |
| 35 | .WithRegular(ProfileSelection::kOwnInstance) |
Alison Gale | 3f4203f7 | 2024-04-26 19:27:42 | [diff] [blame] | 36 | // TODO(crbug.com/40257657): Check if this service is needed in |
Ryan Sultanem | d3d3568 | 2023-05-09 16:50:13 | [diff] [blame] | 37 | // Guest mode. |
| 38 | .WithGuest(ProfileSelection::kOwnInstance) |
Ryan Sultanem | 0f58fd9 | 2024-07-15 09:30:42 | [diff] [blame] | 39 | // TODO(crbug.com/41488885): Check if this service is needed for |
| 40 | // Ash Internals. |
| 41 | .WithAshInternals(ProfileSelection::kOwnInstance) |
Ryan Sultanem | d3d3568 | 2023-05-09 16:50:13 | [diff] [blame] | 42 | .Build()) { |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 43 | DependsOn(HostContentSettingsMapFactory::GetInstance()); |
| 44 | } |
| 45 | |
| 46 | HidChooserContextFactory::~HidChooserContextFactory() = default; |
| 47 | |
Arthur Milchior | 356d4d4 | 2023-08-22 17:55:37 | [diff] [blame] | 48 | std::unique_ptr<KeyedService> |
| 49 | HidChooserContextFactory::BuildServiceInstanceForBrowserContext( |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 50 | content::BrowserContext* context) const { |
Arthur Milchior | 356d4d4 | 2023-08-22 17:55:37 | [diff] [blame] | 51 | return std::make_unique<HidChooserContext>( |
| 52 | Profile::FromBrowserContext(context)); |
Matt Reynolds | b07027a | 2019-05-21 23:43:26 | [diff] [blame] | 53 | } |