OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 Type type_; | 163 Type type_; |
164 std::string email_; | 164 std::string email_; |
165 | 165 |
166 DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); | 166 DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); |
167 }; | 167 }; |
168 | 168 |
169 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, | 169 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, |
170 public OpContext { | 170 public OpContext { |
171 public: | 171 public: |
172 StorePropertyOpContext(const std::string& name, | 172 StorePropertyOpContext(const std::string& name, |
173 const std::string& value, | 173 const base::Value& value, |
174 SignedSettingsHelper::Callback* callback, | 174 SignedSettingsHelper::Callback* callback, |
175 OpContext::Delegate* delegate) | 175 OpContext::Delegate* delegate) |
176 : OpContext(callback, delegate), | 176 : OpContext(callback, delegate), |
177 name_(name), | 177 name_(name), |
178 value_(value) { | 178 value_(value.DeepCopy()) { |
179 } | 179 } |
180 | 180 |
181 // chromeos::SignedSettings::Delegate implementation | 181 // chromeos::SignedSettings::Delegate implementation |
182 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, | 182 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
183 bool unused) OVERRIDE { | 183 bool unused) OVERRIDE { |
184 VLOG(2) << "OnSettingsOpCompleted, code = " << code; | 184 VLOG(2) << "OnSettingsOpCompleted, code = " << code; |
185 if (callback_) | 185 if (callback_) |
186 callback_->OnStorePropertyCompleted(code, name_, value_); | 186 callback_->OnStorePropertyCompleted(code, name_, *value_); |
187 OnOpCompleted(); | 187 OnOpCompleted(); |
188 } | 188 } |
189 | 189 |
190 protected: | 190 protected: |
191 // OpContext implemenetation | 191 // OpContext implemenetation |
192 virtual void CreateOp() OVERRIDE { | 192 virtual void CreateOp() OVERRIDE { |
193 op_ = SignedSettings::CreateStorePropertyOp(name_, value_, this); | 193 op_ = SignedSettings::CreateStorePropertyOp(name_, *value_, this); |
194 } | 194 } |
195 | 195 |
196 private: | 196 private: |
197 std::string name_; | 197 std::string name_; |
198 std::string value_; | 198 scoped_ptr<base::Value> value_; |
199 | 199 |
200 DISALLOW_COPY_AND_ASSIGN(StorePropertyOpContext); | 200 DISALLOW_COPY_AND_ASSIGN(StorePropertyOpContext); |
201 }; | 201 }; |
202 | 202 |
203 class RetrievePropertyOpContext | 203 class RetrievePropertyOpContext |
204 : public SignedSettings::Delegate<std::string>, | 204 : public SignedSettings::Delegate<const base::Value*>, |
205 public OpContext { | 205 public OpContext { |
206 public: | 206 public: |
207 RetrievePropertyOpContext(const std::string& name, | 207 RetrievePropertyOpContext(const std::string& name, |
208 SignedSettingsHelper::Callback* callback, | 208 SignedSettingsHelper::Callback* callback, |
209 OpContext::Delegate* delegate) | 209 OpContext::Delegate* delegate) |
210 : OpContext(callback, delegate), | 210 : OpContext(callback, delegate), |
211 name_(name) { | 211 name_(name) { |
212 } | 212 } |
213 | 213 |
214 // chromeos::SignedSettings::Delegate implementation | 214 // chromeos::SignedSettings::Delegate implementation |
215 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, | 215 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
216 std::string value) OVERRIDE { | 216 const base::Value* value) OVERRIDE { |
217 if (callback_) | 217 if (callback_) |
218 callback_->OnRetrievePropertyCompleted(code, name_, value); | 218 callback_->OnRetrievePropertyCompleted(code, name_, value); |
219 | 219 |
220 OnOpCompleted(); | 220 OnOpCompleted(); |
221 } | 221 } |
222 | 222 |
223 protected: | 223 protected: |
224 // OpContext implemenetation | 224 // OpContext implemenetation |
225 virtual void CreateOp() OVERRIDE { | 225 virtual void CreateOp() OVERRIDE { |
226 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); | 226 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 class SignedSettingsHelperImpl : public SignedSettingsHelper, | 296 class SignedSettingsHelperImpl : public SignedSettingsHelper, |
297 public OpContext::Delegate { | 297 public OpContext::Delegate { |
298 public: | 298 public: |
299 // SignedSettingsHelper implementation | 299 // SignedSettingsHelper implementation |
300 virtual void StartCheckWhitelistOp(const std::string& email, | 300 virtual void StartCheckWhitelistOp(const std::string& email, |
301 Callback* callback) OVERRIDE; | 301 Callback* callback) OVERRIDE; |
302 virtual void StartWhitelistOp(const std::string& email, | 302 virtual void StartWhitelistOp(const std::string& email, |
303 bool add_to_whitelist, | 303 bool add_to_whitelist, |
304 Callback* callback) OVERRIDE; | 304 Callback* callback) OVERRIDE; |
305 virtual void StartStorePropertyOp(const std::string& name, | 305 virtual void StartStorePropertyOp(const std::string& name, |
306 const std::string& value, | 306 const base::Value& value, |
307 Callback* callback) OVERRIDE; | 307 Callback* callback) OVERRIDE; |
308 virtual void StartRetrieveProperty(const std::string& name, | 308 virtual void StartRetrieveProperty(const std::string& name, |
309 Callback* callback) OVERRIDE; | 309 Callback* callback) OVERRIDE; |
310 virtual void StartStorePolicyOp(const em::PolicyFetchResponse& policy, | 310 virtual void StartStorePolicyOp(const em::PolicyFetchResponse& policy, |
311 Callback* callback) OVERRIDE; | 311 Callback* callback) OVERRIDE; |
312 virtual void StartRetrievePolicyOp(Callback* callback) OVERRIDE; | 312 virtual void StartRetrievePolicyOp(Callback* callback) OVERRIDE; |
313 virtual void CancelCallback(Callback* callback) OVERRIDE; | 313 virtual void CancelCallback(Callback* callback) OVERRIDE; |
314 | 314 |
315 // OpContext::Delegate implementation | 315 // OpContext::Delegate implementation |
316 virtual void OnOpCreated(OpContext* context); | 316 virtual void OnOpCreated(OpContext* context); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 SignedSettingsHelper::Callback* callback) { | 360 SignedSettingsHelper::Callback* callback) { |
361 AddOpContext(new WhitelistOpContext( | 361 AddOpContext(new WhitelistOpContext( |
362 add_to_whitelist ? WhitelistOpContext::ADD : WhitelistOpContext::REMOVE, | 362 add_to_whitelist ? WhitelistOpContext::ADD : WhitelistOpContext::REMOVE, |
363 email, | 363 email, |
364 callback, | 364 callback, |
365 this)); | 365 this)); |
366 } | 366 } |
367 | 367 |
368 void SignedSettingsHelperImpl::StartStorePropertyOp( | 368 void SignedSettingsHelperImpl::StartStorePropertyOp( |
369 const std::string& name, | 369 const std::string& name, |
370 const std::string& value, | 370 const base::Value& value, |
371 SignedSettingsHelper::Callback* callback) { | 371 SignedSettingsHelper::Callback* callback) { |
372 AddOpContext(new StorePropertyOpContext( | 372 AddOpContext(new StorePropertyOpContext( |
373 name, | 373 name, |
374 value, | 374 value, |
375 callback, | 375 callback, |
376 this)); | 376 this)); |
377 } | 377 } |
378 | 378 |
379 void SignedSettingsHelperImpl::StartRetrieveProperty( | 379 void SignedSettingsHelperImpl::StartRetrieveProperty( |
380 const std::string& name, | 380 const std::string& name, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 446 |
447 if (test_delegate_) | 447 if (test_delegate_) |
448 test_delegate_->OnOpCompleted(context->op()); | 448 test_delegate_->OnOpCompleted(context->op()); |
449 } | 449 } |
450 | 450 |
451 SignedSettingsHelper* SignedSettingsHelper::Get() { | 451 SignedSettingsHelper* SignedSettingsHelper::Get() { |
452 return g_signed_settings_helper_impl.Pointer(); | 452 return g_signed_settings_helper_impl.Pointer(); |
453 } | 453 } |
454 | 454 |
455 } // namespace chromeos | 455 } // namespace chromeos |
OLD | NEW |