OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ | |
6 #define CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/callback.h" | |
10 | |
11 class WDTypedResult; | |
12 | |
13 // | |
14 // Result types for WebDataService. | |
15 // | |
16 typedef enum { | |
17 BOOL_RESULT = 1, // WDResult<bool> | |
18 KEYWORDS_RESULT, // WDResult<WDKeywordsResult> | |
19 INT64_RESULT, // WDResult<int64> | |
20 #if defined(OS_WIN) | |
21 PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo> | |
22 #endif | |
23 WEB_APP_IMAGES, // WDResult<WDAppImagesResult> | |
24 TOKEN_RESULT, // WDResult<std::vector<std::string>> | |
25 AUTOFILL_VALUE_RESULT, // WDResult<std::vector<string16>> | |
26 AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>> | |
27 AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile> | |
28 AUTOFILL_PROFILES_RESULT, // WDResult<std::vector<AutofillProfile*>> | |
29 AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard> | |
30 AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector<CreditCard*>> | |
31 WEB_INTENTS_RESULT, // WDResult<std::vector<WebIntentServiceData>> | |
32 WEB_INTENTS_DEFAULTS_RESULT, // WDResult<std::vector<DefaultWebIntentService>> | |
33 } WDResultType; | |
34 | |
35 | |
36 typedef base::Callback<void(const WDTypedResult*)> DestroyCallback; | |
37 | |
38 // | |
39 // The top level class for a result. | |
40 // | |
41 class WDTypedResult { | |
42 public: | |
43 virtual ~WDTypedResult() { | |
44 } | |
45 | |
46 // Return the result type. | |
47 WDResultType GetType() const { | |
48 return type_; | |
49 } | |
50 | |
51 virtual void Destroy() { | |
52 } | |
53 | |
54 protected: | |
55 explicit WDTypedResult(WDResultType type) | |
56 : type_(type) { | |
57 } | |
58 | |
59 private: | |
60 WDResultType type_; | |
61 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); | |
62 }; | |
63 | |
64 // A result containing one specific pointer or literal value. | |
65 template <class T> class WDResult : public WDTypedResult { | |
66 public: | |
67 WDResult(WDResultType type, const T& v) | |
68 : WDTypedResult(type), value_(v) { | |
69 } | |
70 | |
71 virtual ~WDResult() { | |
72 } | |
73 | |
74 // Return a single value result. | |
75 T GetValue() const { | |
76 return value_; | |
77 } | |
78 | |
79 private: | |
80 T value_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(WDResult); | |
83 }; | |
84 | |
85 template <class T> class WDDestroyableResult : public WDTypedResult { | |
86 public: | |
87 WDDestroyableResult( | |
88 WDResultType type, | |
89 const T& v, | |
90 const DestroyCallback& callback) | |
91 : WDTypedResult(type), | |
92 value_(v), | |
93 callback_(callback) { | |
94 } | |
95 | |
96 virtual ~WDDestroyableResult() { | |
97 } | |
98 | |
99 | |
100 virtual void Destroy() OVERRIDE { | |
101 if (!callback_.is_null()) { | |
102 callback_.Run(this); | |
103 } | |
104 } | |
105 | |
106 // Return a single value result. | |
107 T GetValue() const { | |
108 return value_; | |
109 } | |
110 | |
111 private: | |
112 T value_; | |
113 DestroyCallback callback_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult); | |
116 }; | |
117 | |
118 template <class T> class WDObjectResult : public WDTypedResult { | |
119 public: | |
120 explicit WDObjectResult(WDResultType type) | |
121 : WDTypedResult(type) { | |
122 } | |
123 | |
124 T* GetValue() const { | |
125 return &value_; | |
126 } | |
127 | |
128 private: | |
129 // mutable to keep GetValue() const. | |
130 mutable T value_; | |
131 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); | |
132 }; | |
133 | |
134 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ | |
OLD | NEW |