summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/autocomplete/autocomplete_classifier_factory.cc
blob: 22dc1e35bb52cffdeeedaafb626340982402af37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h"

#include "base/memory/singleton.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "ios/chrome/browser/autocomplete/autocomplete_provider_client_impl.h"
#include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h"
#include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h"
#include "ios/chrome/browser/autocomplete/shortcuts_backend_factory.h"
#include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"

namespace ios {
namespace {

scoped_ptr<KeyedService> BuildAutocompleteClassifier(
    web::BrowserState* context) {
  ios::ChromeBrowserState* browser_state =
      ios::ChromeBrowserState::FromBrowserState(context);
  return make_scoped_ptr(new AutocompleteClassifier(
      make_scoped_ptr(new AutocompleteController(
          make_scoped_ptr(new AutocompleteProviderClientImpl(browser_state)),
          nullptr, AutocompleteClassifier::kDefaultOmniboxProviders)),
      make_scoped_ptr(new AutocompleteSchemeClassifierImpl)));
}

}  // namespace

// static
AutocompleteClassifier* AutocompleteClassifierFactory::GetForBrowserState(
    ios::ChromeBrowserState* browser_state) {
  return static_cast<AutocompleteClassifier*>(
      GetInstance()->GetServiceForBrowserState(browser_state, true));
}

// static
AutocompleteClassifierFactory* AutocompleteClassifierFactory::GetInstance() {
  return base::Singleton<AutocompleteClassifierFactory>::get();
}

// static
BrowserStateKeyedServiceFactory::TestingFactoryFunction
AutocompleteClassifierFactory::GetDefaultFactory() {
  return &BuildAutocompleteClassifier;
}

AutocompleteClassifierFactory::AutocompleteClassifierFactory()
    : BrowserStateKeyedServiceFactory(
          "AutocompleteClassifier",
          BrowserStateDependencyManager::GetInstance()) {
  DependsOn(ios::InMemoryURLIndexFactory::GetInstance());
  DependsOn(ios::TemplateURLServiceFactory::GetInstance());
  DependsOn(ios::ShortcutsBackendFactory::GetInstance());
}

AutocompleteClassifierFactory::~AutocompleteClassifierFactory() {}

scoped_ptr<KeyedService> AutocompleteClassifierFactory::BuildServiceInstanceFor(
    web::BrowserState* context) const {
  return BuildAutocompleteClassifier(context);
}

web::BrowserState* AutocompleteClassifierFactory::GetBrowserStateToUse(
    web::BrowserState* context) const {
  return GetBrowserStateRedirectedInIncognito(context);
}

bool AutocompleteClassifierFactory::ServiceIsNULLWhileTesting() const {
  return true;
}

}  // namespace ios