1 // Copyright 2018 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/safe_browsing/advanced_protection_status_manager_factory.h" 6 7 #include "chrome/browser/profiles/incognito_helpers.h" 8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/safe_browsing/advanced_protection_status_manager.h" 10 #include "chrome/browser/signin/identity_manager_factory.h" 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" 12 #include "content/public/browser/browser_context.h" 13 14 namespace safe_browsing { 15 16 // static 17 AdvancedProtectionStatusManager* GetForProfile(Profile * profile)18AdvancedProtectionStatusManagerFactory::GetForProfile(Profile* profile) { 19 return static_cast<AdvancedProtectionStatusManager*>( 20 GetInstance()->GetServiceForBrowserContext(profile, /* create= */ true)); 21 } 22 23 // static 24 AdvancedProtectionStatusManagerFactory* GetInstance()25AdvancedProtectionStatusManagerFactory::GetInstance() { 26 return base::Singleton<AdvancedProtectionStatusManagerFactory>::get(); 27 } 28 AdvancedProtectionStatusManagerFactory()29AdvancedProtectionStatusManagerFactory::AdvancedProtectionStatusManagerFactory() 30 : BrowserContextKeyedServiceFactory( 31 "AdvancedProtectionStatusManager", 32 BrowserContextDependencyManager::GetInstance()) { 33 DependsOn(IdentityManagerFactory::GetInstance()); 34 } 35 36 AdvancedProtectionStatusManagerFactory:: ~AdvancedProtectionStatusManagerFactory()37 ~AdvancedProtectionStatusManagerFactory() {} 38 BuildServiceInstanceFor(content::BrowserContext * context) const39KeyedService* AdvancedProtectionStatusManagerFactory::BuildServiceInstanceFor( 40 content::BrowserContext* context) const { 41 Profile* profile = Profile::FromBrowserContext(context); 42 return new AdvancedProtectionStatusManager( 43 profile->GetPrefs(), IdentityManagerFactory::GetForProfile(profile)); 44 } 45 46 bool AdvancedProtectionStatusManagerFactory:: ServiceIsCreatedWithBrowserContext() const47 ServiceIsCreatedWithBrowserContext() const { 48 return true; 49 } 50 51 content::BrowserContext* GetBrowserContextToUse(content::BrowserContext * context) const52AdvancedProtectionStatusManagerFactory::GetBrowserContextToUse( 53 content::BrowserContext* context) const { 54 return chrome::GetBrowserContextRedirectedInIncognito(context); 55 } 56 57 } // namespace safe_browsing 58