1// Copyright 2014 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/autocomplete/chrome_autocomplete_provider_client.h" 6 7#include "base/prefs/pref_service.h" 8#include "chrome/browser/autocomplete/autocomplete_classifier.h" 9#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 10#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" 11#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" 12#include "chrome/browser/history/history_service.h" 13#include "chrome/browser/history/history_service_factory.h" 14#include "chrome/browser/profiles/profile.h" 15#include "chrome/browser/sync/profile_sync_service.h" 16#include "chrome/browser/sync/profile_sync_service_factory.h" 17#include "chrome/common/pref_names.h" 18 19ChromeAutocompleteProviderClient::ChromeAutocompleteProviderClient( 20 Profile* profile) 21 : profile_(profile), 22 scheme_classifier_(profile) { 23} 24 25ChromeAutocompleteProviderClient::~ChromeAutocompleteProviderClient() { 26} 27 28net::URLRequestContextGetter* 29ChromeAutocompleteProviderClient::RequestContext() { 30 return profile_->GetRequestContext(); 31} 32 33bool ChromeAutocompleteProviderClient::IsOffTheRecord() { 34 return profile_->IsOffTheRecord(); 35} 36 37std::string ChromeAutocompleteProviderClient::AcceptLanguages() { 38 return profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); 39} 40 41bool ChromeAutocompleteProviderClient::SearchSuggestEnabled() { 42 return profile_->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); 43} 44 45bool ChromeAutocompleteProviderClient::ShowBookmarkBar() { 46 return profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar); 47} 48 49const AutocompleteSchemeClassifier& 50ChromeAutocompleteProviderClient::SchemeClassifier() { 51 return scheme_classifier_; 52} 53 54void ChromeAutocompleteProviderClient::Classify( 55 const base::string16& text, 56 bool prefer_keyword, 57 bool allow_exact_keyword_match, 58 metrics::OmniboxEventProto::PageClassification page_classification, 59 AutocompleteMatch* match, 60 GURL* alternate_nav_url) { 61 AutocompleteClassifier* classifier = 62 AutocompleteClassifierFactory::GetForProfile(profile_); 63 DCHECK(classifier); 64 classifier->Classify(text, prefer_keyword, allow_exact_keyword_match, 65 page_classification, match, alternate_nav_url); 66} 67 68history::URLDatabase* ChromeAutocompleteProviderClient::InMemoryDatabase() { 69 HistoryService* history_service = 70 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 71 return history_service ? history_service->InMemoryDatabase() : NULL; 72} 73 74void ChromeAutocompleteProviderClient::DeleteMatchingURLsForKeywordFromHistory( 75 history::KeywordID keyword_id, 76 const base::string16& term) { 77 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS) 78 ->DeleteMatchingURLsForKeyword(keyword_id, term); 79} 80 81bool ChromeAutocompleteProviderClient::TabSyncEnabledAndUnencrypted() { 82 // Check field trials and settings allow sending the URL on suggest requests. 83 ProfileSyncService* service = 84 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 85 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); 86 return service && 87 service->IsSyncEnabledAndLoggedIn() && 88 sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( 89 syncer::PROXY_TABS) && 90 !service->GetEncryptedDataTypes().Has(syncer::SESSIONS); 91} 92 93void ChromeAutocompleteProviderClient::PrefetchImage(const GURL& url) { 94 BitmapFetcherService* image_service = 95 BitmapFetcherServiceFactory::GetForBrowserContext(profile_); 96 DCHECK(image_service); 97 image_service->Prefetch(url); 98} 99