1 // Copyright 2019 The Chromium Authors. All rights reserved.
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 
7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
8 #include "chrome/browser/hid/hid_chooser_context.h"
9 #include "chrome/browser/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/keyed_service/content/browser_context_dependency_manager.h"
12 
13 // static
GetInstance()14 HidChooserContextFactory* HidChooserContextFactory::GetInstance() {
15   static base::NoDestructor<HidChooserContextFactory> factory;
16   return factory.get();
17 }
18 
19 // static
GetForProfile(Profile * profile)20 HidChooserContext* HidChooserContextFactory::GetForProfile(Profile* profile) {
21   return static_cast<HidChooserContext*>(
22       GetInstance()->GetServiceForBrowserContext(profile, true));
23 }
24 
HidChooserContextFactory()25 HidChooserContextFactory::HidChooserContextFactory()
26     : BrowserContextKeyedServiceFactory(
27           "HidChooserContext",
28           BrowserContextDependencyManager::GetInstance()) {
29   DependsOn(HostContentSettingsMapFactory::GetInstance());
30 }
31 
32 HidChooserContextFactory::~HidChooserContextFactory() = default;
33 
BuildServiceInstanceFor(content::BrowserContext * context) const34 KeyedService* HidChooserContextFactory::BuildServiceInstanceFor(
35     content::BrowserContext* context) const {
36   return new HidChooserContext(Profile::FromBrowserContext(context));
37 }
38 
GetBrowserContextToUse(content::BrowserContext * context) const39 content::BrowserContext* HidChooserContextFactory::GetBrowserContextToUse(
40     content::BrowserContext* context) const {
41   return chrome::GetBrowserContextOwnInstanceInIncognito(context);
42 }
43