1 // Copyright 2013 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_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ 7 8 #include <vector> 9 10 #include "base/gtest_prod_util.h" 11 #include "base/prefs/pref_member.h" 12 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 13 #include "components/webdata/common/web_data_service_consumer.h" 14 15 namespace autofill { 16 17 class AutofillDriver; 18 class AutofillExternalDelegate; 19 class AutofillManagerDelegate; 20 struct FormData; 21 22 // Per-tab Autocomplete history manager. Handles receiving form data 23 // from the renderer and the storing and retrieving of form data 24 // through WebDataServiceBase. 25 class AutocompleteHistoryManager : public WebDataServiceConsumer { 26 public: 27 AutocompleteHistoryManager(AutofillDriver* driver, 28 AutofillManagerDelegate* delegate); 29 virtual ~AutocompleteHistoryManager(); 30 31 // WebDataServiceConsumer implementation. 32 virtual void OnWebDataServiceRequestDone( 33 WebDataServiceBase::Handle h, 34 const WDTypedResult* result) OVERRIDE; 35 36 // Pass-through functions that are called by AutofillManager, after it has 37 // dispatched a message. 38 void OnGetAutocompleteSuggestions( 39 int query_id, 40 const base::string16& name, 41 const base::string16& prefix, 42 const std::vector<base::string16>& autofill_values, 43 const std::vector<base::string16>& autofill_labels, 44 const std::vector<base::string16>& autofill_icons, 45 const std::vector<int>& autofill_unique_ids); 46 virtual void OnFormSubmitted(const FormData& form); 47 48 // Must be public for the external delegate to use. 49 void OnRemoveAutocompleteEntry(const base::string16& name, 50 const base::string16& value); 51 52 // Sets our external delegate. 53 void SetExternalDelegate(AutofillExternalDelegate* delegate); 54 55 protected: 56 friend class AutofillManagerTest; 57 58 // Sends the given |suggestions| for display in the Autofill popup. 59 void SendSuggestions(const std::vector<base::string16>* suggestions); 60 61 // Used by tests to disable sending IPC. set_send_ipc(bool send_ipc)62 void set_send_ipc(bool send_ipc) { send_ipc_ = send_ipc; } 63 64 private: 65 // Cancels the currently pending WebDataService query, if there is one. 66 void CancelPendingQuery(); 67 68 // Provides driver-level context. Must outlive this object. 69 AutofillDriver* driver_; 70 scoped_refptr<AutofillWebDataService> database_; 71 72 // When the manager makes a request from WebDataServiceBase, the database is 73 // queried on another thread, we record the query handle until we get called 74 // back. We also store the autofill results so we can send them together. 75 WebDataServiceBase::Handle pending_query_handle_; 76 int query_id_; 77 std::vector<base::string16> autofill_values_; 78 std::vector<base::string16> autofill_labels_; 79 std::vector<base::string16> autofill_icons_; 80 std::vector<int> autofill_unique_ids_; 81 82 // Delegate to perform external processing (display, selection) on 83 // our behalf. Weak. 84 AutofillExternalDelegate* external_delegate_; 85 86 // Delegate to provide whether or not autocomplete functionality is enabled. 87 AutofillManagerDelegate* const manager_delegate_; 88 89 // Whether IPC is sent. 90 bool send_ipc_; 91 92 DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager); 93 }; 94 95 } // namespace autofill 96 97 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ 98