OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/gtest_prod_util.h" |
11 #include "chrome/browser/prefs/pref_member.h" | 12 #include "chrome/browser/prefs/pref_member.h" |
12 #include "chrome/browser/webdata/web_data_service.h" | 13 #include "chrome/browser/webdata/web_data_service.h" |
13 #include "content/browser/tab_contents/tab_contents_observer.h" | 14 #include "content/browser/tab_contents/tab_contents_observer.h" |
14 | 15 |
15 namespace webkit_glue { | 16 namespace webkit_glue { |
16 struct FormData; | 17 struct FormData; |
17 } // namespace webkit_glue | 18 } // namespace webkit_glue |
18 | 19 |
| 20 class AutofillExternalDelegate; |
19 class Profile; | 21 class Profile; |
20 class TabContents; | 22 class TabContents; |
21 | 23 |
22 // Per-tab Autocomplete history manager. Handles receiving form data from the | 24 // Per-tab Autocomplete history manager. Handles receiving form data from the |
23 // renderer and the storing and retrieving of form data through WebDataService. | 25 // renderer and the storing and retrieving of form data through WebDataService. |
24 class AutocompleteHistoryManager : public TabContentsObserver, | 26 class AutocompleteHistoryManager : public TabContentsObserver, |
25 public WebDataServiceConsumer { | 27 public WebDataServiceConsumer { |
26 public: | 28 public: |
27 explicit AutocompleteHistoryManager(TabContents* tab_contents); | 29 explicit AutocompleteHistoryManager(TabContents* tab_contents); |
28 virtual ~AutocompleteHistoryManager(); | 30 virtual ~AutocompleteHistoryManager(); |
(...skipping 10 matching lines...) Expand all Loading... |
39 void OnGetAutocompleteSuggestions( | 41 void OnGetAutocompleteSuggestions( |
40 int query_id, | 42 int query_id, |
41 const string16& name, | 43 const string16& name, |
42 const string16& prefix, | 44 const string16& prefix, |
43 const std::vector<string16>& autofill_values, | 45 const std::vector<string16>& autofill_values, |
44 const std::vector<string16>& autofill_labels, | 46 const std::vector<string16>& autofill_labels, |
45 const std::vector<string16>& autofill_icons, | 47 const std::vector<string16>& autofill_icons, |
46 const std::vector<int>& autofill_unique_ids); | 48 const std::vector<int>& autofill_unique_ids); |
47 void OnFormSubmitted(const webkit_glue::FormData& form); | 49 void OnFormSubmitted(const webkit_glue::FormData& form); |
48 | 50 |
| 51 // Sets our external delegate. |
| 52 void SetExternalDelegate(AutofillExternalDelegate* delegate) { |
| 53 external_delegate_ = delegate; |
| 54 } |
| 55 |
49 protected: | 56 protected: |
50 friend class AutocompleteHistoryManagerTest; | 57 friend class AutocompleteHistoryManagerTest; |
51 friend class AutofillManagerTest; | 58 friend class AutofillManagerTest; |
| 59 FRIEND_TEST_ALL_PREFIXES(AutocompleteHistoryManagerTest, ExternalDelegate); |
| 60 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, TestTabContents); |
52 | 61 |
53 // For tests. | 62 // For tests. |
54 AutocompleteHistoryManager(TabContents* tab_contents, | 63 AutocompleteHistoryManager(TabContents* tab_contents, |
55 Profile* profile, | 64 Profile* profile, |
56 WebDataService* wds); | 65 WebDataService* wds); |
57 | 66 |
58 void SendSuggestions(const std::vector<string16>* suggestions); | 67 void SendSuggestions(const std::vector<string16>* suggestions); |
59 void CancelPendingQuery(); | 68 void CancelPendingQuery(); |
60 | 69 |
| 70 // Exposed for testing. |
| 71 AutofillExternalDelegate* external_delegate() { |
| 72 return external_delegate_; |
| 73 } |
| 74 |
61 private: | 75 private: |
62 void OnRemoveAutocompleteEntry(const string16& name, const string16& value); | 76 void OnRemoveAutocompleteEntry(const string16& name, const string16& value); |
63 | 77 |
64 Profile* profile_; | 78 Profile* profile_; |
65 scoped_refptr<WebDataService> web_data_service_; | 79 scoped_refptr<WebDataService> web_data_service_; |
66 | 80 |
67 BooleanPrefMember autofill_enabled_; | 81 BooleanPrefMember autofill_enabled_; |
68 | 82 |
69 // When the manager makes a request from WebDataService, the database is | 83 // 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 | 84 // 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. | 85 // back. We also store the autofill results so we can send them together. |
72 WebDataService::Handle pending_query_handle_; | 86 WebDataService::Handle pending_query_handle_; |
73 int query_id_; | 87 int query_id_; |
74 std::vector<string16> autofill_values_; | 88 std::vector<string16> autofill_values_; |
75 std::vector<string16> autofill_labels_; | 89 std::vector<string16> autofill_labels_; |
76 std::vector<string16> autofill_icons_; | 90 std::vector<string16> autofill_icons_; |
77 std::vector<int> autofill_unique_ids_; | 91 std::vector<int> autofill_unique_ids_; |
78 | 92 |
| 93 // Delegate to perform external processing (display, selection) on |
| 94 // our behalf. Weak. |
| 95 AutofillExternalDelegate* external_delegate_; |
| 96 |
79 DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager); | 97 DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager); |
80 }; | 98 }; |
81 | 99 |
82 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ | 100 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_ |
OLD | NEW |