@@ -149,7 +149,8 @@ namespace api {
149
149
150
150
Autofill::Autofill (v8::Isolate* isolate,
151
151
content::BrowserContext* browser_context)
152
- : browser_context_(browser_context) {
152
+ : browser_context_(browser_context),
153
+ weak_ptr_factory_ (this ) {
153
154
Init (isolate);
154
155
}
155
156
@@ -340,6 +341,71 @@ bool Autofill::RemoveCreditCard(const std::string guid) {
340
341
return true ;
341
342
}
342
343
344
+ void Autofill::ClearAutocompleteData () {
345
+ scoped_refptr<autofill::AutofillWebDataService> web_data_service =
346
+ static_cast <brave::BraveBrowserContext*>(browser_context_)
347
+ ->GetAutofillWebdataService ();
348
+
349
+ if (web_data_service.get ()) {
350
+ base::Time delete_begin;
351
+ base::Time delete_end;
352
+ // TODO(Anthony Tseng): Specify time range from front end
353
+ delete_begin = delete_begin.UnixEpoch ();
354
+ delete_end = delete_end.Now ();
355
+ web_data_service->RemoveFormElementsAddedBetween (delete_begin,
356
+ delete_end);
357
+ // thread. So wait for it.
358
+ content::BrowserThread::PostTaskAndReply (content::BrowserThread::DB,
359
+ FROM_HERE,
360
+ base::Bind (&base::DoNothing),
361
+ base::Bind (&Autofill::OnClearedAutocompleteData,
362
+ weak_ptr_factory_.GetWeakPtr ()));
363
+
364
+ autofill::PersonalDataManager* data_manager =
365
+ autofill::PersonalDataManagerFactory::GetForBrowserContext (
366
+ browser_context_);
367
+ if (data_manager)
368
+ data_manager->Refresh ();
369
+ }
370
+ }
371
+
372
+ void Autofill::ClearAutofillData () {
373
+ scoped_refptr<autofill::AutofillWebDataService> web_data_service =
374
+ static_cast <brave::BraveBrowserContext*>(browser_context_)
375
+ ->GetAutofillWebdataService ();
376
+
377
+ if (web_data_service.get ()) {
378
+ base::Time delete_begin;
379
+ base::Time delete_end;
380
+ // TODO(Anthony Tseng): Specify time range from front end
381
+ delete_begin = delete_begin.UnixEpoch ();
382
+ delete_end = delete_end.Now ();
383
+ web_data_service->RemoveAutofillDataModifiedBetween (delete_begin,
384
+ delete_end);
385
+ // The above calls are done on the UI thread but do their work on the DB
386
+ // thread. So wait for it.
387
+ content::BrowserThread::PostTaskAndReply (content::BrowserThread::DB,
388
+ FROM_HERE,
389
+ base::Bind (&base::DoNothing),
390
+ base::Bind (&Autofill::OnClearedAutofillData,
391
+ weak_ptr_factory_.GetWeakPtr ()));
392
+
393
+ autofill::PersonalDataManager* data_manager =
394
+ autofill::PersonalDataManagerFactory::GetForBrowserContext (
395
+ browser_context_);
396
+ if (data_manager)
397
+ data_manager->Refresh ();
398
+ }
399
+ }
400
+
401
+ void Autofill::OnClearedAutocompleteData () {
402
+ DCHECK_CURRENTLY_ON (content::BrowserThread::UI);
403
+ }
404
+
405
+ void Autofill::OnClearedAutofillData () {
406
+ DCHECK_CURRENTLY_ON (content::BrowserThread::UI);
407
+ }
408
+
343
409
// static
344
410
mate::Handle <Autofill> Autofill::Create (
345
411
v8::Isolate* isolate,
@@ -357,7 +423,9 @@ void Autofill::BuildPrototype(v8::Isolate* isolate,
357
423
.SetMethod (" removeProfile" , &Autofill::RemoveProfile)
358
424
.SetMethod (" addCreditCard" , &Autofill::AddCreditCard)
359
425
.SetMethod (" getCreditCard" , &Autofill::GetCreditCard)
360
- .SetMethod (" removeCreditCard" , &Autofill::RemoveCreditCard);
426
+ .SetMethod (" removeCreditCard" , &Autofill::RemoveCreditCard)
427
+ .SetMethod (" clearAutocompleteData" , &Autofill::ClearAutocompleteData)
428
+ .SetMethod (" clearAutofillData" , &Autofill::ClearAutofillData);
361
429
}
362
430
363
431
} // namespace api
0 commit comments