File: autofill_webdata_service.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (300 lines) | stat: -rw-r--r-- 13,041 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_

#include <string>
#include <string_view>
#include <vector>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/supports_user_data.h"
#include "base/uuid.h"
#include "components/autofill/core/browser/data_model/addresses/autofill_profile.h"
#include "components/autofill/core/browser/data_model/autofill_ai/entity_instance.h"
#include "components/autofill/core/browser/data_model/valuables/loyalty_card.h"
#include "components/autofill/core/browser/webdata/autofill_change.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/sync/base/data_type.h"
#include "components/webdata/common/web_data_results.h"
#include "components/webdata/common/web_data_service_base.h"
#include "components/webdata/common/web_data_service_consumer.h"

class WebDatabaseService;

namespace base {
class SequencedTaskRunner;
}

namespace autofill {

class AutocompleteEntry;
class AutofillWebDataBackend;
class AutofillWebDataBackendImpl;
class AutofillWebDataServiceObserverOnDBSequence;
class AutofillWebDataServiceObserverOnUISequence;
class CreditCard;
class Iban;

// API for Autofill web data.
class AutofillWebDataService : public WebDataServiceBase {
 public:
  // Runs db tasks on the wdbs db task runner.
  AutofillWebDataService(
      scoped_refptr<WebDatabaseService> wdbs,
      scoped_refptr<base::SequencedTaskRunner> ui_task_runner);

  AutofillWebDataService(const AutofillWebDataService&) = delete;
  AutofillWebDataService& operator=(const AutofillWebDataService&) = delete;

  // WebDataServiceBase implementation.
  void ShutdownOnUISequence() override;

  // Schedules a task to add form fields to the web database.
  virtual void AddFormFields(const std::vector<FormFieldData>& fields);

  // Initiates the request for a vector of values which have been entered in
  // form input fields named |name|. The method OnWebDataServiceRequestDone of
  // |consumer| gets called back when the request is finished, with the vector
  // included in the argument |result|.
  virtual WebDataServiceBase::Handle GetFormValuesForElementName(
      const std::u16string& name,
      const std::u16string& prefix,
      int limit,
      WebDataServiceRequestCallback consumer);

  // Removes form elements recorded for Autocomplete from the database.
  void RemoveFormElementsAddedBetween(base::Time delete_begin,
                                      base::Time delete_end);
  void RemoveFormValueForElementName(const std::u16string& name,
                                     const std::u16string& value);

  // Schedules a task to add an Autofill profile to the web database.
  void AddAutofillProfile(
      const AutofillProfile& profile,
      base::OnceCallback<void(const AutofillProfileChange&)> on_success);

  // Schedules a task to update an Autofill profile in the web database.
  void UpdateAutofillProfile(
      const AutofillProfile& profile,
      base::OnceCallback<void(const AutofillProfileChange&)> on_success);

  // Schedules a task to remove an Autofill profile from the web database.
  // `guid` is the identifier of the profile to remove.
  // In practice `change_type` will either be `REMOVE` or `HIDE_IN_AUTOFILL`. It
  // will be used to determine what type of change (permanent remove or update)
  // should happen on the server. Both of them result in the entry being removed
  // from the local database.
  // Important: `HIDE_IN_AUTOFILL` should only be used
  // for calls from the deduplication logic for account profiles.
  void RemoveAutofillProfile(
      const std::string& guid,
      AutofillProfileChange::Type change_type,
      base::OnceCallback<void(const AutofillProfileChange&)> on_success);

  // Initiates the request for Autofill profiles. The profiles are passed to the
  // `consumer` callback.
  WebDataServiceBase::Handle GetAutofillProfiles(
      WebDataServiceRequestCallback consumer);

  // See the identically named functions in EntityDataManager or EntityTable for
  // details.
  // `on_success` is called only if the operation has been completed.
  void AddOrUpdateEntityInstance(
      EntityInstance entity,
      base::OnceCallback<void(EntityInstanceChange)> on_success);
  void RemoveEntityInstance(
      base::Uuid guid,
      base::OnceCallback<void(EntityInstanceChange)> on_success);
  void RemoveEntityInstancesModifiedBetween(base::Time delete_begin,
                                            base::Time delete_end);
  WebDataServiceBase::Handle GetEntityInstances(
      WebDataServiceRequestCallback consumer);

  // Retrieves LoyaltyCards from the database.
  WebDataServiceBase::Handle GetLoyaltyCards(
      WebDataServiceRequestCallback consumer);

  // Schedules a task to count the number of unique autofill values contained
  // in the time interval [|begin|, |end|). |begin| and |end| can be null
  // to indicate no time limitation.
  WebDataServiceBase::Handle GetCountOfValuesContainedBetween(
      base::Time begin,
      base::Time end,
      WebDataServiceRequestCallback consumer);

  // Schedules a task to update autocomplete entries in the web database.
  void UpdateAutocompleteEntries(
      const std::vector<AutocompleteEntry>& autocomplete_entries);

  // Schedules a task to add a local IBAN to the web database.
  void AddLocalIban(const Iban& iban);

  // Initiates the request for local/server IBANs. The method
  // OnWebDataServiceRequestDone of |consumer| gets called when the request is
  // finished, with the IBAN included in the argument |result|. The consumer
  // owns the IBAN.
  WebDataServiceBase::Handle GetLocalIbans(
      WebDataServiceRequestCallback consumer);
  WebDataServiceBase::Handle GetServerIbans(
      WebDataServiceRequestCallback consumer);

  // Schedules a task to update a local IBAN in the web database.
  void UpdateLocalIban(const Iban& iban);

  // Schedules a task to remove an existing local IBAN from the web database.
  // `guid` is the identifier of the IBAN to remove.
  void RemoveLocalIban(const std::string& guid);

  // Updates the metadata for a server IBAN.
  void UpdateServerIbanMetadata(const Iban& iban);

  // Schedules a task to add credit card to the web database.
  void AddCreditCard(const CreditCard& credit_card);

  // Schedules a task to update credit card in the web database.
  void UpdateCreditCard(const CreditCard& credit_card);

  // Schedules a task to update a local CVC in the web database.
  void UpdateLocalCvc(const std::string& guid, const std::u16string& cvc);

  // Schedules a task to remove a credit card from the web database.
  // |guid| is identifier of the credit card to remove.
  void RemoveCreditCard(const std::string& guid);

  // Methods to schedule a task to add, update, remove, clear server cvc in the
  // web database.
  void AddServerCvc(int64_t instrument_id, const std::u16string& cvc);
  void UpdateServerCvc(int64_t instrument_id, const std::u16string& cvc);
  void RemoveServerCvc(int64_t instrument_id);
  void ClearServerCvcs();

  // Method to clear all the local CVCs from the web database.
  void ClearLocalCvcs();

  // Method to clean up for crbug.com/411681430.
  void CleanupForCrbug411681430();

  // Initiates the request for local/server credit cards.  The method
  // OnWebDataServiceRequestDone of |consumer| gets called when the request is
  // finished, with the credit cards included in the argument |result|.  The
  // consumer owns the credit cards.
  WebDataServiceBase::Handle GetCreditCards(
      WebDataServiceRequestCallback consumer);
  WebDataServiceBase::Handle GetServerCreditCards(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for Payments customer data.  The method
  // OnWebDataServiceRequestDone of |consumer| gets called when the request is
  // finished, with the customer data included in the argument |result|. The
  // consumer owns the data.
  WebDataServiceBase::Handle GetPaymentsCustomerData(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for server credit card cloud token data. The method
  // OnWebDataServiceRequestDone of |consumer| gets called when the request is
  // finished, with the cloud token data included in the argument |result|. The
  // consumer owns the data.
  WebDataServiceBase::Handle GetCreditCardCloudTokenData(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for autofill offer data. The method
  // OnWebDataServiceRequestDone of |consumer| gets called when the request is
  // finished, with the offer data included in the argument |result|. The
  // consumer owns the data.
  WebDataServiceBase::Handle GetAutofillOffers(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for virtual card usage data. The method
  // OnWebDataServiceRequestDone() of `consumer` gets called when the request is
  // finished, with the virtual card usage data included in the argument
  // `result`. The consumer owns the data.
  WebDataServiceBase::Handle GetVirtualCardUsageData(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for credit card benefits. The method
  // OnWebDataServiceRequestDone() of `consumer` gets called when the request is
  // finished, with the credit card benefits included in the argument `result`.
  // The consumer owns the data.
  WebDataServiceBase::Handle GetCreditCardBenefits(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for masked bank accounts. The method
  // OnWebDataServiceRequestDone() of `consumer` gets called when the request is
  // finished, with the masked bank accounts included in the argument `result`.
  // The consumer owns the data.
  WebDataServiceBase::Handle GetMaskedBankAccounts(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for payment instruments. The method
  // OnWebDataServiceRequestDone() of `consumer` gets called when the request is
  // finished, with the payment instruments included in the argument `result`.
  // The consumer owns the data.
  WebDataServiceBase::Handle GetPaymentInstruments(
      WebDataServiceRequestCallback consumer);

  // Initiates the request for payment instrument creation options from local
  // storage. The method OnWebDataServiceRequestDone() of `consumer` gets called
  // when the request is finished, with the payment instrument creation options
  // included in the argument `result`. The consumer owns the data.
  WebDataServiceBase::Handle GetPaymentInstrumentCreationOptions(
      WebDataServiceRequestCallback consumer);

  // Clears all the credit card benefits from the database.
  void ClearAllCreditCardBenefits();

  void ClearAllServerData();

  // Updates the metadata for a server card (masked or not).
  void UpdateServerCardMetadata(const CreditCard& credit_card);

  void AddObserver(AutofillWebDataServiceObserverOnDBSequence* observer);
  void RemoveObserver(AutofillWebDataServiceObserverOnDBSequence* observer);

  void AddObserver(AutofillWebDataServiceObserverOnUISequence* observer);
  void RemoveObserver(AutofillWebDataServiceObserverOnUISequence* observer);

  // Returns a SupportsUserData object that may be used to store data accessible
  // from the DB sequence. Should be called only from the DB sequence, and will
  // be destroyed on the DB sequence soon after ShutdownOnUISequence() is
  // called.
  base::SupportsUserData* GetDBUserData();

  // Takes a callback which will be called on the DB sequence with a pointer to
  // an AutofillWebdataBackend. This backend can be used to access or update the
  // WebDatabase directly on the DB sequence.
  void GetAutofillBackend(
      base::OnceCallback<void(AutofillWebDataBackend*)> callback);

  // Returns a task runner that can be used to schedule tasks on the DB
  // sequence.
  scoped_refptr<base::SequencedTaskRunner> GetDBTaskRunner();

  // Triggers an Autocomplete retention policy run which will cleanup data that
  // hasn't been used since over the retention threshold.
  virtual WebDataServiceBase::Handle RemoveExpiredAutocompleteEntries(
      WebDataServiceRequestCallback consumer);

  // Schedules a task to add a server credit card to the web database.
  //
  // This is used for tests only. In production, server cards are set directly
  // by Chrome Sync code.
  void AddServerCreditCardForTesting(const CreditCard& credit_card);

 protected:
  ~AutofillWebDataService() override;

 private:
  // The task runner that this class uses for UI tasks.
  scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;

  scoped_refptr<AutofillWebDataBackendImpl> autofill_backend_;
};

}  // namespace autofill

#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_