summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/webdata/autofill_change.h35
-rw-r--r--chrome/browser/webdata/web_data_service.cc31
-rw-r--r--chrome/browser/webdata/web_data_service.h8
-rw-r--r--chrome/browser/webdata/web_data_service_unittest.cc56
-rw-r--r--chrome/common/notification_type.h12
5 files changed, 114 insertions, 28 deletions
diff --git a/chrome/browser/webdata/autofill_change.h b/chrome/browser/webdata/autofill_change.h
new file mode 100644
index 0000000..2eb8d50
--- /dev/null
+++ b/chrome/browser/webdata/autofill_change.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
+#define CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
+
+#include "chrome/browser/webdata/autofill_entry.h"
+
+class AutofillChange {
+ public:
+ typedef enum {
+ ADD,
+ UPDATE,
+ REMOVE
+ } Type;
+
+ AutofillChange(Type type, const AutofillKey& key)
+ : type_(type),
+ key_(key) {}
+ virtual ~AutofillChange() {}
+
+ Type type() const { return type_; }
+ const AutofillKey& key() const { return key_; }
+
+ bool operator==(const AutofillChange& change) const {
+ return type_ == change.type() && key_ == change.key();
+ }
+
+ private:
+ Type type_;
+ AutofillKey key_;
+};
+
+#endif // CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index b37dc06..ee1d4c9 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -7,6 +7,7 @@
#include "base/message_loop.h"
#include "base/task.h"
#include "base/thread.h"
+#include "chrome/browser/webdata/autofill_change.h"
#include "chrome/browser/webdata/autofill_entry.h"
#include "chrome/browser/webdata/web_database.h"
#include "chrome/common/chrome_constants.h"
@@ -188,13 +189,13 @@ void WebDataService::RequestCompleted(Handle h) {
// including the list of affected keys.
const WDTypedResult* result = request->GetResult();
if (!request->IsCancelled() && result) {
- if (result->GetType() == AUTOFILL_AFFECTED_KEYS) {
- AutofillKeyList affected_keys =
- static_cast<const WDResult<AutofillKeyList>*>(result)->GetValue();
+ if (result->GetType() == AUTOFILL_CHANGES) {
+ AutofillChangeList changes =
+ static_cast<const WDResult<AutofillChangeList>*>(result)->GetValue();
NotificationService::current()->Notify(
- NotificationType::AUTOFILL_ENTRIES_ADDED,
+ NotificationType::AUTOFILL_ENTRIES_CHANGED,
NotificationService::AllSources(),
- Details<AutofillKeyList>(&affected_keys));
+ Details<AutofillChangeList>(&changes));
}
}
}
@@ -619,14 +620,16 @@ void WebDataService::AddFormFieldValuesImpl(
if (!db_->AddFormFieldValues(form_fields))
NOTREACHED();
- AutofillKeyList keys;
+ AutofillChangeList changes;
for (std::vector<FormField>::const_iterator itr = form_fields.begin();
itr != form_fields.end();
itr++) {
- keys.push_back(AutofillKey(itr->name(), itr->value()));
+ changes.push_back(
+ AutofillChange(AutofillChange::ADD,
+ AutofillKey(itr->name(), itr->value())));
}
request->SetResult(
- new WDResult<AutofillKeyList>(AUTOFILL_AFFECTED_KEYS, keys));
+ new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes));
ScheduleCommit();
}
request->RequestComplete();
@@ -660,9 +663,17 @@ void WebDataService::RemoveFormValueForElementNameImpl(
GenericRequest2<string16, string16>* request) {
InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled()) {
- if (db_->RemoveFormElement(request->GetArgument1(),
- request->GetArgument2()))
+ const string16& name = request->GetArgument1();
+ const string16& value = request->GetArgument2();
+
+ if (db_->RemoveFormElement(name, value)) {
+ AutofillChangeList changes;
+ changes.push_back(AutofillChange(AutofillChange::REMOVE,
+ AutofillKey(name, value)));
+ request->SetResult(
+ new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes));
ScheduleCommit();
+ }
}
request->RequestComplete();
}
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index 74120a8..b87803c 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -15,12 +15,11 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "webkit/glue/form_field.h"
-class AutofillKey;
+class AutofillChange;
#if defined(OS_WIN)
struct IE7PasswordInfo;
#endif
class MessageLoop;
-class NotificationType;
class Task;
class WebDatabase;
@@ -61,9 +60,11 @@ typedef enum {
#endif
WEB_APP_IMAGES, // WDResult<WDAppImagesResult>
AUTOFILL_VALUE_RESULT, // WDResult<std::vector<string16>>
- AUTOFILL_AFFECTED_KEYS, // WDResult<std::vector<AutofillKey>>
+ AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>>
} WDResultType;
+typedef std::vector<AutofillChange> AutofillChangeList;
+
// Result from GetWebAppImages.
struct WDAppImagesResult {
WDAppImagesResult() : has_all_images(false) {}
@@ -427,7 +428,6 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
typedef GenericRequest2<std::vector<const TemplateURL*>,
std::vector<TemplateURL*> > SetKeywordsRequest;
- typedef std::vector<AutofillKey> AutofillKeyList;
~WebDataService();
// Initialize the database, if it hasn't already been initialized.
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
index f4bf2e9..917abd2 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -12,6 +12,7 @@
#include "base/string16.h"
#include "base/string_util.h"
#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/webdata/autofill_change.h"
#include "chrome/browser/webdata/autofill_entry.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/common/chrome_paths.h"
@@ -24,11 +25,12 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/form_field.h"
+using testing::_;
using testing::ElementsAreArray;
using testing::Pointee;
using testing::Property;
-typedef std::vector<AutofillKey> AutofillKeyList;
+typedef std::vector<AutofillChange> AutofillChangeList;
ACTION(QuitUIMessageLoop) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
@@ -100,23 +102,23 @@ TEST_F(WebDataServiceTest, AutofillAdd) {
const string16 kName2 = ASCIIToUTF16("name2");
const string16 kValue2 = ASCIIToUTF16("value2");
- const AutofillKey expected_keys[] = {
- AutofillKey(kName1, kValue1),
- AutofillKey(kName2, kValue2)
+ const AutofillChange expected_changes[] = {
+ AutofillChange(AutofillChange::ADD, AutofillKey(kName1, kValue1)),
+ AutofillChange(AutofillChange::ADD, AutofillKey(kName2, kValue2))
};
// This will verify that the correct notification is triggered,
// passing the correct list of autofill keys in the details.
EXPECT_CALL(
observer_,
- Observe(NotificationType(NotificationType::AUTOFILL_ENTRIES_ADDED),
+ Observe(NotificationType(NotificationType::AUTOFILL_ENTRIES_CHANGED),
NotificationService::AllSources(),
- Property(&Details<AutofillKeyList>::ptr,
- Pointee(ElementsAreArray(expected_keys))))).
+ Property(&Details<const AutofillChangeList>::ptr,
+ Pointee(ElementsAreArray(expected_changes))))).
WillOnce(QuitUIMessageLoop());
registrar_.Add(&observer_,
- NotificationType::AUTOFILL_ENTRIES_ADDED,
+ NotificationType::AUTOFILL_ENTRIES_CHANGED,
NotificationService::AllSources());
std::vector<webkit_glue::FormField> form_fields;
@@ -148,3 +150,41 @@ TEST_F(WebDataServiceTest, AutofillAdd) {
ASSERT_EQ(1U, consumer.values().size());
EXPECT_EQ(kValue1, consumer.values()[0]);
}
+
+TEST_F(WebDataServiceTest, AutofillRemoveOne) {
+ const string16 kName1 = ASCIIToUTF16("name1");
+ const string16 kValue1 = ASCIIToUTF16("value1");
+
+ // First add some values to autofill.
+ EXPECT_CALL(observer_, Observe(_, _, _)).WillOnce(QuitUIMessageLoop());
+ registrar_.Add(&observer_,
+ NotificationType::AUTOFILL_ENTRIES_CHANGED,
+ NotificationService::AllSources());
+ std::vector<webkit_glue::FormField> form_fields;
+ form_fields.push_back(
+ webkit_glue::FormField(EmptyString16(),
+ kName1,
+ EmptyString16(),
+ kValue1));
+ wds_->AddFormFieldValues(form_fields);
+
+ // The message loop will exit when the mock observer is notified.
+ MessageLoop::current()->Run();
+
+ // This will verify that the correct notification is triggered,
+ // passing the correct list of autofill keys in the details.
+ const AutofillChange expected_changes[] = {
+ AutofillChange(AutofillChange::REMOVE, AutofillKey(kName1, kValue1))
+ };
+ EXPECT_CALL(
+ observer_,
+ Observe(NotificationType(NotificationType::AUTOFILL_ENTRIES_CHANGED),
+ NotificationService::AllSources(),
+ Property(&Details<const AutofillChangeList>::ptr,
+ Pointee(ElementsAreArray(expected_changes))))).
+ WillOnce(QuitUIMessageLoop());
+ wds_->RemoveFormValueForElementName(kName1, kValue1);
+
+ // The message loop will exit when the mock observer is notified.
+ MessageLoop::current()->Run();
+}
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 3ec4a4c..f157b52 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -782,12 +782,12 @@ class NotificationType {
// (the pointer is usable). No details are expected.
NOTIFY_BALLOON_DISCONNECTED,
- // This notification is sent whenever autofill entries are added
- // to the database. The detail of this notification is a list of
- // the affected entries represented by a vector of AutofillKey.
- // Note that this notification will always be sent even in the
- // autofill entries already exist in the database.
- AUTOFILL_ENTRIES_ADDED,
+ // This notification is sent whenever autofill entries are
+ // changed. The detail of this notification is a list of changes
+ // represented by a vector of AutofillChange. Each change
+ // includes a change type (add, update, or remove) as well as the
+ // key of the entry that was affected.
+ AUTOFILL_ENTRIES_CHANGED,
// Count (must be last) ----------------------------------------------------
// Used to determine the number of notification types. Not valid as