1 // Copyright (c) 2011 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_AUTOCOMPLETE_HISTORY_MANAGER_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ 7 #pragma once 8 9 #include <vector> 10 11 #include "chrome/browser/prefs/pref_member.h" 12 #include "chrome/browser/webdata/web_data_service.h" 13 #include "content/browser/tab_contents/tab_contents_observer.h" 14 15 namespace webkit_glue { 16 struct FormData; 17 } // namespace webkit_glue 18 19 class Profile; 20 class TabContents; 21 22 // Per-tab Autocomplete history manager. Handles receiving form data from the 23 // renderer and the storing and retrieving of form data through WebDataService. 24 class AutocompleteHistoryManager : public TabContentsObserver, 25 public WebDataServiceConsumer { 26 public: 27 explicit AutocompleteHistoryManager(TabContents* tab_contents); 28 virtual ~AutocompleteHistoryManager(); 29 30 // TabContentsObserver implementation. 31 virtual bool OnMessageReceived(const IPC::Message& message); 32 33 // WebDataServiceConsumer implementation. 34 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, 35 const WDTypedResult* result); 36 37 // Pass-through functions that are called by AutofillManager, after it has 38 // dispatched a message. 39 void OnGetAutocompleteSuggestions( 40 int query_id, 41 const string16& name, 42 const string16& prefix, 43 const std::vector<string16>& autofill_values, 44 const std::vector<string16>& autofill_labels, 45 const std::vector<string16>& autofill_icons, 46 const std::vector<int>& autofill_unique_ids); 47 void OnFormSubmitted(const webkit_glue::FormData& form); 48 49 protected: 50 friend class AutocompleteHistoryManagerTest; 51 friend class AutofillManagerTest; 52 53 // For tests. 54 AutocompleteHistoryManager(TabContents* tab_contents, 55 Profile* profile, 56 WebDataService* wds); 57 58 void SendSuggestions(const std::vector<string16>* suggestions); 59 void CancelPendingQuery(); 60 61 private: 62 void OnRemoveAutocompleteEntry(const string16& name, const string16& value); 63 64 Profile* profile_; 65 scoped_refptr<WebDataService> web_data_service_; 66 67 BooleanPrefMember autofill_enabled_; 68 69 // When the manager makes a request from WebDataService, 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 WebDataService::Handle pending_query_handle_; 73 int query_id_; 74 std::vector<string16> autofill_values_; 75 std::vector<string16> autofill_labels_; 76 std::vector<string16> autofill_icons_; 77 std::vector<int> autofill_unique_ids_; 78 79 DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager); 80 }; 81 82 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ 83