diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-13 17:06:19 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-13 17:06:19 +0000 |
commit | 66769db5458358647d65c09c67e1daf58b1439a1 (patch) | |
tree | e4caa3c61245887efafde65f8983d772dd465806 /chrome/browser/api/webdata | |
parent | 9d8cfb68c1c0e887773f077c6e12692d69d5a846 (diff) | |
download | chromium_src-66769db5458358647d65c09c67e1daf58b1439a1.zip chromium_src-66769db5458358647d65c09c67e1daf58b1439a1.tar.gz chromium_src-66769db5458358647d65c09c67e1daf58b1439a1.tar.bz2 |
Introduce a couple of abstract bases for WebDataService.
WebDataService is really a collection of different services that have a common initialization and some commonality e.g. how to cancel requests, and it's probably best that the interfaces reflect this logical split so that the implementation might some daybe tidied up. Starting this off with a WebDataServiceBase for the common bits, and an AutofillWebData for the Autofill-specific functionalities of WebDataService.
Using these interfaces to break Autofill's concrete dependency on WebDataService.
TBR=ben@chromium.org
BUG=140037
Review URL: https://chromiumcodereview.appspot.com/10908065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156567 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/api/webdata')
-rw-r--r-- | chrome/browser/api/webdata/autofill_web_data.h | 89 | ||||
-rw-r--r-- | chrome/browser/api/webdata/autofill_web_data_service.h | 28 | ||||
-rw-r--r-- | chrome/browser/api/webdata/web_data_results.h | 89 | ||||
-rw-r--r-- | chrome/browser/api/webdata/web_data_service_base.h | 30 | ||||
-rw-r--r-- | chrome/browser/api/webdata/web_data_service_consumer.h | 26 |
5 files changed, 262 insertions, 0 deletions
diff --git a/chrome/browser/api/webdata/autofill_web_data.h b/chrome/browser/api/webdata/autofill_web_data.h new file mode 100644 index 0000000..d509dde --- /dev/null +++ b/chrome/browser/api/webdata/autofill_web_data.h @@ -0,0 +1,89 @@ +// Copyright (c) 2012 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_API_WEBDATA_AUTOFILL_WEB_DATA_H_ +#define CHROME_BROWSER_API_WEBDATA_AUTOFILL_WEB_DATA_H_ + +#include <string> +#include <vector> + +#include "base/memory/scoped_ptr.h" +#include "base/string16.h" +#include "chrome/browser/api/webdata/web_data_service_base.h" + +namespace webkit { +namespace forms { +struct FormField; +} +} + +class AutofillProfile; +class CreditCard; +class Profile; +class WebDataServiceConsumer; + +// Pure virtual interface for retrieving Autofill data. API users +// should use AutofillWebDataService. +class AutofillWebData { + public: + virtual ~AutofillWebData() {} + + // Schedules a task to add form fields to the web database. + virtual void AddFormFields( + const std::vector<webkit::forms::FormField>& fields) = 0; + + // Initiates the request for a vector of values which have been entered in + // form input fields named |name|. The method OnWebDataServiceRequestDone of + // |consumer| gets called back when the request is finished, with the vector + // included in the argument |result|. + virtual WebDataServiceBase::Handle GetFormValuesForElementName( + const string16& name, + const string16& prefix, + int limit, + WebDataServiceConsumer* consumer) = 0; + + virtual void RemoveExpiredFormElements() = 0; + virtual void RemoveFormValueForElementName(const string16& name, + const string16& value) = 0; + + // Schedules a task to add an Autofill profile to the web database. + virtual void AddAutofillProfile(const AutofillProfile& profile) = 0; + + // Schedules a task to update an Autofill profile in the web database. + virtual void UpdateAutofillProfile(const AutofillProfile& profile) = 0; + + // Schedules a task to remove an Autofill profile from the web database. + // |guid| is the identifer of the profile to remove. + virtual void RemoveAutofillProfile(const std::string& guid) = 0; + + // Initiates the request for all Autofill profiles. The method + // OnWebDataServiceRequestDone of |consumer| gets called when the request is + // finished, with the profiles included in the argument |result|. The + // consumer owns the profiles. + virtual WebDataServiceBase::Handle GetAutofillProfiles( + WebDataServiceConsumer* consumer) = 0; + + // Remove "trashed" profile guids from the web database and optionally send + // notifications to tell Sync that the items have been removed. + virtual void EmptyMigrationTrash(bool notify_sync) = 0; + + // Schedules a task to add credit card to the web database. + virtual void AddCreditCard(const CreditCard& credit_card) = 0; + + // Schedules a task to update credit card in the web database. + virtual void UpdateCreditCard(const CreditCard& credit_card) = 0; + + // Schedules a task to remove a credit card from the web database. + // |guid| is identifer of the credit card to remove. + virtual void RemoveCreditCard(const std::string& guid) = 0; + + // Initiates the request for all credit cards. The method + // OnWebDataServiceRequestDone of |consumer| gets called when the request is + // finished, with the credit cards included in the argument |result|. The + // consumer owns the credit cards. + virtual WebDataServiceBase::Handle + GetCreditCards(WebDataServiceConsumer* consumer) = 0; +}; + +#endif // CHROME_BROWSER_API_WEBDATA_AUTOFILL_WEB_DATA_H_ diff --git a/chrome/browser/api/webdata/autofill_web_data_service.h b/chrome/browser/api/webdata/autofill_web_data_service.h new file mode 100644 index 0000000..dc26832 --- /dev/null +++ b/chrome/browser/api/webdata/autofill_web_data_service.h @@ -0,0 +1,28 @@ +// Copyright (c) 2012 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_API_WEBDATA_AUTOFILL_WEB_DATA_SERVICE_H_ +#define CHROME_BROWSER_API_WEBDATA_AUTOFILL_WEB_DATA_SERVICE_H_ + +#include "chrome/browser/api/webdata/autofill_web_data.h" + +namespace content { +class BrowserContext; +} + +// API for Autofill web data. +class AutofillWebDataService + : public AutofillWebData, + public WebDataServiceBase { + public: + // Retrieve an AutofillWebDataService for the given context. + // + // Can return NULL in some contexts. + static scoped_ptr<AutofillWebDataService> ForContext( + content::BrowserContext* context); + + virtual ~AutofillWebDataService() {} +}; + +#endif // CHROME_BROWSER_API_WEBDATA_AUTOFILL_WEB_DATA_SERVICE_H_ diff --git a/chrome/browser/api/webdata/web_data_results.h b/chrome/browser/api/webdata/web_data_results.h new file mode 100644 index 0000000..6d2d5b8 --- /dev/null +++ b/chrome/browser/api/webdata/web_data_results.h @@ -0,0 +1,89 @@ +// Copyright (c) 2012 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_API_WEBDATA_WEB_DATA_RESULTS_H_ +#define CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ + +#include "base/basictypes.h" + +// +// Result types for WebDataService. +// +typedef enum { + BOOL_RESULT = 1, // WDResult<bool> + KEYWORDS_RESULT, // WDResult<WDKeywordsResult> + INT64_RESULT, // WDResult<int64> +#if defined(OS_WIN) + PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo> +#endif + WEB_APP_IMAGES, // WDResult<WDAppImagesResult> + TOKEN_RESULT, // WDResult<std::vector<std::string>> + AUTOFILL_VALUE_RESULT, // WDResult<std::vector<string16>> + AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>> + AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile> + AUTOFILL_PROFILES_RESULT, // WDResult<std::vector<AutofillProfile*>> + AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard> + AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector<CreditCard*>> + WEB_INTENTS_RESULT, // WDResult<std::vector<WebIntentServiceData>> + WEB_INTENTS_DEFAULTS_RESULT, // WDResult<std::vector<DefaultWebIntentService>> +} WDResultType; + +// +// The top level class for a result. +// +class WDTypedResult { + public: + virtual ~WDTypedResult() {} + + // Return the result type. + WDResultType GetType() const { + return type_; + } + + protected: + explicit WDTypedResult(WDResultType type) : type_(type) { + } + + private: + WDResultType type_; + DISALLOW_COPY_AND_ASSIGN(WDTypedResult); +}; + +// A result containing one specific pointer or literal value. +template <class T> class WDResult : public WDTypedResult { + public: + + WDResult(WDResultType type, const T& v) : WDTypedResult(type), value_(v) { + } + + virtual ~WDResult() { + } + + // Return a single value result. + T GetValue() const { + return value_; + } + + private: + T value_; + + DISALLOW_COPY_AND_ASSIGN(WDResult); +}; + +template <class T> class WDObjectResult : public WDTypedResult { + public: + explicit WDObjectResult(WDResultType type) : WDTypedResult(type) { + } + + T* GetValue() const { + return &value_; + } + + private: + // mutable to keep GetValue() const. + mutable T value_; + DISALLOW_COPY_AND_ASSIGN(WDObjectResult); +}; + +#endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ diff --git a/chrome/browser/api/webdata/web_data_service_base.h b/chrome/browser/api/webdata/web_data_service_base.h new file mode 100644 index 0000000..bb092c0 --- /dev/null +++ b/chrome/browser/api/webdata/web_data_service_base.h @@ -0,0 +1,30 @@ +// Copyright (c) 2012 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_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ +#define CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ + +#include "chrome/browser/profiles/refcounted_profile_keyed_service.h" +#include "content/public/browser/notification_source.h" + +class Profile; + +// Base for WebDataService class hierarchy. +class WebDataServiceBase { + public: + // All requests return an opaque handle of the following type. + typedef int Handle; + + virtual ~WebDataServiceBase() {} + + // Cancel any pending request. You need to call this method if your + // WebDataServiceConsumer is about to be deleted. + virtual void CancelRequest(Handle h) = 0; + + // Returns the notification source for this service. This may use a + // pointer other than this object's |this| pointer. + virtual content::NotificationSource GetNotificationSource() = 0; +}; + +#endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ diff --git a/chrome/browser/api/webdata/web_data_service_consumer.h b/chrome/browser/api/webdata/web_data_service_consumer.h new file mode 100644 index 0000000..b42bc30 --- /dev/null +++ b/chrome/browser/api/webdata/web_data_service_consumer.h @@ -0,0 +1,26 @@ +// Copyright (c) 2012 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_API_WEBDATA_WEB_DATA_SERVICE_CONSUMER_H_ +#define CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_CONSUMER_H_ + +#include "chrome/browser/api/webdata/web_data_results.h" +#include "chrome/browser/api/webdata/web_data_service_base.h" + +// All requests to the web data service are asynchronous. When the request has +// been performed, the data consumer is notified using the following interface. +class WebDataServiceConsumer { + public: + // Called when a request is done. h uniquely identifies the request. + // result can be NULL, if no result is expected or if the database could + // not be opened. The result object is destroyed after this call. + virtual void OnWebDataServiceRequestDone(WebDataServiceBase::Handle h, + const WDTypedResult* result) = 0; + + protected: + virtual ~WebDataServiceConsumer() {} +}; + + +#endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_CONSUMER_H_ |