Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / autocomplete / in_memory_url_index_factory.cc
blobcb8e0419195a059c972e00ac4553c917c7dac9fa
1 // Copyright 2015 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.
5 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h"
7 #include "base/memory/singleton.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/autocomplete/in_memory_url_index.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/profiles/incognito_helpers.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/keyed_service/core/service_access_type.h"
18 // static
19 InMemoryURLIndex* InMemoryURLIndexFactory::GetForProfile(Profile* profile) {
20 return static_cast<InMemoryURLIndex*>(
21 GetInstance()->GetServiceForBrowserContext(profile, true));
24 // static
25 InMemoryURLIndexFactory* InMemoryURLIndexFactory::GetInstance() {
26 return Singleton<InMemoryURLIndexFactory>::get();
29 InMemoryURLIndexFactory::InMemoryURLIndexFactory()
30 : BrowserContextKeyedServiceFactory(
31 "InMemoryURLIndex",
32 BrowserContextDependencyManager::GetInstance()) {
33 DependsOn(BookmarkModelFactory::GetInstance());
34 DependsOn(HistoryServiceFactory::GetInstance());
37 InMemoryURLIndexFactory::~InMemoryURLIndexFactory() {
40 KeyedService* InMemoryURLIndexFactory::BuildServiceInstanceFor(
41 content::BrowserContext* context) const {
42 // Do not force creation of the HistoryService if saving history is disabled.
43 Profile* profile = Profile::FromBrowserContext(context);
44 InMemoryURLIndex* in_memory_url_index = new InMemoryURLIndex(
45 BookmarkModelFactory::GetForProfile(profile),
46 HistoryServiceFactory::GetForProfile(profile,
47 ServiceAccessType::IMPLICIT_ACCESS),
48 profile->GetPath(),
49 profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
50 in_memory_url_index->Init();
51 return in_memory_url_index;
54 content::BrowserContext* InMemoryURLIndexFactory::GetBrowserContextToUse(
55 content::BrowserContext* context) const {
56 return chrome::GetBrowserContextRedirectedInIncognito(context);
59 bool InMemoryURLIndexFactory::ServiceIsNULLWhileTesting() const {
60 return true;