OLD | NEW |
---|---|
(Empty) | |
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_delegate.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 | |
19 ChromeAutocompleteProviderDelegate::ChromeAutocompleteProviderDelegate( | |
20 Profile* profile) : profile_(profile), | |
Peter Kasting
2014/08/25 19:11:00
Nit: Put ": profile_(profile)," on a subsequent li
hashimoto
2014/08/26 00:52:30
Done.
| |
21 scheme_classifier_(profile) { | |
22 } | |
23 | |
24 ChromeAutocompleteProviderDelegate::~ChromeAutocompleteProviderDelegate() { | |
25 } | |
26 | |
27 net::URLRequestContextGetter* | |
28 ChromeAutocompleteProviderDelegate::GetRequestContext() { | |
29 return profile_->GetRequestContext(); | |
30 } | |
31 | |
32 bool ChromeAutocompleteProviderDelegate::IsOffTheRecord() { | |
33 return profile_->IsOffTheRecord(); | |
34 } | |
35 | |
36 std::string ChromeAutocompleteProviderDelegate::GetAcceptLanguages() { | |
37 return profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
38 } | |
39 | |
40 bool ChromeAutocompleteProviderDelegate::SearchSuggestEnabled() { | |
41 return profile_->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); | |
42 } | |
43 | |
44 bool ChromeAutocompleteProviderDelegate::ShowBookmarkBar() { | |
45 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | |
46 } | |
47 | |
48 const AutocompleteSchemeClassifier& | |
49 ChromeAutocompleteProviderDelegate::GetSchemeClassifier() { | |
50 return scheme_classifier_; | |
51 } | |
52 | |
53 void ChromeAutocompleteProviderDelegate::Classify( | |
54 const base::string16& text, | |
55 bool prefer_keyword, | |
56 bool allow_exact_keyword_match, | |
57 metrics::OmniboxEventProto::PageClassification page_classification, | |
58 AutocompleteMatch* match, | |
59 GURL* alternate_nav_url) { | |
60 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( | |
61 text, prefer_keyword, allow_exact_keyword_match, page_classification, | |
62 match, alternate_nav_url); | |
63 } | |
64 | |
65 history::URLDatabase* ChromeAutocompleteProviderDelegate::InMemoryDatabase() { | |
66 HistoryService* history_service = | |
67 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | |
68 return history_service ? history_service->InMemoryDatabase() : NULL; | |
69 } | |
70 | |
71 void | |
72 ChromeAutocompleteProviderDelegate::DeleteMatchingURLsForKeywordFromHistory( | |
73 history::KeywordID keyword_id, | |
74 const base::string16& term) { | |
75 HistoryService* const history_service = | |
Peter Kasting
2014/08/25 19:11:00
Nit: I'd just inline this into the next statement.
hashimoto
2014/08/26 00:52:30
Done.
| |
76 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | |
77 history_service->DeleteMatchingURLsForKeyword(keyword_id, term); | |
78 } | |
79 | |
80 bool ChromeAutocompleteProviderDelegate::TabSyncEnabledAndUnencrypted() { | |
81 // Check field trials and settings allow sending the URL on suggest requests. | |
82 ProfileSyncService* service = | |
83 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | |
84 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); | |
85 if (service == NULL || | |
Peter Kasting
2014/08/25 19:11:00
Nit: Convert this:
if (x)
return false;
r
hashimoto
2014/08/26 00:52:30
Done.
| |
86 !service->IsSyncEnabledAndLoggedIn() || | |
87 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( | |
88 syncer::PROXY_TABS) || | |
89 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) | |
90 return false; | |
91 return true; | |
92 } | |
93 | |
94 void ChromeAutocompleteProviderDelegate::PrefetchImage(const GURL& url) { | |
95 BitmapFetcherService* image_service = | |
96 BitmapFetcherServiceFactory::GetForBrowserContext(profile_); | |
97 DCHECK(image_service); | |
98 image_service->Prefetch(url); | |
99 } | |
OLD | NEW |