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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
// Copyright 2014 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 "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/shortcuts_backend_factory.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/top_sites_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/common/pref_names.h"
#include "components/history/core/browser/history_service.h"
#include "content/public/browser/notification_service.h"
ChromeAutocompleteProviderClient::ChromeAutocompleteProviderClient(
Profile* profile)
: profile_(profile),
scheme_classifier_(profile),
search_terms_data_(profile_) {
}
ChromeAutocompleteProviderClient::~ChromeAutocompleteProviderClient() {
}
net::URLRequestContextGetter*
ChromeAutocompleteProviderClient::GetRequestContext() {
return profile_->GetRequestContext();
}
PrefService* ChromeAutocompleteProviderClient::GetPrefs() {
return profile_->GetPrefs();
}
const AutocompleteSchemeClassifier&
ChromeAutocompleteProviderClient::GetSchemeClassifier() const {
return scheme_classifier_;
}
AutocompleteClassifier*
ChromeAutocompleteProviderClient::GetAutocompleteClassifier() {
return AutocompleteClassifierFactory::GetForProfile(profile_);
}
history::HistoryService* ChromeAutocompleteProviderClient::GetHistoryService() {
return HistoryServiceFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
}
scoped_refptr<history::TopSites>
ChromeAutocompleteProviderClient::GetTopSites() {
return TopSitesFactory::GetForProfile(profile_);
}
bookmarks::BookmarkModel* ChromeAutocompleteProviderClient::GetBookmarkModel() {
return BookmarkModelFactory::GetForProfile(profile_);
}
history::URLDatabase* ChromeAutocompleteProviderClient::GetInMemoryDatabase() {
history::HistoryService* history_service = GetHistoryService();
// This method is called in unit test contexts where the HistoryService isn't
// loaded.
return history_service ? history_service->InMemoryDatabase() : NULL;
}
TemplateURLService* ChromeAutocompleteProviderClient::GetTemplateURLService() {
return TemplateURLServiceFactory::GetForProfile(profile_);
}
const TemplateURLService*
ChromeAutocompleteProviderClient::GetTemplateURLService() const {
return TemplateURLServiceFactory::GetForProfile(profile_);
}
const
SearchTermsData& ChromeAutocompleteProviderClient::GetSearchTermsData() const {
return search_terms_data_;
}
scoped_refptr<ShortcutsBackend>
ChromeAutocompleteProviderClient::GetShortcutsBackend() {
return ShortcutsBackendFactory::GetForProfile(profile_);
}
scoped_refptr<ShortcutsBackend>
ChromeAutocompleteProviderClient::GetShortcutsBackendIfExists() {
return ShortcutsBackendFactory::GetForProfileIfExists(profile_);
}
std::string ChromeAutocompleteProviderClient::GetAcceptLanguages() const {
return profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
}
bool ChromeAutocompleteProviderClient::IsOffTheRecord() const {
return profile_->IsOffTheRecord();
}
bool ChromeAutocompleteProviderClient::SearchSuggestEnabled() const {
return profile_->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled);
}
bool ChromeAutocompleteProviderClient::BookmarkBarIsVisible() const {
return profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar);
}
bool ChromeAutocompleteProviderClient::TabSyncEnabledAndUnencrypted() const {
// Check field trials and settings allow sending the URL on suggest requests.
ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
return service && service->CanSyncStart() &&
sync_prefs.GetPreferredDataTypes(syncer::UserTypes())
.Has(syncer::PROXY_TABS) &&
!service->GetEncryptedDataTypes().Has(syncer::SESSIONS);
}
void ChromeAutocompleteProviderClient::Classify(
const base::string16& text,
bool prefer_keyword,
bool allow_exact_keyword_match,
metrics::OmniboxEventProto::PageClassification page_classification,
AutocompleteMatch* match,
GURL* alternate_nav_url) {
AutocompleteClassifier* classifier = GetAutocompleteClassifier();
DCHECK(classifier);
classifier->Classify(text, prefer_keyword, allow_exact_keyword_match,
page_classification, match, alternate_nav_url);
}
void ChromeAutocompleteProviderClient::DeleteMatchingURLsForKeywordFromHistory(
history::KeywordID keyword_id,
const base::string16& term) {
GetHistoryService()->DeleteMatchingURLsForKeyword(keyword_id, term);
}
void ChromeAutocompleteProviderClient::PrefetchImage(const GURL& url) {
BitmapFetcherService* image_service =
BitmapFetcherServiceFactory::GetForBrowserContext(profile_);
DCHECK(image_service);
image_service->Prefetch(url);
}
void ChromeAutocompleteProviderClient::OnAutocompleteControllerResultReady(
AutocompleteController* controller) {
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY,
content::Source<AutocompleteController>(controller),
content::NotificationService::NoDetails());
}
|