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