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