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

Unified 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: fix typos Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/browser/aw_form_database_service.cc
diff --git a/android_webview/browser/aw_form_database_service.cc b/android_webview/browser/aw_form_database_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eb8a2942db8ce4b9dc8b066bd67bfb6ecf31ac63
--- /dev/null
+++ b/android_webview/browser/aw_form_database_service.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "android_webview/browser/aw_form_database_service.h"
+#include "base/logging.h"
+#include "components/autofill/browser/webdata/autofill_table.h"
+#include "components/webdata/common/webdata_constants.h"
+#include "content/public/browser/browser_thread.h"
+#include "ui/base/l10n/l10n_util_android.h"
+
+using content::BrowserThread;
+
+namespace {
+
+// Callback to handle database error. It seems chrome uses this to
+// display an error dialog box only.
+void DatabaseErrorCallback(sql::InitStatus status) {
+ LOG(WARNING) << "initializing autocomplete database failed";
+}
+
+} // namespace
+
+namespace android_webview {
+
+AwFormDatabaseService::AwFormDatabaseService(const base::FilePath path)
+ : completion_(false, false) {
benm (inactive) 2013/04/29 18:00:03 missing some members.
sgurun-gerrit only 2013/04/29 19:32:39 Done.
+
+ web_database_ = new WebDatabaseService(path.Append(kWebDataFilename));
+ web_database_->AddTable(
+ scoped_ptr<WebDatabaseTable>(new autofill::AutofillTable(
+ l10n_util::GetDefaultLocale())));
+ web_database_->LoadDatabase(WebDatabaseService::InitCallback());
+
+ autofill_data_ = new autofill::AutofillWebDataService(
+ web_database_, base::Bind(&DatabaseErrorCallback));
+ autofill_data_->Init();
+}
+
+AwFormDatabaseService::~AwFormDatabaseService() {
+ CancelPendingQuery();
+}
+
+void AwFormDatabaseService::Shutdown() {
+ autofill_data_->ShutdownOnUIThread();
+ web_database_->ShutdownDatabase();
+}
+
+void AwFormDatabaseService::CancelPendingQuery() {
+ if (pending_query_handle_) {
+ if (autofill_data_)
+ autofill_data_->CancelRequest(pending_query_handle_);
+ pending_query_handle_ = 0;
+ }
+}
+
+scoped_refptr<autofill::AutofillWebDataService>
+AwFormDatabaseService::get_autofill_webdata_service() {
+ return autofill_data_;
+}
+
+bool AwFormDatabaseService::HasFormElements() {
+
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&AwFormDatabaseService::HasFormElementsImpl,
+ base::Unretained(this)));
+ completion_.Wait();
+ return has_form_elements_;
+}
+
+void AwFormDatabaseService::HasFormElementsImpl() {
+
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ has_form_elements_ = false;
+ pending_query_handle_ = autofill_data_->HasFormElements(this);
+}
+
+
+void AwFormDatabaseService::OnWebDataServiceRequestDone(
+ WebDataServiceBase::Handle h,
+ const WDTypedResult* result) {
+
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(pending_query_handle_);
+ pending_query_handle_ = 0;
+
+ if (result) {
+ DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
+ const WDResult<bool>* autofill_result =
+ static_cast<const WDResult<bool>*>(result);
+ has_form_elements_ = autofill_result->GetValue();
+ }
+ completion_.Signal();
+}
+
+} // namespace android_webview

Powered by Google App Engine
This is Rietveld 408576698