Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: components/autofill/browser/autocomplete_history_manager.h

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nit Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 AutofillDriver;
22 class AutofillExternalDelegate; 23 class AutofillExternalDelegate;
23 struct FormData; 24 struct FormData;
24 25
25 // Per-tab Autocomplete history manager. Handles receiving form data 26 // Per-tab Autocomplete history manager. Handles receiving form data
26 // from the renderer and the storing and retrieving of form data 27 // from the renderer and the storing and retrieving of form data
27 // through WebDataServiceBase. 28 // through WebDataServiceBase.
28 class AutocompleteHistoryManager : public content::WebContentsObserver, 29 class AutocompleteHistoryManager : public WebDataServiceConsumer {
29 public WebDataServiceConsumer {
30 public: 30 public:
31 explicit AutocompleteHistoryManager(content::WebContents* web_contents); 31 explicit AutocompleteHistoryManager(AutofillDriver* driver);
32 virtual ~AutocompleteHistoryManager(); 32 virtual ~AutocompleteHistoryManager();
33 33
34 // content::WebContentsObserver implementation.
35 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
36
37 // WebDataServiceConsumer implementation. 34 // WebDataServiceConsumer implementation.
38 virtual void OnWebDataServiceRequestDone( 35 virtual void OnWebDataServiceRequestDone(
39 WebDataServiceBase::Handle h, 36 WebDataServiceBase::Handle h,
40 const WDTypedResult* result) OVERRIDE; 37 const WDTypedResult* result) OVERRIDE;
41 38
42 // Pass-through functions that are called by AutofillManager, after it has 39 // Pass-through functions that are called by AutofillManager, after it has
43 // dispatched a message. 40 // dispatched a message.
44 void OnGetAutocompleteSuggestions( 41 void OnGetAutocompleteSuggestions(
45 int query_id, 42 int query_id,
46 const base::string16& name, 43 const base::string16& name,
47 const base::string16& prefix, 44 const base::string16& prefix,
48 const std::vector<base::string16>& autofill_values, 45 const std::vector<base::string16>& autofill_values,
49 const std::vector<base::string16>& autofill_labels, 46 const std::vector<base::string16>& autofill_labels,
50 const std::vector<base::string16>& autofill_icons, 47 const std::vector<base::string16>& autofill_icons,
51 const std::vector<int>& autofill_unique_ids); 48 const std::vector<int>& autofill_unique_ids);
52 void OnFormSubmitted(const FormData& form); 49 void OnFormSubmitted(const FormData& form);
53 50
54 // Must be public for the external delegate to use. 51 // Must be public for the external delegate to use.
55 void OnRemoveAutocompleteEntry(const base::string16& name, 52 void OnRemoveAutocompleteEntry(const base::string16& name,
56 const base::string16& value); 53 const base::string16& value);
57 54
58 // Sets our external delegate. 55 // Sets our external delegate.
59 void SetExternalDelegate(AutofillExternalDelegate* delegate); 56 void SetExternalDelegate(AutofillExternalDelegate* delegate);
60 57
61 protected: 58 protected:
62 friend class AutofillManagerTest; 59 friend class AutofillManagerTest;
60 FRIEND_TEST_ALL_PREFIXES(AutocompleteHistoryManagerTest, ExternalDelegate);
63 61
64 // Sends the given |suggestions| for display in the Autofill popup. 62 // Sends the given |suggestions| for display in the Autofill popup.
65 void SendSuggestions(const std::vector<base::string16>* suggestions); 63 void SendSuggestions(const std::vector<base::string16>* suggestions);
66 64
67 private: 65 private:
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 AutofillDriver* driver_;
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_;
Ilya Sherman 2013/06/12 00:07:46 nit: If you keep this variable, it should use hack
blundell 2013/06/12 16:29:37 Done. It was a bug that the variable wasn't used;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698