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" | 9 #include "base/callback.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 } WDResultType; | 33 } WDResultType; |
34 | 34 |
35 | 35 |
36 typedef base::Callback<void(const WDTypedResult*)> DestroyCallback; | 36 typedef base::Callback<void(const WDTypedResult*)> DestroyCallback; |
37 | 37 |
38 // | 38 // |
39 // The top level class for a result. | 39 // The top level class for a result. |
40 // | 40 // |
41 class WDTypedResult { | 41 class WDTypedResult { |
42 public: | 42 public: |
43 virtual ~WDTypedResult(); | 43 virtual ~WDTypedResult() { |
44 } | |
44 | 45 |
45 // Return the result type. | 46 // Return the result type. |
46 WDResultType GetType() const { | 47 WDResultType GetType() const { |
47 return type_; | 48 return type_; |
48 } | 49 } |
49 | 50 |
50 void Destroy() const { | 51 virtual void Destroy() { |
51 if (!callback_.is_null()) { | |
52 callback_.Run(this); | |
53 } | |
54 } | 52 } |
55 | 53 |
56 protected: | 54 protected: |
57 explicit WDTypedResult(WDResultType type); | 55 explicit WDTypedResult(WDResultType type) |
58 | 56 : type_(type) { |
59 WDTypedResult(WDResultType type, const DestroyCallback& callback); | 57 } |
60 | 58 |
61 private: | 59 private: |
62 WDResultType type_; | 60 WDResultType type_; |
63 DestroyCallback callback_; | |
64 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); | 61 DISALLOW_COPY_AND_ASSIGN(WDTypedResult); |
65 }; | 62 }; |
66 | 63 |
67 // A result containing one specific pointer or literal value. | 64 // A result containing one specific pointer or literal value. |
68 template <class T> class WDResult : public WDTypedResult { | 65 template <class T> class WDResult : public WDTypedResult { |
69 public: | 66 public: |
70 WDResult(WDResultType type, const T& v) | 67 WDResult(WDResultType type, const T& v) |
71 : WDTypedResult(type), value_(v) { | 68 : WDTypedResult(type), value_(v) { |
72 } | 69 } |
73 | 70 |
74 WDResult(WDResultType type, const DestroyCallback& callback, const T& v) | |
75 : WDTypedResult(type, callback), value_(v) { | |
76 } | |
77 | |
78 virtual ~WDResult() { | 71 virtual ~WDResult() { |
79 } | 72 } |
80 | 73 |
81 // Return a single value result. | 74 // Return a single value result. |
82 T GetValue() const { | 75 T GetValue() const { |
83 return value_; | 76 return value_; |
84 } | 77 } |
85 | 78 |
86 private: | 79 private: |
87 T value_; | 80 T value_; |
88 | 81 |
89 DISALLOW_COPY_AND_ASSIGN(WDResult); | 82 DISALLOW_COPY_AND_ASSIGN(WDResult); |
90 }; | 83 }; |
91 | 84 |
85 template <class T> class WDDestroyableResult : public WDTypedResult { | |
86 public: | |
87 WDDestroyableResult(WDResultType type, const T& v, | |
88 const DestroyCallback& callback) | |
erikwright (departed)
2013/01/28 20:01:05
indentation.
Cait (Slow)
2013/01/29 01:10:29
Done.
| |
89 : WDTypedResult(type), value_(v), callback_(callback) { | |
90 } | |
91 | |
92 virtual ~WDDestroyableResult() { | |
93 } | |
94 | |
95 | |
96 virtual void Destroy() OVERRIDE { | |
97 if (!callback_.is_null()) { | |
98 callback_.Run(this); | |
99 } | |
100 } | |
101 | |
102 // Return a single value result. | |
103 T GetValue() const { | |
104 return value_; | |
105 } | |
106 | |
107 private: | |
108 T value_; | |
109 DestroyCallback callback_; | |
110 | |
111 DISALLOW_COPY_AND_ASSIGN(WDDestroyableResult); | |
112 }; | |
113 | |
92 template <class T> class WDObjectResult : public WDTypedResult { | 114 template <class T> class WDObjectResult : public WDTypedResult { |
93 public: | 115 public: |
94 explicit WDObjectResult(WDResultType type) | 116 explicit WDObjectResult(WDResultType type) |
95 : WDTypedResult(type) { | 117 : WDTypedResult(type) { |
96 } | 118 } |
97 | 119 |
98 WDObjectResult(WDResultType type, const DestroyCallback& callback) | |
99 : WDTypedResult(type, callback) { | |
100 } | |
101 | |
102 T* GetValue() const { | 120 T* GetValue() const { |
103 return &value_; | 121 return &value_; |
104 } | 122 } |
105 | 123 |
106 private: | 124 private: |
107 // mutable to keep GetValue() const. | 125 // mutable to keep GetValue() const. |
108 mutable T value_; | 126 mutable T value_; |
109 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); | 127 DISALLOW_COPY_AND_ASSIGN(WDObjectResult); |
110 }; | 128 }; |
111 | 129 |
112 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ | 130 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ |
OLD | NEW |