1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "components/webdata/common/webdata_export.h"
15 // Result types for WebDataService.
18 BOOL_RESULT
= 1, // WDResult<bool>
19 KEYWORDS_RESULT
, // WDResult<WDKeywordsResult>
20 INT64_RESULT
, // WDResult<int64>
22 PASSWORD_IE7_RESULT
, // WDResult<IE7PasswordInfo>
24 WEB_APP_IMAGES
, // WDResult<WDAppImagesResult>
25 TOKEN_RESULT
, // WDResult<std::vector<std::string>>
26 AUTOFILL_VALUE_RESULT
, // WDResult<std::vector<base::string16>>
27 AUTOFILL_CHANGES
, // WDResult<std::vector<AutofillChange>>
28 AUTOFILL_PROFILE_RESULT
, // WDResult<AutofillProfile>
29 AUTOFILL_PROFILES_RESULT
, // WDResult<std::vector<AutofillProfile*>>
30 AUTOFILL_CREDITCARD_RESULT
, // WDResult<CreditCard>
31 AUTOFILL_CREDITCARDS_RESULT
, // WDResult<std::vector<CreditCard*>>
32 WEB_INTENTS_RESULT
, // WDResult<std::vector<WebIntentServiceData>>
33 WEB_INTENTS_DEFAULTS_RESULT
, // WDResult<std::vector<DefaultWebIntentService>>
37 typedef base::Callback
<void(const WDTypedResult
*)> DestroyCallback
;
40 // The top level class for a result.
42 class WEBDATA_EXPORT WDTypedResult
{
44 virtual ~WDTypedResult() {
47 // Return the result type.
48 WDResultType
GetType() const {
52 virtual void Destroy() {
56 explicit WDTypedResult(WDResultType type
)
62 DISALLOW_COPY_AND_ASSIGN(WDTypedResult
);
65 // A result containing one specific pointer or literal value.
66 template <class T
> class WDResult
: public WDTypedResult
{
68 WDResult(WDResultType type
, const T
& v
)
69 : WDTypedResult(type
), value_(v
) {
75 // Return a single value result.
83 DISALLOW_COPY_AND_ASSIGN(WDResult
);
86 template <class T
> class WDDestroyableResult
: public WDTypedResult
{
91 const DestroyCallback
& callback
)
92 : WDTypedResult(type
),
97 virtual ~WDDestroyableResult() {
101 virtual void Destroy() OVERRIDE
{
102 if (!callback_
.is_null()) {
107 // Return a single value result.
114 DestroyCallback callback_
;
116 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult
);
119 template <class T
> class WDObjectResult
: public WDTypedResult
{
121 explicit WDObjectResult(WDResultType type
)
122 : WDTypedResult(type
) {
125 T
* GetValue() const {
130 // mutable to keep GetValue() const.
132 DISALLOW_COPY_AND_ASSIGN(WDObjectResult
);
135 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_