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