| 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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "components/webdata/common/webdata_export.h" | 10 #include "components/webdata/common/webdata_export.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 T GetValue() const { | 74 T GetValue() const { |
| 75 return value_; | 75 return value_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 T value_; | 79 T value_; |
| 80 | 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(WDResult); | 81 DISALLOW_COPY_AND_ASSIGN(WDResult); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 template <class T> class WDDestroyableResult : public WDTypedResult { | 84 template <class T> class WDDestroyableResult : public WDResult<T> { |
| 85 public: | 85 public: |
| 86 WDDestroyableResult( | 86 WDDestroyableResult( |
| 87 WDResultType type, | 87 WDResultType type, |
| 88 const T& v, | 88 const T& v, |
| 89 const DestroyCallback& callback) | 89 const DestroyCallback& callback) |
| 90 : WDTypedResult(type), | 90 : WDResult<T>(type, v), |
| 91 value_(v), | |
| 92 callback_(callback) { | 91 callback_(callback) { |
| 93 } | 92 } |
| 94 | 93 |
| 95 virtual ~WDDestroyableResult() { | 94 virtual ~WDDestroyableResult() { |
| 96 } | 95 } |
| 97 | 96 |
| 98 | 97 |
| 99 virtual void Destroy() override { | 98 virtual void Destroy() override { |
| 100 if (!callback_.is_null()) { | 99 if (!callback_.is_null()) { |
| 101 callback_.Run(this); | 100 callback_.Run(this); |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 | 103 |
| 105 // Return a single value result. | |
| 106 T GetValue() const { | |
| 107 return value_; | |
| 108 } | |
| 109 | |
| 110 private: | 104 private: |
| 111 T value_; | |
| 112 DestroyCallback callback_; | 105 DestroyCallback callback_; |
| 113 | 106 |
| 114 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult); | 107 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult); |
| 115 }; | 108 }; |
| 116 | 109 |
| 117 template <class T> class WDObjectResult : public WDTypedResult { | 110 template <class T> class WDObjectResult : public WDTypedResult { |
| 118 public: | 111 public: |
| 119 explicit WDObjectResult(WDResultType type) | 112 explicit WDObjectResult(WDResultType type) |
| 120 : WDTypedResult(type) { | 113 : WDTypedResult(type) { |
| 121 } | 114 } |
| 122 | 115 |
| 123 T* GetValue() const { | 116 T* GetValue() const { |
| 124 return &value_; | 117 return &value_; |
| 125 } | 118 } |
| 126 | 119 |
| 127 private: | 120 private: |
| 128 // mutable to keep GetValue() const. | 121 // mutable to keep GetValue() const. |
| 129 mutable T value_; | 122 mutable T value_; |
| 130 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); | 123 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); |
| 131 }; | 124 }; |
| 132 | 125 |
| 133 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ | 126 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_RESULTS_H_ |
| OLD | NEW |