autocomplete_history_manager.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1// Copyright 2013 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 COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
6#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
7
8#include <vector>
9
10#include "base/gtest_prod_util.h"
11#include "base/prefs/pref_member.h"
12#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
13#include "components/webdata/common/web_data_service_consumer.h"
14
15namespace content {
16class BrowserContext;
17class WebContents;
18}
19
20namespace autofill {
21
22class AutofillDriver;
23class AutofillExternalDelegate;
24class AutofillManagerDelegate;
25struct FormData;
26
27// Per-tab Autocomplete history manager. Handles receiving form data
28// from the renderer and the storing and retrieving of form data
29// through WebDataServiceBase.
30class AutocompleteHistoryManager : public WebDataServiceConsumer {
31 public:
32  AutocompleteHistoryManager(AutofillDriver* driver,
33                             AutofillManagerDelegate* delegate);
34  virtual ~AutocompleteHistoryManager();
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 base::string16& name,
46      const base::string16& prefix,
47      const std::vector<base::string16>& autofill_values,
48      const std::vector<base::string16>& autofill_labels,
49      const std::vector<base::string16>& autofill_icons,
50      const std::vector<int>& autofill_unique_ids);
51  virtual void OnFormSubmitted(const FormData& form);
52
53  // Must be public for the external delegate to use.
54  void OnRemoveAutocompleteEntry(const base::string16& name,
55                                 const base::string16& value);
56
57  // Sets our external delegate.
58  void SetExternalDelegate(AutofillExternalDelegate* delegate);
59
60 protected:
61  friend class AutofillManagerTest;
62
63  // Sends the given |suggestions| for display in the Autofill popup.
64  void SendSuggestions(const std::vector<base::string16>* suggestions);
65
66  // Used by tests to disable sending IPC.
67  void set_send_ipc(bool send_ipc) { send_ipc_ = send_ipc; }
68
69 private:
70  // Cancels the currently pending WebDataService query, if there is one.
71  void CancelPendingQuery();
72
73  content::BrowserContext* browser_context_;
74  // Provides driver-level context. Must outlive this object.
75  AutofillDriver* driver_;
76  scoped_refptr<AutofillWebDataService> autofill_data_;
77
78  // When the manager makes a request from WebDataServiceBase, the database is
79  // queried on another thread, we record the query handle until we get called
80  // back.  We also store the autofill results so we can send them together.
81  WebDataServiceBase::Handle pending_query_handle_;
82  int query_id_;
83  std::vector<base::string16> autofill_values_;
84  std::vector<base::string16> autofill_labels_;
85  std::vector<base::string16> autofill_icons_;
86  std::vector<int> autofill_unique_ids_;
87
88  // Delegate to perform external processing (display, selection) on
89  // our behalf.  Weak.
90  AutofillExternalDelegate* external_delegate_;
91
92  // Delegate to provide whether or not autocomplete functionality is enabled.
93  AutofillManagerDelegate* const manager_delegate_;
94
95  // Whether IPC is sent.
96  bool send_ipc_;
97
98  DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager);
99};
100
101}  // namespace autofill
102
103#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
104