summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorsgurun@chromium.org <sgurun@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-08 16:16:37 +0000
committersgurun@chromium.org <sgurun@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-08 16:16:37 +0000
commit1140180828d318fe4d096484dd1a110b714ec285 (patch)
treeb45a687a3fa16b41c3847b1ad0c8d57f13a6bb84 /components
parent5558ebad44509c3574cf5dce1ad2929b1b0bdeb2 (diff)
downloadchromium_src-1140180828d318fe4d096484dd1a110b714ec285.zip
chromium_src-1140180828d318fe4d096484dd1a110b714ec285.tar.gz
chromium_src-1140180828d318fe4d096484dd1a110b714ec285.tar.bz2
Implement WebViewDatabase's hasFormData API for chromium based webview.
BUG=b/6234236 Review URL: https://chromiumcodereview.appspot.com/14503010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/autofill/browser/webdata/autofill_table.cc10
-rw-r--r--components/autofill/browser/webdata/autofill_table.h3
-rw-r--r--components/autofill/browser/webdata/autofill_table_unittest.cc2
-rw-r--r--components/autofill/browser/webdata/autofill_webdata.h4
-rw-r--r--components/autofill/browser/webdata/autofill_webdata_backend.cc8
-rw-r--r--components/autofill/browser/webdata/autofill_webdata_backend.h3
-rw-r--r--components/autofill/browser/webdata/autofill_webdata_service.cc7
-rw-r--r--components/autofill/browser/webdata/autofill_webdata_service.h3
8 files changed, 40 insertions, 0 deletions
diff --git a/components/autofill/browser/webdata/autofill_table.cc b/components/autofill/browser/webdata/autofill_table.cc
index a9c7367..99eeeb4 100644
--- a/components/autofill/browser/webdata/autofill_table.cc
+++ b/components/autofill/browser/webdata/autofill_table.cc
@@ -463,6 +463,16 @@ bool AutofillTable::GetFormValuesForElementName(
return s.Succeeded();
}
+bool AutofillTable::HasFormElements() {
+ sql::Statement s(db_->GetUniqueStatement(
+ "SELECT COUNT(*) FROM autofill"));
+ if (!s.Step()) {
+ NOTREACHED();
+ return false;
+ }
+ return s.ColumnInt(0) > 0;
+}
+
bool AutofillTable::RemoveFormElementsAddedBetween(
const Time& delete_begin,
const Time& delete_end,
diff --git a/components/autofill/browser/webdata/autofill_table.h b/components/autofill/browser/webdata/autofill_table.h
index f86302f..0ff0c8f 100644
--- a/components/autofill/browser/webdata/autofill_table.h
+++ b/components/autofill/browser/webdata/autofill_table.h
@@ -154,6 +154,9 @@ class AutofillTable : public WebDatabaseTable {
std::vector<base::string16>* values,
int limit);
+ // Returns whether any form elements are stored in the database.
+ bool HasFormElements();
+
// Removes rows from autofill_dates if they were created on or after
// |delete_begin| and strictly before |delete_end|. Decrements the
// count of the corresponding rows in the autofill table, and
diff --git a/components/autofill/browser/webdata/autofill_table_unittest.cc b/components/autofill/browser/webdata/autofill_table_unittest.cc
index b4f3264..575ece2 100644
--- a/components/autofill/browser/webdata/autofill_table_unittest.cc
+++ b/components/autofill/browser/webdata/autofill_table_unittest.cc
@@ -140,7 +140,9 @@ TEST_F(AutofillTableTest, Autofill) {
field.value = ASCIIToUTF16("Superman");
base::Time now = base::Time::Now();
base::TimeDelta two_seconds = base::TimeDelta::FromSeconds(2);
+ EXPECT_FALSE(table_->HasFormElements());
EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
+ EXPECT_TRUE(table_->HasFormElements());
std::vector<base::string16> v;
for (int i = 0; i < 5; i++) {
field.value = ASCIIToUTF16("Clark Kent");
diff --git a/components/autofill/browser/webdata/autofill_webdata.h b/components/autofill/browser/webdata/autofill_webdata.h
index 032649b..66f42f8 100644
--- a/components/autofill/browser/webdata/autofill_webdata.h
+++ b/components/autofill/browser/webdata/autofill_webdata.h
@@ -41,6 +41,10 @@ class AutofillWebData {
int limit,
WebDataServiceConsumer* consumer) = 0;
+ // Checks if there are any form elements in the database.
+ virtual WebDataServiceBase::Handle HasFormElements(
+ WebDataServiceConsumer* consumer) = 0;
+
// Removes form elements recorded for Autocomplete from the database.
virtual void RemoveFormElementsAddedBetween(
const base::Time& delete_begin, const base::Time& delete_end) = 0;
diff --git a/components/autofill/browser/webdata/autofill_webdata_backend.cc b/components/autofill/browser/webdata/autofill_webdata_backend.cc
index 0cda3d1..e8c5fd8 100644
--- a/components/autofill/browser/webdata/autofill_webdata_backend.cc
+++ b/components/autofill/browser/webdata/autofill_webdata_backend.cc
@@ -72,6 +72,14 @@ AutofillWebDataBackend::GetFormValuesForElementName(
values));
}
+scoped_ptr<WDTypedResult> AutofillWebDataBackend::HasFormElements(
+ WebDatabase* db) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ bool value = AutofillTable::FromWebDatabase(db)->HasFormElements();
+ return scoped_ptr<WDTypedResult>(
+ new WDResult<bool>(AUTOFILL_VALUE_RESULT, value));
+}
+
WebDatabase::State AutofillWebDataBackend::RemoveFormElementsAddedBetween(
const base::Time& delete_begin, const base::Time& delete_end,
WebDatabase* db) {
diff --git a/components/autofill/browser/webdata/autofill_webdata_backend.h b/components/autofill/browser/webdata/autofill_webdata_backend.h
index b1ab6d6..3ab841e 100644
--- a/components/autofill/browser/webdata/autofill_webdata_backend.h
+++ b/components/autofill/browser/webdata/autofill_webdata_backend.h
@@ -44,6 +44,9 @@ class AutofillWebDataBackend
int limit,
WebDatabase* db);
+ // Returns true if there are any elements in the form.
+ scoped_ptr<WDTypedResult> HasFormElements(WebDatabase* db);
+
// Removes form elements recorded for Autocomplete from the database.
WebDatabase::State RemoveFormElementsAddedBetween(
const base::Time& delete_begin,
diff --git a/components/autofill/browser/webdata/autofill_webdata_service.cc b/components/autofill/browser/webdata/autofill_webdata_service.cc
index 217f265..1f7e158 100644
--- a/components/autofill/browser/webdata/autofill_webdata_service.cc
+++ b/components/autofill/browser/webdata/autofill_webdata_service.cc
@@ -72,6 +72,13 @@ WebDataServiceBase::Handle AutofillWebDataService::GetFormValuesForElementName(
autofill_backend_, name, prefix, limit), consumer);
}
+WebDataServiceBase::Handle AutofillWebDataService::HasFormElements(
+ WebDataServiceConsumer* consumer) {
+ return wdbs_->ScheduleDBTaskWithResult(FROM_HERE,
+ Bind(&AutofillWebDataBackend::HasFormElements, autofill_backend_),
+ consumer);
+}
+
void AutofillWebDataService::RemoveFormElementsAddedBetween(
const Time& delete_begin, const Time& delete_end) {
wdbs_->ScheduleDBTask(FROM_HERE,
diff --git a/components/autofill/browser/webdata/autofill_webdata_service.h b/components/autofill/browser/webdata/autofill_webdata_service.h
index 87b967c..2ca80ef 100644
--- a/components/autofill/browser/webdata/autofill_webdata_service.h
+++ b/components/autofill/browser/webdata/autofill_webdata_service.h
@@ -65,6 +65,9 @@ class AutofillWebDataService : public AutofillWebData,
const base::string16& prefix,
int limit,
WebDataServiceConsumer* consumer) OVERRIDE;
+
+ virtual WebDataServiceBase::Handle HasFormElements(
+ WebDataServiceConsumer* consumer) OVERRIDE;
virtual void RemoveFormElementsAddedBetween(
const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
virtual void RemoveExpiredFormElements() OVERRIDE;