OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ | 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ |
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ | 6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "components/webdata/common/webdata_export.h" | 13 #include "components/webdata/common/webdata_export.h" |
14 | 14 |
15 class WDTypedResult; | 15 class WDTypedResult; |
16 | 16 |
17 // | 17 // |
18 // Result types for WebDataService. | 18 // Result types for WebDataService. |
19 // | 19 // |
20 typedef enum { | 20 typedef enum { |
21 BOOL_RESULT = 1, // WDResult<bool> | 21 BOOL_RESULT = 1, // WDResult<bool> |
22 KEYWORDS_RESULT, // WDResult<WDKeywordsResult> | 22 KEYWORDS_RESULT, // WDResult<WDKeywordsResult> |
23 INT64_RESULT, // WDResult<int64_t> | 23 INT64_RESULT, // WDResult<int64_t> |
24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) // |
25 PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo> | 25 PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo> |
26 #endif | 26 #endif // |
27 WEB_APP_IMAGES, // WDResult<WDAppImagesResult> | 27 WEB_APP_IMAGES, // WDResult<WDAppImagesResult> |
28 TOKEN_RESULT, // WDResult<std::vector<std::string>> | 28 TOKEN_RESULT, // WDResult<std::vector<std::string>> |
29 AUTOFILL_VALUE_RESULT, // WDResult<std::vector<base::string16>> | 29 AUTOFILL_VALUE_RESULT, // WDResult<std::vector<base::string16>> |
30 AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>> | 30 AUTOFILL_CHANGES, // WDResult<std::vector<AutofillChange>> |
31 AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile> | 31 AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile> |
32 AUTOFILL_PROFILES_RESULT, // WDResult<std::vector<AutofillProfile*>> | 32 AUTOFILL_PROFILES_RESULT, // WDResult<std::vector< |
| 33 // std::unique_ptr<AutofillProfile>>> |
33 AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard> | 34 AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard> |
34 AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector<CreditCard*>> | 35 AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector< |
| 36 // std::unique_ptr<CreditCard>>> |
35 } WDResultType; | 37 } WDResultType; |
36 | 38 |
37 | |
38 typedef base::Callback<void(const WDTypedResult*)> DestroyCallback; | |
39 | |
40 // | 39 // |
41 // The top level class for a result. | 40 // The top level class for a result. |
42 // | 41 // |
43 class WEBDATA_EXPORT WDTypedResult { | 42 class WEBDATA_EXPORT WDTypedResult { |
44 public: | 43 public: |
45 virtual ~WDTypedResult() { | 44 virtual ~WDTypedResult() { |
46 } | 45 } |
47 | 46 |
48 // Return the result type. | 47 // Return the result type. |
49 WDResultType GetType() const { | 48 WDResultType GetType() const { |
50 return type_; | 49 return type_; |
51 } | 50 } |
52 | 51 |
53 virtual void Destroy() { | |
54 } | |
55 | |
56 protected: | 52 protected: |
57 explicit WDTypedResult(WDResultType type) | 53 explicit WDTypedResult(WDResultType type) |
58 : type_(type) { | 54 : type_(type) { |
59 } | 55 } |
60 | 56 |
61 private: | 57 private: |
62 WDResultType type_; | 58 WDResultType type_; |
63 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); | 59 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); |
64 }; | 60 }; |
65 | 61 |
66 // A result containing one specific pointer or literal value. | 62 // A result containing one specific pointer or literal value. |
67 template <class T> class WDResult : public WDTypedResult { | 63 template <class T> class WDResult : public WDTypedResult { |
68 public: | 64 public: |
69 WDResult(WDResultType type, const T& v) | 65 WDResult(WDResultType type, const T& v) : WDTypedResult(type), value_(v) {} |
70 : WDTypedResult(type), value_(v) { | 66 WDResult(WDResultType type, T&& v) |
71 } | 67 : WDTypedResult(type), value_(std::move(v)) {} |
72 | 68 |
73 ~WDResult() override { | 69 ~WDResult() override {} |
74 } | |
75 | 70 |
76 // Return a single value result. | 71 // Return a single value result. |
77 T GetValue() const { | 72 const T& GetValue() const { return value_; } |
78 return value_; | 73 T GetValue() { return std::move(value_); } |
79 } | |
80 | 74 |
81 private: | 75 private: |
82 T value_; | 76 T value_; |
83 | 77 |
84 DISALLOW_COPY_AND_ASSIGN(WDResult); | 78 DISALLOW_COPY_AND_ASSIGN(WDResult); |
85 }; | 79 }; |
86 | 80 |
87 template <class T> class WDDestroyableResult : public WDResult<T> { | |
88 public: | |
89 WDDestroyableResult( | |
90 WDResultType type, | |
91 const T& v, | |
92 const DestroyCallback& callback) | |
93 : WDResult<T>(type, v), | |
94 callback_(callback) { | |
95 } | |
96 | |
97 ~WDDestroyableResult() override { | |
98 } | |
99 | |
100 void Destroy() override { | |
101 if (!callback_.is_null()) { | |
102 callback_.Run(this); | |
103 } | |
104 } | |
105 | |
106 private: | |
107 DestroyCallback callback_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult); | |
110 }; | |
111 | |
112 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ | 81 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ |
OLD | NEW |