1 // Copyright 2013 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/search/instant_service_factory.h"
6 
7 #include "chrome/browser/history/top_sites_factory.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/instant_service.h"
11 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
12 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "chrome/browser/themes/theme_service_factory.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/search/search.h"
16 
17 // static
GetForProfile(Profile * profile)18 InstantService* InstantServiceFactory::GetForProfile(Profile* profile) {
19   DCHECK(search::IsInstantExtendedAPIEnabled());
20 
21   return static_cast<InstantService*>(
22       GetInstance()->GetServiceForBrowserContext(profile, true));
23 }
24 
25 // static
GetInstance()26 InstantServiceFactory* InstantServiceFactory::GetInstance() {
27   return base::Singleton<InstantServiceFactory>::get();
28 }
29 
InstantServiceFactory()30 InstantServiceFactory::InstantServiceFactory()
31     : BrowserContextKeyedServiceFactory(
32         "InstantService",
33         BrowserContextDependencyManager::GetInstance()) {
34   DependsOn(suggestions::SuggestionsServiceFactory::GetInstance());
35   DependsOn(TemplateURLServiceFactory::GetInstance());
36   DependsOn(ThemeServiceFactory::GetInstance());
37   DependsOn(TopSitesFactory::GetInstance());
38 }
39 
40 InstantServiceFactory::~InstantServiceFactory() = default;
41 
GetBrowserContextToUse(content::BrowserContext * context) const42 content::BrowserContext* InstantServiceFactory::GetBrowserContextToUse(
43     content::BrowserContext* context) const {
44   return chrome::GetBrowserContextOwnInstanceInIncognito(context);
45 }
46 
BuildServiceInstanceFor(content::BrowserContext * context) const47 KeyedService* InstantServiceFactory::BuildServiceInstanceFor(
48     content::BrowserContext* context) const {
49   DCHECK(search::IsInstantExtendedAPIEnabled());
50   return new InstantService(Profile::FromBrowserContext(context));
51 }
52