Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ios / chrome / browser / autocomplete / autocomplete_provider_client_impl.cc
blob890d40b7712f865727b6c7ff29e3f89b97f2344d
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 "ios/chrome/browser/autocomplete/autocomplete_provider_client_impl.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/bookmarks/common/bookmark_pref_names.h"
10 #include "components/history/core/browser/history_service.h"
11 #include "components/keyed_service/core/service_access_type.h"
12 #include "components/omnibox/browser/autocomplete_classifier.h"
13 #include "components/sync_driver/sync_service_utils.h"
14 #include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h"
15 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h"
16 #include "ios/chrome/browser/autocomplete/shortcuts_backend_factory.h"
17 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
18 #include "ios/chrome/browser/history/history_service_factory.h"
19 #include "ios/chrome/browser/history/top_sites_factory.h"
20 #include "ios/chrome/browser/pref_names.h"
21 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
22 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
23 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
24 #include "ios/public/provider/chrome/browser/keyed_service_provider.h"
26 AutocompleteProviderClientImpl::AutocompleteProviderClientImpl(
27 ios::ChromeBrowserState* browser_state)
28 : browser_state_(browser_state), search_terms_data_(browser_state_) {}
30 AutocompleteProviderClientImpl::~AutocompleteProviderClientImpl() {}
32 net::URLRequestContextGetter*
33 AutocompleteProviderClientImpl::GetRequestContext() {
34 return browser_state_->GetRequestContext();
37 PrefService* AutocompleteProviderClientImpl::GetPrefs() {
38 return browser_state_->GetPrefs();
41 const AutocompleteSchemeClassifier&
42 AutocompleteProviderClientImpl::GetSchemeClassifier() const {
43 return scheme_classifier_;
46 AutocompleteClassifier*
47 AutocompleteProviderClientImpl::GetAutocompleteClassifier() {
48 return ios::AutocompleteClassifierFactory::GetForBrowserState(browser_state_);
51 history::HistoryService* AutocompleteProviderClientImpl::GetHistoryService() {
52 return ios::HistoryServiceFactory::GetForBrowserState(
53 browser_state_, ServiceAccessType::EXPLICIT_ACCESS);
56 scoped_refptr<history::TopSites> AutocompleteProviderClientImpl::GetTopSites() {
57 return ios::TopSitesFactory::GetForBrowserState(browser_state_);
60 bookmarks::BookmarkModel* AutocompleteProviderClientImpl::GetBookmarkModel() {
61 return ios::BookmarkModelFactory::GetForBrowserState(browser_state_);
64 history::URLDatabase* AutocompleteProviderClientImpl::GetInMemoryDatabase() {
65 // This method is called in unit test contexts where the HistoryService isn't
66 // loaded. In that case, return null.
67 history::HistoryService* history_service = GetHistoryService();
68 return history_service ? history_service->InMemoryDatabase() : nullptr;
71 InMemoryURLIndex* AutocompleteProviderClientImpl::GetInMemoryURLIndex() {
72 return ios::InMemoryURLIndexFactory::GetForBrowserState(browser_state_);
75 TemplateURLService* AutocompleteProviderClientImpl::GetTemplateURLService() {
76 return ios::TemplateURLServiceFactory::GetForBrowserState(browser_state_);
79 const TemplateURLService*
80 AutocompleteProviderClientImpl::GetTemplateURLService() const {
81 return ios::TemplateURLServiceFactory::GetForBrowserState(browser_state_);
84 const SearchTermsData& AutocompleteProviderClientImpl::GetSearchTermsData()
85 const {
86 return search_terms_data_;
89 scoped_refptr<ShortcutsBackend>
90 AutocompleteProviderClientImpl::GetShortcutsBackend() {
91 return ios::ShortcutsBackendFactory::GetForBrowserState(browser_state_);
94 scoped_refptr<ShortcutsBackend>
95 AutocompleteProviderClientImpl::GetShortcutsBackendIfExists() {
96 return ios::ShortcutsBackendFactory::GetForBrowserStateIfExists(
97 browser_state_);
100 scoped_ptr<KeywordExtensionsDelegate>
101 AutocompleteProviderClientImpl::GetKeywordExtensionsDelegate(
102 KeywordProvider* keyword_provider) {
103 return nullptr;
106 std::string AutocompleteProviderClientImpl::GetAcceptLanguages() const {
107 return browser_state_->GetPrefs()->GetString(ios::prefs::kAcceptLanguages);
110 std::string
111 AutocompleteProviderClientImpl::GetEmbedderRepresentationOfAboutScheme() {
112 return ios::GetChromeBrowserProvider()->GetChromeUIScheme();
115 std::vector<base::string16> AutocompleteProviderClientImpl::GetBuiltinURLs() {
116 // iOS does not supports BuiltinProvider.
117 return std::vector<base::string16>();
120 std::vector<base::string16>
121 AutocompleteProviderClientImpl::GetBuiltinsToProvideAsUserTypes() {
122 // iOS does not supports BuiltinProvider.
123 return std::vector<base::string16>();
126 bool AutocompleteProviderClientImpl::IsOffTheRecord() const {
127 return browser_state_->IsOffTheRecord();
130 bool AutocompleteProviderClientImpl::SearchSuggestEnabled() const {
131 return browser_state_->GetPrefs()->GetBoolean(
132 ios::prefs::kSearchSuggestEnabled);
135 bool AutocompleteProviderClientImpl::BookmarkBarIsVisible() const {
136 return browser_state_->GetPrefs()->GetBoolean(
137 bookmarks::prefs::kShowBookmarkBar);
140 bool AutocompleteProviderClientImpl::TabSyncEnabledAndUnencrypted() const {
141 return sync_driver::IsTabSyncEnabledAndUnencrypted(
142 ios::GetKeyedServiceProvider()->GetSyncServiceForBrowserState(
143 browser_state_),
144 browser_state_->GetPrefs());
147 void AutocompleteProviderClientImpl::Classify(
148 const base::string16& text,
149 bool prefer_keyword,
150 bool allow_exact_keyword_match,
151 metrics::OmniboxEventProto::PageClassification page_classification,
152 AutocompleteMatch* match,
153 GURL* alternate_nav_url) {
154 AutocompleteClassifier* classifier = GetAutocompleteClassifier();
155 classifier->Classify(text, prefer_keyword, allow_exact_keyword_match,
156 page_classification, match, alternate_nav_url);
159 void AutocompleteProviderClientImpl::DeleteMatchingURLsForKeywordFromHistory(
160 history::KeywordID keyword_id,
161 const base::string16& term) {
162 GetHistoryService()->DeleteMatchingURLsForKeyword(keyword_id, term);
165 void AutocompleteProviderClientImpl::PrefetchImage(const GURL& url) {}
167 void AutocompleteProviderClientImpl::OnAutocompleteControllerResultReady(
168 AutocompleteController* controller) {
169 // iOS currently has no client for this event.