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 WDTypedResult(WDResultType type, const DestroyCallback& callback) |
dhollowa
2013/01/04 23:57:36
It seems reasonable to me in this case to have a t
Cait (Slow)
2013/01/07 17:08:54
Done.
| |
58 : type_(type), | |
59 callback_(callback) { | |
46 } | 60 } |
47 | 61 |
48 private: | 62 private: |
49 WDResultType type_; | 63 WDResultType type_; |
64 DestroyCallback callback_; | |
50 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); | 65 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); |
51 }; | 66 }; |
52 | 67 |
53 // A result containing one specific pointer or literal value. | 68 // A result containing one specific pointer or literal value. |
54 template <class T> class WDResult : public WDTypedResult { | 69 template <class T> class WDResult : public WDTypedResult { |
55 public: | 70 public: |
56 | 71 |
57 WDResult(WDResultType type, const T& v) : WDTypedResult(type), value_(v) { | 72 WDResult(WDResultType type, const DestroyCallback& callback, const T& v) |
73 : WDTypedResult(type, callback), value_(v) { | |
58 } | 74 } |
59 | 75 |
60 virtual ~WDResult() { | 76 virtual ~WDResult() { |
61 } | 77 } |
62 | 78 |
63 // Return a single value result. | 79 // Return a single value result. |
64 T GetValue() const { | 80 T GetValue() const { |
65 return value_; | 81 return value_; |
66 } | 82 } |
67 | 83 |
68 private: | 84 private: |
69 T value_; | 85 T value_; |
70 | 86 |
71 DISALLOW_COPY_AND_ASSIGN(WDResult); | 87 DISALLOW_COPY_AND_ASSIGN(WDResult); |
72 }; | 88 }; |
73 | 89 |
74 template <class T> class WDObjectResult : public WDTypedResult { | 90 template <class T> class WDObjectResult : public WDTypedResult { |
75 public: | 91 public: |
76 explicit WDObjectResult(WDResultType type) : WDTypedResult(type) { | 92 WDObjectResult(WDResultType type, const DestroyCallback& callback) |
93 : WDTypedResult(type, callback) { | |
77 } | 94 } |
78 | 95 |
79 T* GetValue() const { | 96 T* GetValue() const { |
80 return &value_; | 97 return &value_; |
81 } | 98 } |
82 | 99 |
83 private: | 100 private: |
84 // mutable to keep GetValue() const. | 101 // mutable to keep GetValue() const. |
85 mutable T value_; | 102 mutable T value_; |
86 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); | 103 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); |
87 }; | 104 }; |
88 | 105 |
89 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ | 106 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ |
OLD | NEW |