12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/search/instant_service_factory.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/incognito_helpers.h"
8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/profile.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/search/instant_service.h"
10558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "chrome/browser/search_engines/template_url_service_factory.h"
11558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "chrome/browser/themes/theme_service_factory.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/browser_context_dependency_manager.h"
135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/search/search.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)InstantService* InstantServiceFactory::GetForProfile(Profile* profile) {
17a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (!chrome::IsInstantExtendedAPIEnabled())
18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return NULL;
19a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return static_cast<InstantService*>(
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      GetInstance()->GetServiceForBrowserContext(profile, true));
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)InstantServiceFactory* InstantServiceFactory::GetInstance() {
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return Singleton<InstantServiceFactory>::get();
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)InstantServiceFactory::InstantServiceFactory()
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    : BrowserContextKeyedServiceFactory(
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        "InstantService",
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        BrowserContextDependencyManager::GetInstance()) {
33558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  DependsOn(TemplateURLServiceFactory::GetInstance());
34558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(ENABLE_THEMES)
35558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  DependsOn(ThemeServiceFactory::GetInstance());
36558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)InstantServiceFactory::~InstantServiceFactory() {
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)content::BrowserContext* InstantServiceFactory::GetBrowserContextToUse(
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content::BrowserContext* context) const {
44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return chrome::GetBrowserContextOwnInstanceInIncognito(context);
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* InstantServiceFactory::BuildServiceInstanceFor(
48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content::BrowserContext* profile) const {
49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return chrome::IsInstantExtendedAPIEnabled() ?
50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      new InstantService(static_cast<Profile*>(profile)) : NULL;
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
52