summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill_manager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/autofill_manager.cc')
-rw-r--r--chrome/browser/autofill_manager.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/chrome/browser/autofill_manager.cc b/chrome/browser/autofill_manager.cc
new file mode 100644
index 0000000..af8589b
--- /dev/null
+++ b/chrome/browser/autofill_manager.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2006-2008 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 "chrome/browser/autofill_manager.h"
+
+#include "base/string_util.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/web_contents.h"
+
+AutofillManager::~AutofillManager() {
+ ClearPendingQuery();
+}
+
+void AutofillManager::ClearPendingQuery() {
+ pending_query_name_.clear();
+ pending_query_prefix_.clear();
+
+ if (query_is_pending_) {
+ WebDataService* web_data_service =
+ profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ if (!web_data_service) {
+ NOTREACHED();
+ return;
+ }
+ web_data_service->CancelRequest(pending_query_handle_);
+ }
+ pending_query_handle_ = 0;
+ query_is_pending_ = false;
+}
+
+void AutofillManager::AutofillFormSubmitted(const AutofillForm& form) {
+ StoreFormEntriesInWebDatabase(form);
+}
+
+void AutofillManager::FetchValuesForName(const std::wstring& name,
+ const std::wstring& prefix,
+ int limit) {
+ WebDataService* web_data_service =
+ profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ if (!web_data_service) {
+ NOTREACHED();
+ return;
+ }
+
+ ClearPendingQuery();
+
+ pending_query_handle_ = web_data_service->
+ GetFormValuesForElementName(name, prefix, limit, this);
+ pending_query_name_ = name;
+ pending_query_prefix_ = prefix;
+}
+
+void AutofillManager::OnWebDataServiceRequestDone(WebDataService::Handle h,
+ const WDTypedResult* result) {
+ DCHECK(query_is_pending_);
+
+ DCHECK(result);
+ if (!result)
+ return;
+
+ switch (result->GetType()) {
+ case AUTOFILL_VALUE_RESULT: {
+ break;
+ }
+ default:
+ NOTREACHED();
+ break;
+ }
+
+ ClearPendingQuery();
+}
+
+void AutofillManager::StoreFormEntriesInWebDatabase(
+ const AutofillForm& form) {
+ if (profile()->IsOffTheRecord())
+ return;
+
+ profile()->GetWebDataService(Profile::EXPLICIT_ACCESS)->
+ AddAutofillFormElements(form.elements);
+}