1 // Copyright 2019 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 #ifndef COMPONENTS_OMNIBOX_BROWSER_LOCAL_HISTORY_ZERO_SUGGEST_PROVIDER_H_ 6 #define COMPONENTS_OMNIBOX_BROWSER_LOCAL_HISTORY_ZERO_SUGGEST_PROVIDER_H_ 7 8 #include "base/memory/weak_ptr.h" 9 #include "base/strings/string16.h" 10 #include "base/task/cancelable_task_tracker.h" 11 #include "components/omnibox/browser/autocomplete_provider.h" 12 13 class AutocompleteProviderClient; 14 class AutocompleteProviderListener; 15 16 namespace history { 17 class QueryResults; 18 } // namespace history 19 20 // Autocomplete provider for on-focus zero-prefix query suggestions from local 21 // history when Google is the default search engine. 22 class LocalHistoryZeroSuggestProvider : public AutocompleteProvider { 23 public: 24 // Creates and returns an instance of this provider. 25 static LocalHistoryZeroSuggestProvider* Create( 26 AutocompleteProviderClient* client, 27 AutocompleteProviderListener* listener); 28 29 // AutocompleteProvider: 30 void Start(const AutocompleteInput& input, bool minimal_changes) override; 31 void DeleteMatch(const AutocompleteMatch& match) override; 32 33 private: 34 FRIEND_TEST_ALL_PREFIXES(LocalHistoryZeroSuggestProviderTest, Input); 35 36 LocalHistoryZeroSuggestProvider(AutocompleteProviderClient* client, 37 AutocompleteProviderListener* listener); 38 ~LocalHistoryZeroSuggestProvider() override; 39 LocalHistoryZeroSuggestProvider(const LocalHistoryZeroSuggestProvider&) = 40 delete; 41 LocalHistoryZeroSuggestProvider& operator=( 42 const LocalHistoryZeroSuggestProvider&) = delete; 43 44 // Queries the keyword search terms table of the in-memory URLDatabase for the 45 // recent search terms submitted to the default search provider. 46 void QueryURLDatabase(const AutocompleteInput& input); 47 48 // Called when the query results from HistoryService::QueryHistory are ready. 49 // Deletes URLs in |results| that would generate |suggestion|. |query_time| is 50 // the time HistoryService was queried. 51 void OnHistoryQueryResults(const base::string16& suggestion, 52 const base::TimeTicks& query_time, 53 history::QueryResults results); 54 55 // The maximum number of matches to return. 56 const size_t max_matches_; 57 58 // Client for accessing TemplateUrlService, prefs, etc. 59 AutocompleteProviderClient* const client_; 60 61 // Listener to notify when matches are available. 62 AutocompleteProviderListener* const listener_; 63 64 // Used for the async tasks querying the HistoryService. 65 base::CancelableTaskTracker history_task_tracker_; 66 67 base::WeakPtrFactory<LocalHistoryZeroSuggestProvider> weak_ptr_factory_{this}; 68 }; 69 70 #endif // COMPONENTS_OMNIBOX_BROWSER_LOCAL_HISTORY_ZERO_SUGGEST_PROVIDER_H_ 71