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

Side by Side Diff: android_webview/browser/aw_form_database_service.cc

Issue 14503010: Implement WebViewDatabase's hasFormData API for chromium based webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address ben's code review Created 7 years, 7 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
(Empty)
1 // Copyright (c) 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 #include "android_webview/browser/aw_form_database_service.h"
6 #include "base/logging.h"
7 #include "components/autofill/browser/webdata/autofill_table.h"
8 #include "components/webdata/common/webdata_constants.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "ui/base/l10n/l10n_util_android.h"
11
12 using content::BrowserThread;
13
14 namespace {
15
16 // Callback to handle database error. It seems chrome uses this to
17 // display an error dialog box only.
18 void DatabaseErrorCallback(sql::InitStatus status) {
19 LOG(WARNING) << "initializing autocomplete database failed";
20 }
21
22 } // namespace
23
24 namespace android_webview {
25
26 AwFormDatabaseService::AwFormDatabaseService(const base::FilePath path)
27 : pending_query_handle_(0),
28 has_form_data_(false),
29 completion_(false, false) {
30
31 web_database_ = new WebDatabaseService(path.Append(kWebDataFilename));
32 web_database_->AddTable(
33 scoped_ptr<WebDatabaseTable>(new autofill::AutofillTable(
34 l10n_util::GetDefaultLocale())));
35 web_database_->LoadDatabase();
36
37 autofill_data_ = new autofill::AutofillWebDataService(
38 web_database_, base::Bind(&DatabaseErrorCallback));
39 autofill_data_->Init();
40 }
41
42 AwFormDatabaseService::~AwFormDatabaseService() {
43 Shutdown();
44 CancelPendingQuery();
benm (inactive) 2013/05/07 19:06:55 These should be the other way around I think? (Can
sgurun-gerrit only 2013/05/07 19:56:09 Done.
45 }
46
47 void AwFormDatabaseService::Shutdown() {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 autofill_data_->ShutdownOnUIThread();
50 web_database_->ShutdownDatabase();
51 }
52
53 void AwFormDatabaseService::CancelPendingQuery() {
54 if (pending_query_handle_) {
55 if (autofill_data_)
56 autofill_data_->CancelRequest(pending_query_handle_);
57 pending_query_handle_ = 0;
58 }
59 }
60
61 scoped_refptr<autofill::AutofillWebDataService>
62 AwFormDatabaseService::get_autofill_webdata_service() {
63 return autofill_data_;
64 }
65
66 void AwFormDatabaseService::ClearFormData() {
67 base::Time begin;
68 base::Time end = base::Time::Max();
69 autofill_data_->RemoveFormElementsAddedBetween(begin, end);
70 autofill_data_->RemoveAutofillDataModifiedBetween(begin, end);
71 }
72
73 bool AwFormDatabaseService::HasFormData() {
74 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
75 base::Bind(&AwFormDatabaseService::HasFormDataImpl,
76 base::Unretained(this)));
77 completion_.Wait();
78 return has_form_data_;
79 }
80
81 void AwFormDatabaseService::HasFormDataImpl() {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
83 has_form_data_ = false;
84 pending_query_handle_ = autofill_data_->HasFormElements(this);
85 }
86
87
88 void AwFormDatabaseService::OnWebDataServiceRequestDone(
89 WebDataServiceBase::Handle h,
90 const WDTypedResult* result) {
91
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
93 DCHECK_EQ(pending_query_handle_, h);
94 pending_query_handle_ = 0;
95
benm (inactive) 2013/05/07 19:06:55 maybe for clarity we should set has_form_data_ to
sgurun-gerrit only 2013/05/07 19:56:09 Done.
96 if (result) {
97 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
98 const WDResult<bool>* autofill_result =
99 static_cast<const WDResult<bool>*>(result);
100 has_form_data_ = autofill_result->GetValue();
101 }
102 completion_.Signal();
103 }
104
105 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698