Chromium Code Reviews| 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) |
| 58 : type_(type), | |
| 59 callback_(DestroyCallback()) { | |
| 60 } | |
| 61 | |
| 62 WDTypedResult(WDResultType type, const DestroyCallback& callback) | |
| 63 : type_(type), | |
| 64 callback_(callback) { | |
| 46 } | 65 } |
| 47 | 66 |
| 48 private: | 67 private: |
| 49 WDResultType type_; | 68 WDResultType type_; |
| 69 DestroyCallback callback_; | |
| 50 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); | 70 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); |
| 51 }; | 71 }; |
| 52 | 72 |
| 53 // A result containing one specific pointer or literal value. | 73 // A result containing one specific pointer or literal value. |
| 54 template <class T> class WDResult : public WDTypedResult { | 74 template <class T> class WDResult : public WDTypedResult { |
| 55 public: | 75 public: |
| 76 explicit WDResult(WDResultType type, const T& v) | |
|
dhollowa
2013/01/07 21:27:13
nit: omit "explicit", only needed for single-param
Cait (Slow)
2013/01/07 22:43:32
Done.
| |
| 77 : WDTypedResult(type), value_(v) { | |
| 78 } | |
| 56 | 79 |
| 57 WDResult(WDResultType type, const T& v) : WDTypedResult(type), value_(v) { | 80 WDResult(WDResultType type, const DestroyCallback& callback, const T& v) |
| 81 : WDTypedResult(type, callback), value_(v) { | |
| 58 } | 82 } |
| 59 | 83 |
| 60 virtual ~WDResult() { | 84 virtual ~WDResult() { |
| 61 } | 85 } |
| 62 | 86 |
| 63 // Return a single value result. | 87 // Return a single value result. |
| 64 T GetValue() const { | 88 T GetValue() const { |
| 65 return value_; | 89 return value_; |
| 66 } | 90 } |
| 67 | 91 |
| 68 private: | 92 private: |
| 69 T value_; | 93 T value_; |
| 70 | 94 |
| 71 DISALLOW_COPY_AND_ASSIGN(WDResult); | 95 DISALLOW_COPY_AND_ASSIGN(WDResult); |
| 72 }; | 96 }; |
| 73 | 97 |
| 74 template <class T> class WDObjectResult : public WDTypedResult { | 98 template <class T> class WDObjectResult : public WDTypedResult { |
| 75 public: | 99 public: |
| 76 explicit WDObjectResult(WDResultType type) : WDTypedResult(type) { | 100 explicit WDObjectResult(WDResultType type) |
| 101 : WDTypedResult(type) { | |
| 102 } | |
| 103 | |
| 104 WDObjectResult(WDResultType type, const DestroyCallback& callback) | |
| 105 : WDTypedResult(type, callback) { | |
| 77 } | 106 } |
| 78 | 107 |
| 79 T* GetValue() const { | 108 T* GetValue() const { |
| 80 return &value_; | 109 return &value_; |
| 81 } | 110 } |
| 82 | 111 |
| 83 private: | 112 private: |
| 84 // mutable to keep GetValue() const. | 113 // mutable to keep GetValue() const. |
| 85 mutable T value_; | 114 mutable T value_; |
| 86 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); | 115 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); |
| 87 }; | 116 }; |
| 88 | 117 |
| 89 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ | 118 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ |
| OLD | NEW |