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