Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 
| 6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 6 #define COMPONENTS_AUTOFILL_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/browser/webdata/autofill_webdata_service.h" | 12 #include "components/autofill/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 #include "content/public/browser/web_contents_observer.h" | |
| 15 | 14 | 
| 16 namespace content { | 15 namespace content { | 
| 17 class BrowserContext; | 16 class BrowserContext; | 
| 17 class WebContents; | |
| 18 } | 18 } | 
| 19 | 19 | 
| 20 namespace autofill { | 20 namespace autofill { | 
| 21 | 21 | 
| 22 class AutofillExternalDelegate; | 22 class AutofillExternalDelegate; | 
| 23 struct FormData; | 23 struct FormData; | 
| 24 | 24 | 
| 25 // Per-tab Autocomplete history manager. Handles receiving form data | 25 // Per-tab Autocomplete history manager. Handles receiving form data | 
| 26 // from the renderer and the storing and retrieving of form data | 26 // from the renderer and the storing and retrieving of form data | 
| 27 // through WebDataServiceBase. | 27 // through WebDataServiceBase. | 
| 28 class AutocompleteHistoryManager : public content::WebContentsObserver, | 28 class AutocompleteHistoryManager : public WebDataServiceConsumer { | 
| 29 public WebDataServiceConsumer { | |
| 30 public: | 29 public: | 
| 31 explicit AutocompleteHistoryManager(content::WebContents* web_contents); | 30 explicit AutocompleteHistoryManager(content::WebContents* web_contents); | 
| 32 virtual ~AutocompleteHistoryManager(); | 31 virtual ~AutocompleteHistoryManager(); | 
| 33 | 32 | 
| 34 // content::WebContentsObserver implementation. | |
| 35 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 36 | |
| 37 // WebDataServiceConsumer implementation. | 33 // WebDataServiceConsumer implementation. | 
| 38 virtual void OnWebDataServiceRequestDone( | 34 virtual void OnWebDataServiceRequestDone( | 
| 39 WebDataServiceBase::Handle h, | 35 WebDataServiceBase::Handle h, | 
| 40 const WDTypedResult* result) OVERRIDE; | 36 const WDTypedResult* result) OVERRIDE; | 
| 41 | 37 | 
| 42 // Pass-through functions that are called by AutofillManager, after it has | 38 // Pass-through functions that are called by AutofillManager, after it has | 
| 43 // dispatched a message. | 39 // dispatched a message. | 
| 44 void OnGetAutocompleteSuggestions( | 40 void OnGetAutocompleteSuggestions( | 
| 45 int query_id, | 41 int query_id, | 
| 46 const base::string16& name, | 42 const base::string16& name, | 
| 47 const base::string16& prefix, | 43 const base::string16& prefix, | 
| 48 const std::vector<base::string16>& autofill_values, | 44 const std::vector<base::string16>& autofill_values, | 
| 49 const std::vector<base::string16>& autofill_labels, | 45 const std::vector<base::string16>& autofill_labels, | 
| 50 const std::vector<base::string16>& autofill_icons, | 46 const std::vector<base::string16>& autofill_icons, | 
| 51 const std::vector<int>& autofill_unique_ids); | 47 const std::vector<int>& autofill_unique_ids); | 
| 52 void OnFormSubmitted(const FormData& form); | 48 void OnFormSubmitted(const FormData& form); | 
| 53 | 49 | 
| 54 // Must be public for the external delegate to use. | 50 // Must be public for the external delegate to use. | 
| 55 void OnRemoveAutocompleteEntry(const base::string16& name, | 51 void OnRemoveAutocompleteEntry(const base::string16& name, | 
| 56 const base::string16& value); | 52 const base::string16& value); | 
| 57 | 53 | 
| 58 // Sets our external delegate. | 54 // Sets our external delegate. | 
| 59 void SetExternalDelegate(AutofillExternalDelegate* delegate); | 55 void SetExternalDelegate(AutofillExternalDelegate* delegate); | 
| 60 | 56 | 
| 61 protected: | 57 protected: | 
| 62 friend class AutofillManagerTest; | 58 friend class AutofillManagerTest; | 
| 59 FRIEND_TEST_ALL_PREFIXES(AutocompleteHistoryManagerTest, ExternalDelegate); | |
| 
 
Ilya Sherman
2013/06/05 10:50:02
Why is this needed?
 
blundell
2013/06/11 15:35:47
To disable sending IPC. Previously a custom subcla
 
Ilya Sherman
2013/06/12 00:07:46
Using a custom subclass is preferable, as it expos
 
blundell
2013/06/12 16:29:37
Done.
 
 | |
| 63 | 60 | 
| 64 // Sends the given |suggestions| for display in the Autofill popup. | 61 // Sends the given |suggestions| for display in the Autofill popup. | 
| 65 void SendSuggestions(const std::vector<base::string16>* suggestions); | 62 void SendSuggestions(const std::vector<base::string16>* suggestions); | 
| 66 | 63 | 
| 67 private: | 64 private: | 
| 65 | |
| 
 
Ilya Sherman
2013/06/05 10:50:02
nit: Spurious blank line.
 
blundell
2013/06/11 15:35:47
Done.
 
 | |
| 68 // Cancels the currently pending WebDataService query, if there is one. | 66 // Cancels the currently pending WebDataService query, if there is one. | 
| 69 void CancelPendingQuery(); | 67 void CancelPendingQuery(); | 
| 70 | 68 | 
| 71 content::BrowserContext* browser_context_; | 69 content::BrowserContext* browser_context_; | 
| 70 content::WebContents* web_contents_; | |
| 72 scoped_refptr<AutofillWebDataService> autofill_data_; | 71 scoped_refptr<AutofillWebDataService> autofill_data_; | 
| 73 | 72 | 
| 74 BooleanPrefMember autofill_enabled_; | 73 BooleanPrefMember autofill_enabled_; | 
| 75 | 74 | 
| 76 // When the manager makes a request from WebDataServiceBase, the database is | 75 // When the manager makes a request from WebDataServiceBase, the database is | 
| 77 // queried on another thread, we record the query handle until we get called | 76 // queried on another thread, we record the query handle until we get called | 
| 78 // back. We also store the autofill results so we can send them together. | 77 // back. We also store the autofill results so we can send them together. | 
| 79 WebDataServiceBase::Handle pending_query_handle_; | 78 WebDataServiceBase::Handle pending_query_handle_; | 
| 80 int query_id_; | 79 int query_id_; | 
| 81 std::vector<base::string16> autofill_values_; | 80 std::vector<base::string16> autofill_values_; | 
| 82 std::vector<base::string16> autofill_labels_; | 81 std::vector<base::string16> autofill_labels_; | 
| 83 std::vector<base::string16> autofill_icons_; | 82 std::vector<base::string16> autofill_icons_; | 
| 84 std::vector<int> autofill_unique_ids_; | 83 std::vector<int> autofill_unique_ids_; | 
| 85 | 84 | 
| 86 // Delegate to perform external processing (display, selection) on | 85 // Delegate to perform external processing (display, selection) on | 
| 87 // our behalf. Weak. | 86 // our behalf. Weak. | 
| 88 AutofillExternalDelegate* external_delegate_; | 87 AutofillExternalDelegate* external_delegate_; | 
| 89 | 88 | 
| 89 // Used by tests to disable sending IPC. | |
| 90 bool send_IPC_; | |
| 91 | |
| 90 DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager); | 92 DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager); | 
| 91 }; | 93 }; | 
| 92 | 94 | 
| 93 } // namespace autofill | 95 } // namespace autofill | 
| 94 | 96 | 
| 95 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 97 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 
| OLD | NEW |