OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/login/signed_settings_helper.h" | 5 #include "chrome/browser/chromeos/login/signed_settings_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 virtual void CreateOp() = 0; | 83 virtual void CreateOp() = 0; |
84 | 84 |
85 // Callback on op completion. | 85 // Callback on op completion. |
86 virtual void OnOpCompleted() { | 86 virtual void OnOpCompleted() { |
87 if (delegate_) | 87 if (delegate_) |
88 delegate_->OnOpCompleted(this); | 88 delegate_->OnOpCompleted(this); |
89 | 89 |
90 delete this; | 90 delete this; |
91 } | 91 } |
92 | 92 |
93 // Callback on op failure. | |
94 virtual void OnOpFailed() { | |
95 OnOpCompleted(); | |
96 } | |
97 | |
98 bool executing_; | 93 bool executing_; |
99 Delegate* delegate_; | 94 Delegate* delegate_; |
100 | 95 |
101 scoped_refptr<SignedSettings> op_; | 96 scoped_refptr<SignedSettings> op_; |
102 SignedSettingsHelper::Callback* callback_; | 97 SignedSettingsHelper::Callback* callback_; |
103 }; | 98 }; |
104 | 99 |
105 class WhitelistOpContext : public SignedSettings::Delegate<bool>, | 100 class WhitelistOpContext : public SignedSettings::Delegate<bool>, |
106 public OpContext { | 101 public OpContext { |
107 public: | 102 public: |
108 enum Type { | 103 enum Type { |
109 CHECK, | 104 CHECK, |
110 ADD, | 105 ADD, |
111 REMOVE, | 106 REMOVE, |
112 }; | 107 }; |
113 | 108 |
114 WhitelistOpContext(Type type, | 109 WhitelistOpContext(Type type, |
115 const std::string& email, | 110 const std::string& email, |
116 SignedSettingsHelper::Callback* callback, | 111 SignedSettingsHelper::Callback* callback, |
117 Delegate* delegate) | 112 Delegate* delegate) |
118 : OpContext(callback, delegate), | 113 : OpContext(callback, delegate), |
119 type_(type), | 114 type_(type), |
120 email_(email) { | 115 email_(email) { |
121 } | 116 } |
122 | 117 |
123 // chromeos::SignedSettings::Delegate implementation | 118 // chromeos::SignedSettings::Delegate implementation |
124 virtual void OnSettingsOpSucceeded(bool value) { | 119 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
| 120 bool value) { |
125 if (callback_) { | 121 if (callback_) { |
126 switch (type_) { | 122 switch (type_) { |
127 case CHECK: | 123 case CHECK: |
128 callback_->OnCheckWhiteListCompleted(value, email_); | 124 callback_->OnCheckWhitelistCompleted(code, email_); |
129 break; | 125 break; |
130 case ADD: | 126 case ADD: |
131 callback_->OnWhitelistCompleted(value, email_); | 127 callback_->OnWhitelistCompleted(code, email_); |
132 break; | 128 break; |
133 case REMOVE: | 129 case REMOVE: |
134 callback_->OnUnwhitelistCompleted(value, email_); | 130 callback_->OnUnwhitelistCompleted(code, email_); |
135 break; | 131 break; |
136 default: | 132 default: |
137 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; | 133 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; |
138 break; | 134 break; |
139 } | 135 } |
140 } | 136 } |
141 | |
142 OnOpCompleted(); | 137 OnOpCompleted(); |
143 } | 138 } |
144 | 139 |
145 virtual void OnSettingsOpFailed(SignedSettings::FailureCode code) { | |
146 OnOpFailed(); | |
147 } | |
148 | |
149 protected: | 140 protected: |
150 // OpContext implemenetation | 141 // OpContext implemenetation |
151 virtual void CreateOp() { | 142 virtual void CreateOp() { |
152 switch (type_) { | 143 switch (type_) { |
153 case CHECK: | 144 case CHECK: |
154 op_ = SignedSettings::CreateCheckWhitelistOp(email_, this); | 145 op_ = SignedSettings::CreateCheckWhitelistOp(email_, this); |
155 break; | 146 break; |
156 case ADD: | 147 case ADD: |
157 op_ = SignedSettings::CreateWhitelistOp(email_, true, this); | 148 op_ = SignedSettings::CreateWhitelistOp(email_, true, this); |
158 break; | 149 break; |
159 case REMOVE: | 150 case REMOVE: |
160 op_ = SignedSettings::CreateWhitelistOp(email_, false, this); | 151 op_ = SignedSettings::CreateWhitelistOp(email_, false, this); |
161 break; | 152 break; |
162 default: | 153 default: |
163 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; | 154 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; |
164 break; | 155 break; |
165 } | 156 } |
166 } | 157 } |
167 | 158 |
168 virtual void OnOpFailed() { | |
169 if (callback_) { | |
170 switch (type_) { | |
171 case CHECK: | |
172 callback_->OnCheckWhiteListCompleted(false, email_); | |
173 break; | |
174 case ADD: | |
175 callback_->OnWhitelistCompleted(false, email_); | |
176 break; | |
177 case REMOVE: | |
178 callback_->OnUnwhitelistCompleted(false, email_); | |
179 break; | |
180 default: | |
181 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; | |
182 break; | |
183 } | |
184 } | |
185 | |
186 OnOpCompleted(); | |
187 } | |
188 | |
189 private: | 159 private: |
190 Type type_; | 160 Type type_; |
191 std::string email_; | 161 std::string email_; |
192 | 162 |
193 DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); | 163 DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); |
194 }; | 164 }; |
195 | 165 |
196 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, | 166 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, |
197 public OpContext { | 167 public OpContext { |
198 public: | 168 public: |
199 StorePropertyOpContext(const std::string& name, | 169 StorePropertyOpContext(const std::string& name, |
200 const std::string& value, | 170 const std::string& value, |
201 SignedSettingsHelper::Callback* callback, | 171 SignedSettingsHelper::Callback* callback, |
202 Delegate* delegate) | 172 Delegate* delegate) |
203 : OpContext(callback, delegate), | 173 : OpContext(callback, delegate), |
204 name_(name), | 174 name_(name), |
205 value_(value) { | 175 value_(value) { |
206 } | 176 } |
207 | 177 |
208 // chromeos::SignedSettings::Delegate implementation | 178 // chromeos::SignedSettings::Delegate implementation |
209 virtual void OnSettingsOpSucceeded(bool value) { | 179 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
| 180 bool unused) { |
| 181 VLOG(2) << "OnSettingsOpCompleted, code = " << code; |
210 if (callback_) | 182 if (callback_) |
211 callback_->OnStorePropertyCompleted(true, name_, value_); | 183 callback_->OnStorePropertyCompleted(code, name_, value_); |
212 OnOpCompleted(); | 184 OnOpCompleted(); |
213 } | 185 } |
214 | 186 |
215 virtual void OnSettingsOpFailed(SignedSettings::FailureCode code) { | |
216 OnOpFailed(); | |
217 } | |
218 | |
219 protected: | 187 protected: |
220 // OpContext implemenetation | 188 // OpContext implemenetation |
221 virtual void CreateOp() { | 189 virtual void CreateOp() { |
222 op_ = SignedSettings::CreateStorePropertyOp(name_, value_, this); | 190 op_ = SignedSettings::CreateStorePropertyOp(name_, value_, this); |
223 } | 191 } |
224 | 192 |
225 virtual void OnOpFailed() { | |
226 if (callback_) | |
227 callback_->OnStorePropertyCompleted(false, name_, value_); | |
228 OnOpCompleted(); | |
229 } | |
230 | |
231 private: | 193 private: |
232 std::string name_; | 194 std::string name_; |
233 std::string value_; | 195 std::string value_; |
234 | 196 |
235 DISALLOW_COPY_AND_ASSIGN(StorePropertyOpContext); | 197 DISALLOW_COPY_AND_ASSIGN(StorePropertyOpContext); |
236 }; | 198 }; |
237 | 199 |
238 class RetrievePropertyOpContext | 200 class RetrievePropertyOpContext |
239 : public SignedSettings::Delegate<std::string>, | 201 : public SignedSettings::Delegate<std::string>, |
240 public OpContext { | 202 public OpContext { |
241 public: | 203 public: |
242 RetrievePropertyOpContext(const std::string& name, | 204 RetrievePropertyOpContext(const std::string& name, |
243 SignedSettingsHelper::Callback* callback, | 205 SignedSettingsHelper::Callback* callback, |
244 Delegate* delegate) | 206 Delegate* delegate) |
245 : OpContext(callback, delegate), | 207 : OpContext(callback, delegate), |
246 name_(name) { | 208 name_(name) { |
247 } | 209 } |
248 | 210 |
249 // chromeos::SignedSettings::Delegate implementation | 211 // chromeos::SignedSettings::Delegate implementation |
250 virtual void OnSettingsOpSucceeded(std::string value) { | 212 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
| 213 std::string value) { |
251 if (callback_) | 214 if (callback_) |
252 callback_->OnRetrievePropertyCompleted(true, name_, value); | 215 callback_->OnRetrievePropertyCompleted(code, name_, value); |
253 | 216 |
254 OnOpCompleted(); | 217 OnOpCompleted(); |
255 } | 218 } |
256 | 219 |
257 virtual void OnSettingsOpFailed(SignedSettings::FailureCode code) { | |
258 OnOpFailed(); | |
259 } | |
260 | |
261 protected: | 220 protected: |
262 // OpContext implemenetation | 221 // OpContext implemenetation |
263 virtual void CreateOp() { | 222 virtual void CreateOp() { |
264 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); | 223 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); |
265 } | 224 } |
266 | 225 |
267 virtual void OnOpFailed() { | |
268 if (callback_) | |
269 callback_->OnRetrievePropertyCompleted(false, name_, std::string()); | |
270 OnOpCompleted(); | |
271 } | |
272 | |
273 private: | 226 private: |
274 std::string name_; | 227 std::string name_; |
275 | 228 |
276 DISALLOW_COPY_AND_ASSIGN(RetrievePropertyOpContext); | 229 DISALLOW_COPY_AND_ASSIGN(RetrievePropertyOpContext); |
277 }; | 230 }; |
278 | 231 |
279 } // namespace | 232 } // namespace |
280 | 233 |
281 | 234 |
282 class SignedSettingsHelperImpl : public SignedSettingsHelper, | 235 class SignedSettingsHelperImpl : public SignedSettingsHelper, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 368 |
416 if (test_delegate_) | 369 if (test_delegate_) |
417 test_delegate_->OnOpCompleted(context->op()); | 370 test_delegate_->OnOpCompleted(context->op()); |
418 } | 371 } |
419 | 372 |
420 SignedSettingsHelper* SignedSettingsHelper::Get() { | 373 SignedSettingsHelper* SignedSettingsHelper::Get() { |
421 return Singleton<SignedSettingsHelperImpl>::get(); | 374 return Singleton<SignedSettingsHelperImpl>::get(); |
422 } | 375 } |
423 | 376 |
424 } // namespace chromeos | 377 } // namespace chromeos |
OLD | NEW |