15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/search_engines/template_url_fetcher_factory.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/incognito_helpers.h" 8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/search_engines/template_url_service_factory.h" 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/browser_context_dependency_manager.h" 11116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/search_engines/template_url_fetcher.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TemplateURLFetcher* TemplateURLFetcherFactory::GetForProfile( 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile) { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return static_cast<TemplateURLFetcher*>( 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) GetInstance()->GetServiceForBrowserContext(profile, true)); 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TemplateURLFetcherFactory* TemplateURLFetcherFactory::GetInstance() { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Singleton<TemplateURLFetcherFactory>::get(); 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TemplateURLFetcherFactory::ShutdownForProfile(Profile* profile) { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TemplateURLFetcherFactory* factory = GetInstance(); 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) factory->BrowserContextShutdown(profile); 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) factory->BrowserContextDestroyed(profile); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TemplateURLFetcherFactory::TemplateURLFetcherFactory() 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : BrowserContextKeyedServiceFactory( 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) "TemplateURLFetcher", 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) BrowserContextDependencyManager::GetInstance()) { 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DependsOn(TemplateURLServiceFactory::GetInstance()); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TemplateURLFetcherFactory::~TemplateURLFetcherFactory() { 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* TemplateURLFetcherFactory::BuildServiceInstanceFor( 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::BrowserContext* profile) const { 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return new TemplateURLFetcher( 45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch TemplateURLServiceFactory::GetForProfile(static_cast<Profile*>(profile)), 46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile->GetRequestContext()); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)content::BrowserContext* TemplateURLFetcherFactory::GetBrowserContextToUse( 50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::BrowserContext* context) const { 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return chrome::GetBrowserContextRedirectedInIncognito(context); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 53