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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
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"
18 class AutofillExternalDelegate;
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 {
27 AutocompleteHistoryManager(AutofillDriver* driver,
28 AutofillClient* autofill_client);
29 ~AutocompleteHistoryManager() override;
31 // WebDataServiceConsumer implementation.
32 void OnWebDataServiceRequestDone(WebDataServiceBase::Handle h,
33 const WDTypedResult* result) override;
35 // Pass-through functions that are called by AutofillManager, after it has
36 // dispatched a message.
37 virtual void OnGetAutocompleteSuggestions(
39 const base::string16& name,
40 const base::string16& prefix,
41 const std::string& form_control_type,
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);
48 // Cancels the currently pending WebDataService query, if there is one.
49 void CancelPendingQuery();
51 // Must be public for the external delegate to use.
52 void OnRemoveAutocompleteEntry(const base::string16& name,
53 const base::string16& value);
55 // Sets our external delegate.
56 void SetExternalDelegate(AutofillExternalDelegate* delegate);
59 friend class AutofillManagerTest;
61 // Sends the given |suggestions| for display in the Autofill popup.
62 void SendSuggestions(const std::vector<base::string16>* suggestions);
65 // Provides driver-level context. Must outlive this object.
66 AutofillDriver* driver_;
67 scoped_refptr<AutofillWebDataService> database_;
69 // When the manager makes a request from WebDataServiceBase, the database is
70 // queried on another thread, we record the query handle until we get called
71 // back. We also store the autofill results so we can send them together.
72 WebDataServiceBase::Handle pending_query_handle_;
74 std::vector<base::string16> autofill_values_;
75 std::vector<base::string16> autofill_labels_;
76 std::vector<base::string16> autofill_icons_;
77 std::vector<int> autofill_unique_ids_;
79 // Delegate to perform external processing (display, selection) on
81 AutofillExternalDelegate* external_delegate_;
83 // Delegate to provide whether or not autocomplete functionality is enabled.
84 AutofillClient* const autofill_client_;
86 // Whether IPC is sent.
89 DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager);
92 } // namespace autofill
94 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_