1 // Copyright 2014 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/translate/translate_accept_languages_factory.h" 6 7 #include "base/macros.h" 8 #include "chrome/browser/profiles/incognito_helpers.h" 9 #include "chrome/browser/profiles/profile.h" 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" 11 #include "components/language/core/browser/pref_names.h" 12 #include "components/prefs/pref_service.h" 13 #include "components/translate/core/browser/translate_accept_languages.h" 14 15 // static 16 TranslateAcceptLanguagesFactory* GetInstance()17TranslateAcceptLanguagesFactory::GetInstance() { 18 return base::Singleton<TranslateAcceptLanguagesFactory>::get(); 19 } 20 21 // static 22 translate::TranslateAcceptLanguages* GetForBrowserContext(content::BrowserContext * context)23TranslateAcceptLanguagesFactory::GetForBrowserContext( 24 content::BrowserContext* context) { 25 return static_cast<translate::TranslateAcceptLanguages*>( 26 GetInstance()->GetServiceForBrowserContext(context, true)); 27 } 28 TranslateAcceptLanguagesFactory()29TranslateAcceptLanguagesFactory::TranslateAcceptLanguagesFactory() 30 : BrowserContextKeyedServiceFactory( 31 "TranslateAcceptLanguages", 32 BrowserContextDependencyManager::GetInstance()) {} 33 ~TranslateAcceptLanguagesFactory()34TranslateAcceptLanguagesFactory::~TranslateAcceptLanguagesFactory() {} 35 BuildServiceInstanceFor(content::BrowserContext * browser_context) const36KeyedService* TranslateAcceptLanguagesFactory::BuildServiceInstanceFor( 37 content::BrowserContext* browser_context) const { 38 Profile* profile = Profile::FromBrowserContext(browser_context); 39 return new translate::TranslateAcceptLanguages( 40 profile->GetPrefs(), language::prefs::kAcceptLanguages); 41 } 42 43 content::BrowserContext* GetBrowserContextToUse(content::BrowserContext * context) const44TranslateAcceptLanguagesFactory::GetBrowserContextToUse( 45 content::BrowserContext* context) const { 46 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 47 } 48