Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / components / webdata / common / web_data_results.h
blob6d454335ce8b5927754b33c2d999a33af23be42e
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"
12 class WDTypedResult;
15 // Result types for WebDataService.
17 typedef enum {
18 BOOL_RESULT = 1, // WDResult<bool>
19 KEYWORDS_RESULT, // WDResult<WDKeywordsResult>
20 INT64_RESULT, // WDResult<int64>
21 #if defined(OS_WIN)
22 PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo>
23 #endif
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 } WDResultType;
35 typedef base::Callback<void(const WDTypedResult*)> DestroyCallback;
38 // The top level class for a result.
40 class WEBDATA_EXPORT WDTypedResult {
41 public:
42 virtual ~WDTypedResult() {
45 // Return the result type.
46 WDResultType GetType() const {
47 return type_;
50 virtual void Destroy() {
53 protected:
54 explicit WDTypedResult(WDResultType type)
55 : type_(type) {
58 private:
59 WDResultType type_;
60 DISALLOW_COPY_AND_ASSIGN(WDTypedResult);
63 // A result containing one specific pointer or literal value.
64 template <class T> class WDResult : public WDTypedResult {
65 public:
66 WDResult(WDResultType type, const T& v)
67 : WDTypedResult(type), value_(v) {
70 virtual ~WDResult() {
73 // Return a single value result.
74 T GetValue() const {
75 return value_;
78 private:
79 T value_;
81 DISALLOW_COPY_AND_ASSIGN(WDResult);
84 template <class T> class WDDestroyableResult : public WDTypedResult {
85 public:
86 WDDestroyableResult(
87 WDResultType type,
88 const T& v,
89 const DestroyCallback& callback)
90 : WDTypedResult(type),
91 value_(v),
92 callback_(callback) {
95 virtual ~WDDestroyableResult() {
99 virtual void Destroy() override {
100 if (!callback_.is_null()) {
101 callback_.Run(this);
105 // Return a single value result.
106 T GetValue() const {
107 return value_;
110 private:
111 T value_;
112 DestroyCallback callback_;
114 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult);
117 template <class T> class WDObjectResult : public WDTypedResult {
118 public:
119 explicit WDObjectResult(WDResultType type)
120 : WDTypedResult(type) {
123 T* GetValue() const {
124 return &value_;
127 private:
128 // mutable to keep GetValue() const.
129 mutable T value_;
130 DISALLOW_COPY_AND_ASSIGN(WDObjectResult);
133 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_