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/serial/serial_chooser_context_factory.h" 6 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 8 #include "chrome/browser/profiles/incognito_helpers.h" 9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/serial/serial_chooser_context.h" 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" 12 SerialChooserContextFactory()13SerialChooserContextFactory::SerialChooserContextFactory() 14 : BrowserContextKeyedServiceFactory( 15 "SerialChooserContext", 16 BrowserContextDependencyManager::GetInstance()) { 17 DependsOn(HostContentSettingsMapFactory::GetInstance()); 18 } 19 ~SerialChooserContextFactory()20SerialChooserContextFactory::~SerialChooserContextFactory() {} 21 BuildServiceInstanceFor(content::BrowserContext * context) const22KeyedService* SerialChooserContextFactory::BuildServiceInstanceFor( 23 content::BrowserContext* context) const { 24 return new SerialChooserContext(Profile::FromBrowserContext(context)); 25 } 26 27 // static GetInstance()28SerialChooserContextFactory* SerialChooserContextFactory::GetInstance() { 29 return base::Singleton<SerialChooserContextFactory>::get(); 30 } 31 32 // static GetForProfile(Profile * profile)33SerialChooserContext* SerialChooserContextFactory::GetForProfile( 34 Profile* profile) { 35 return static_cast<SerialChooserContext*>( 36 GetInstance()->GetServiceForBrowserContext(profile, true)); 37 } 38 GetBrowserContextToUse(content::BrowserContext * context) const39content::BrowserContext* SerialChooserContextFactory::GetBrowserContextToUse( 40 content::BrowserContext* context) const { 41 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 42 } 43