Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Add clearAutocompleteData & clearAutofillData
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh authored and bridiver committed Sep 16, 2016
1 parent 3bee689 commit 17d20ff
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
72 changes: 70 additions & 2 deletions atom/browser/api/atom_api_autofill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ namespace api {

Autofill::Autofill(v8::Isolate* isolate,
content::BrowserContext* browser_context)
: browser_context_(browser_context) {
: browser_context_(browser_context),
weak_ptr_factory_(this) {
Init(isolate);
}

Expand Down Expand Up @@ -340,6 +341,71 @@ bool Autofill::RemoveCreditCard(const std::string guid) {
return true;
}

void Autofill::ClearAutocompleteData() {
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
static_cast<brave::BraveBrowserContext*>(browser_context_)
->GetAutofillWebdataService();

if (web_data_service.get()) {
base::Time delete_begin;
base::Time delete_end;
// TODO(Anthony Tseng): Specify time range from front end
delete_begin = delete_begin.UnixEpoch();
delete_end = delete_end.Now();
web_data_service->RemoveFormElementsAddedBetween(delete_begin,
delete_end);
// thread. So wait for it.
content::BrowserThread::PostTaskAndReply(content::BrowserThread::DB,
FROM_HERE,
base::Bind(&base::DoNothing),
base::Bind(&Autofill::OnClearedAutocompleteData,
weak_ptr_factory_.GetWeakPtr()));

autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForBrowserContext(
browser_context_);
if (data_manager)
data_manager->Refresh();
}
}

void Autofill::ClearAutofillData() {
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
static_cast<brave::BraveBrowserContext*>(browser_context_)
->GetAutofillWebdataService();

if (web_data_service.get()) {
base::Time delete_begin;
base::Time delete_end;
// TODO(Anthony Tseng): Specify time range from front end
delete_begin = delete_begin.UnixEpoch();
delete_end = delete_end.Now();
web_data_service->RemoveAutofillDataModifiedBetween(delete_begin,
delete_end);
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
content::BrowserThread::PostTaskAndReply(content::BrowserThread::DB,
FROM_HERE,
base::Bind(&base::DoNothing),
base::Bind(&Autofill::OnClearedAutofillData,
weak_ptr_factory_.GetWeakPtr()));

autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForBrowserContext(
browser_context_);
if (data_manager)
data_manager->Refresh();
}
}

void Autofill::OnClearedAutocompleteData() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}

void Autofill::OnClearedAutofillData() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}

// static
mate::Handle<Autofill> Autofill::Create(
v8::Isolate* isolate,
Expand All @@ -357,7 +423,9 @@ void Autofill::BuildPrototype(v8::Isolate* isolate,
.SetMethod("removeProfile", &Autofill::RemoveProfile)
.SetMethod("addCreditCard", &Autofill::AddCreditCard)
.SetMethod("getCreditCard", &Autofill::GetCreditCard)
.SetMethod("removeCreditCard", &Autofill::RemoveCreditCard);
.SetMethod("removeCreditCard", &Autofill::RemoveCreditCard)
.SetMethod("clearAutocompleteData", &Autofill::ClearAutocompleteData)
.SetMethod("clearAutofillData", &Autofill::ClearAutofillData);
}

} // namespace api
Expand Down
8 changes: 8 additions & 0 deletions atom/browser/api/atom_api_autofill.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@ class Autofill : public mate::TrackableObject<Autofill> {
autofill::CreditCard* GetCreditCard(std::string guid);
bool RemoveCreditCard(const std::string guid);

void ClearAutocompleteData();
void ClearAutofillData();

brave::BraveBrowserContext* browser_context() {
return static_cast<brave::BraveBrowserContext*>(browser_context_);
}

private:
void OnClearedAutocompleteData();
void OnClearedAutofillData();

content::BrowserContext* browser_context_; // not owned

base::WeakPtrFactory<Autofill> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(Autofill);
};

Expand Down

0 comments on commit 17d20ff

Please sign in to comment.