diff options
author | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-07 18:53:57 +0000 |
---|---|---|
committer | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-07 18:53:57 +0000 |
commit | 83cb9e0a28d12f4c68e75dca6df33678f754e302 (patch) | |
tree | eed727623e48bdf4f07c3a9d4e07bae682c9491f /chrome | |
parent | 4bdd8e1ead1683e5ccba967d252c0ef50ff1d722 (diff) | |
download | chromium_src-83cb9e0a28d12f4c68e75dca6df33678f754e302.zip chromium_src-83cb9e0a28d12f4c68e75dca6df33678f754e302.tar.gz chromium_src-83cb9e0a28d12f4c68e75dca6df33678f754e302.tar.bz2 |
Add notification for autofill changes.
This is the first in a series of changes for adding notifications to autofill. This change adds the notification plumbing to WebDataService::AddFormFieldValues that sends a simple notification.
The next change will add a Details<> payload to the notification with a list of changes that were performed, and then I will expand the notifications to the other autofill mutation methods.
Review URL: http://codereview.chromium.org/455027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/webdata/web_data_service.cc | 16 | ||||
-rw-r--r-- | chrome/browser/webdata/web_data_service.h | 4 | ||||
-rw-r--r-- | chrome/browser/webdata/web_data_service_unittest.cc | 30 | ||||
-rw-r--r-- | chrome/common/notification_observer_mock.h | 24 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 4 |
5 files changed, 76 insertions, 2 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc index fe00c5d..380613b 100644 --- a/chrome/browser/webdata/web_data_service.cc +++ b/chrome/browser/webdata/web_data_service.cc @@ -4,9 +4,13 @@ #include "chrome/browser/webdata/web_data_service.h" +#include "base/message_loop.h" +#include "base/task.h" #include "base/thread.h" #include "chrome/browser/webdata/web_database.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #include "webkit/glue/password_form.h" //////////////////////////////////////////////////////////////////////////////// @@ -116,6 +120,12 @@ void WebDataService::CancelRequest(Handle h) { i->second->Cancel(); } +void WebDataService::Notify(NotificationType type) { + NotificationService::current()->Notify(type, + NotificationService::AllSources(), + NotificationService::NoDetails()); +} + void WebDataService::AddFormFieldValues( const std::vector<FormField>& element) { GenericRequest<std::vector<FormField> >* request = @@ -177,6 +187,12 @@ void WebDataService::RequestCompleted(Handle h) { consumer->OnWebDataServiceRequestDone(request->GetHandle(), request->GetResult()); } + + // If this is an autofill request, post the notifications. + if (!request->IsCancelled() && + request->GetResult() && + request->GetResult()->GetType() == AUTOFILL_VALUE_RESULT) + Notify(NotificationType::AUTOFILL_CHANGED); } ////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h index 956a9c9..8735c45 100644 --- a/chrome/browser/webdata/web_data_service.h +++ b/chrome/browser/webdata/web_data_service.h @@ -19,6 +19,7 @@ struct IE7PasswordInfo; #endif class MessageLoop; +class NotificationType; class Task; class WebDatabase; @@ -372,6 +373,9 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { // WebDataServiceConsumer is about to be deleted. void CancelRequest(Handle h); + // Sends a notification using the notification service. + void Notify(NotificationType type); + ////////////////////////////////////////////////////////////////////////////// // // Autofill. diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc index 1386792..29f7bdf 100644 --- a/chrome/browser/webdata/web_data_service_unittest.cc +++ b/chrome/browser/webdata/web_data_service_unittest.cc @@ -11,11 +11,24 @@ #include "base/scoped_ptr.h" #include "base/string16.h" #include "base/string_util.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/notification_observer_mock.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/glue/form_field.h" +using testing::_; + +ACTION(QuitUIMessageLoop) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + MessageLoop::current()->Quit(); +} + class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { public: AutofillWebDataServiceConsumer() {} @@ -23,13 +36,13 @@ class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle, const WDTypedResult* result) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT); handle_ = handle; const WDResult<std::vector<string16> >* autofill_result = static_cast<const WDResult<std::vector<string16> >*>(result); // Copy the values. values_ = autofill_result->GetValue(); - MessageLoop::current()->Quit(); } WebDataService::Handle const handle() { return handle_; } @@ -42,8 +55,9 @@ class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { }; class WebDataServiceTest : public testing::Test { + public: + WebDataServiceTest() : ui_thread_(ChromeThread::UI, &message_loop_) {} protected: - virtual void SetUp() { PathService::Get(chrome::DIR_TEST_DATA, &profile_dir_); const std::string test_profile = "WebDataServiceTest"; @@ -64,11 +78,23 @@ class WebDataServiceTest : public testing::Test { } MessageLoopForUI message_loop_; + ChromeThread ui_thread_; FilePath profile_dir_; scoped_refptr<WebDataService> wds_; + NotificationRegistrar registrar_; + NotificationObserverMock observer_; }; TEST_F(WebDataServiceTest, AutofillAdd) { + EXPECT_CALL(observer_, + Observe(NotificationType(NotificationType::AUTOFILL_CHANGED), + NotificationService::AllSources(), + NotificationService::NoDetails())). + WillOnce(QuitUIMessageLoop()); + registrar_.Add(&observer_, + NotificationType::AUTOFILL_CHANGED, + NotificationService::AllSources()); + std::vector<webkit_glue::FormField> form_fields; form_fields.push_back(webkit_glue::FormField(EmptyString16(), ASCIIToUTF16("name"), diff --git a/chrome/common/notification_observer_mock.h b/chrome/common/notification_observer_mock.h new file mode 100644 index 0000000..9eeb665 --- /dev/null +++ b/chrome/common/notification_observer_mock.h @@ -0,0 +1,24 @@ +// 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_COMMON_NOTIFICATION_OBSERVER_MOCK_H_ +#define CHROME_COMMON_NOTIFICATION_OBSERVER_MOCK_H_ + +#include "chrome/common/notification_details.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_source.h" +#include "chrome/common/notification_type.h" +#include "testing/gmock/include/gmock/gmock.h" + +class NotificationObserverMock : public NotificationObserver { + public: + NotificationObserverMock() {} + virtual ~NotificationObserverMock() {} + + MOCK_METHOD3(Observe, void(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details)); +}; + +#endif // CHROME_COMMON_NOTIFICATION_OBSERVER_MOCK_H_ diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 4a45a3e..ed930c2 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -775,6 +775,10 @@ class NotificationType { // (the pointer is usable). No details are expected. NOTIFY_BALLOON_DISCONNECTED, + // This notification is sent whenever the list of autofill values + // has been changed. + AUTOFILL_CHANGED, + // Count (must be last) ---------------------------------------------------- // Used to determine the number of notification types. Not valid as // a type parameter when registering for or posting notifications. |