Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc

Issue 1185723002: Prepare HistoryProvider for componentization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" 5 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
10 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" 10 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" 11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
12 #include "chrome/browser/history/history_service_factory.h" 13 #include "chrome/browser/history/history_service_factory.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sync/profile_sync_service.h" 15 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "chrome/browser/sync/profile_sync_service_factory.h" 16 #include "chrome/browser/sync/profile_sync_service_factory.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "components/history/core/browser/history_service.h" 18 #include "components/history/core/browser/history_service.h"
18 19
19 ChromeAutocompleteProviderClient::ChromeAutocompleteProviderClient( 20 ChromeAutocompleteProviderClient::ChromeAutocompleteProviderClient(
20 Profile* profile) 21 Profile* profile)
21 : profile_(profile), 22 : profile_(profile),
(...skipping 22 matching lines...) Expand all
44 45
45 bool ChromeAutocompleteProviderClient::ShowBookmarkBar() { 46 bool ChromeAutocompleteProviderClient::ShowBookmarkBar() {
46 return profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar); 47 return profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar);
47 } 48 }
48 49
49 const AutocompleteSchemeClassifier& 50 const AutocompleteSchemeClassifier&
50 ChromeAutocompleteProviderClient::SchemeClassifier() { 51 ChromeAutocompleteProviderClient::SchemeClassifier() {
51 return scheme_classifier_; 52 return scheme_classifier_;
52 } 53 }
53 54
55 history::HistoryService* ChromeAutocompleteProviderClient::HistoryService() {
56 return HistoryServiceFactory::GetForProfile(
57 profile_, ServiceAccessType::EXPLICIT_ACCESS);
58 }
59
60 bookmarks::BookmarkModel* ChromeAutocompleteProviderClient::BookmarkModel() {
61 return BookmarkModelFactory::GetForProfile(profile_);
62 }
63
54 void ChromeAutocompleteProviderClient::Classify( 64 void ChromeAutocompleteProviderClient::Classify(
55 const base::string16& text, 65 const base::string16& text,
56 bool prefer_keyword, 66 bool prefer_keyword,
57 bool allow_exact_keyword_match, 67 bool allow_exact_keyword_match,
58 metrics::OmniboxEventProto::PageClassification page_classification, 68 metrics::OmniboxEventProto::PageClassification page_classification,
59 AutocompleteMatch* match, 69 AutocompleteMatch* match,
60 GURL* alternate_nav_url) { 70 GURL* alternate_nav_url) {
61 AutocompleteClassifier* classifier = 71 AutocompleteClassifier* classifier =
62 AutocompleteClassifierFactory::GetForProfile(profile_); 72 AutocompleteClassifierFactory::GetForProfile(profile_);
63 DCHECK(classifier); 73 DCHECK(classifier);
64 classifier->Classify(text, prefer_keyword, allow_exact_keyword_match, 74 classifier->Classify(text, prefer_keyword, allow_exact_keyword_match,
65 page_classification, match, alternate_nav_url); 75 page_classification, match, alternate_nav_url);
66 } 76 }
67 77
68 history::URLDatabase* ChromeAutocompleteProviderClient::InMemoryDatabase() { 78 history::URLDatabase* ChromeAutocompleteProviderClient::InMemoryDatabase() {
69 history::HistoryService* history_service = 79 // This method is called in unit test contexts where the HistoryService isn't
70 HistoryServiceFactory::GetForProfile(profile_, 80 // loaded.
Peter Kasting 2015/06/16 00:03:42 Tiny nit: I'd put this comment below the next stat
blundell 2015/06/16 07:21:25 Done.
71 ServiceAccessType::EXPLICIT_ACCESS); 81 history::HistoryService* history_service = HistoryService();
72 return history_service ? history_service->InMemoryDatabase() : NULL; 82 return history_service ? history_service->InMemoryDatabase() : NULL;
73 } 83 }
74 84
75 void ChromeAutocompleteProviderClient::DeleteMatchingURLsForKeywordFromHistory( 85 void ChromeAutocompleteProviderClient::DeleteMatchingURLsForKeywordFromHistory(
76 history::KeywordID keyword_id, 86 history::KeywordID keyword_id,
77 const base::string16& term) { 87 const base::string16& term) {
78 HistoryServiceFactory::GetForProfile(profile_, 88 HistoryService()->DeleteMatchingURLsForKeyword(keyword_id, term);
79 ServiceAccessType::EXPLICIT_ACCESS)
80 ->DeleteMatchingURLsForKeyword(keyword_id, term);
81 } 89 }
82 90
83 bool ChromeAutocompleteProviderClient::TabSyncEnabledAndUnencrypted() { 91 bool ChromeAutocompleteProviderClient::TabSyncEnabledAndUnencrypted() {
84 // Check field trials and settings allow sending the URL on suggest requests. 92 // Check field trials and settings allow sending the URL on suggest requests.
85 ProfileSyncService* service = 93 ProfileSyncService* service =
86 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 94 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
87 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); 95 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
88 return service && 96 return service &&
89 service->IsSyncEnabledAndLoggedIn() && 97 service->IsSyncEnabledAndLoggedIn() &&
90 sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( 98 sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has(
91 syncer::PROXY_TABS) && 99 syncer::PROXY_TABS) &&
92 !service->GetEncryptedDataTypes().Has(syncer::SESSIONS); 100 !service->GetEncryptedDataTypes().Has(syncer::SESSIONS);
93 } 101 }
94 102
95 void ChromeAutocompleteProviderClient::PrefetchImage(const GURL& url) { 103 void ChromeAutocompleteProviderClient::PrefetchImage(const GURL& url) {
96 BitmapFetcherService* image_service = 104 BitmapFetcherService* image_service =
97 BitmapFetcherServiceFactory::GetForBrowserContext(profile_); 105 BitmapFetcherServiceFactory::GetForBrowserContext(profile_);
98 DCHECK(image_service); 106 DCHECK(image_service);
99 image_service->Prefetch(url); 107 image_service->Prefetch(url);
100 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698