Chromium Code Reviews| 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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 // Cancels the callback. | 48 // Cancels the callback. |
| 49 void CancelCallback() { | 49 void CancelCallback() { |
| 50 callback_ = NULL; | 50 callback_ = NULL; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Cancels the callback and cancels the op if it is not executing. | 53 // Cancels the callback and cancels the op if it is not executing. |
| 54 void Cancel() { | 54 void Cancel() { |
| 55 CancelCallback(); | 55 CancelCallback(); |
| 56 | 56 |
| 57 if (!executing_) | 57 if (!executing_) |
| 58 OnOpCompleted(); | 58 OnOpCompleted(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Accessors. | 61 // Accessors. |
| 62 SignedSettings* op() const { | 62 SignedSettings* op() const { |
| 63 return op_.get(); | 63 return op_.get(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 SignedSettingsHelper::Callback* callback() const { | 66 SignedSettingsHelper::Callback* callback() const { |
| 67 return callback_; | 67 return callback_; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 virtual void CreateOp() { | 222 virtual void CreateOp() { |
| 223 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); | 223 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); |
| 224 } | 224 } |
| 225 | 225 |
| 226 private: | 226 private: |
| 227 std::string name_; | 227 std::string name_; |
| 228 | 228 |
| 229 DISALLOW_COPY_AND_ASSIGN(RetrievePropertyOpContext); | 229 DISALLOW_COPY_AND_ASSIGN(RetrievePropertyOpContext); |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 class StorePolicyOpContext : public SignedSettings::Delegate<bool>, | |
| 233 public OpContext { | |
| 234 public: | |
| 235 StorePolicyOpContext(const std::string& value, | |
| 236 SignedSettingsHelper::Callback* callback, | |
| 237 Delegate* delegate) | |
| 238 : OpContext(callback, delegate), | |
| 239 value_(value) { | |
| 240 } | |
| 241 | |
| 242 // chromeos::SignedSettings::Delegate implementation | |
| 243 virtual void OnSettingsCompleted(SignedSettings::ReturnCode code, | |
|
Chris Masone
2011/03/23 23:03:53
On SettingsOpCompleted, no?
Mattias Nissler (ping if slow)
2011/03/24 18:55:57
Maybe this could use an OVERRIDE declaration then
Jakob Kummerow
2011/03/28 13:53:53
Most definitely. Good catch. Done.
Jakob Kummerow
2011/03/28 13:53:53
Done.
| |
| 244 bool unused) { | |
| 245 VLOG(2) << "OnSettingsOpCompleted, code = " << code; | |
| 246 if (callback_) | |
| 247 callback_->OnStorePolicyCompleted(code); | |
| 248 OnOpCompleted(); | |
| 249 } | |
| 250 | |
| 251 protected: | |
| 252 // OpContext implementation | |
| 253 virtual void CreateOp() { | |
| 254 op_ = SignedSettings::CreateStorePolicyOp(value_, this); | |
| 255 } | |
| 256 | |
| 257 private: | |
| 258 std::string value_; | |
| 259 DISALLOW_COPY_AND_ASSIGN(StorePolicyOpContext); | |
| 260 }; | |
| 261 | |
| 262 class RetrievePolicyOpContext : public SignedSettings::Delegate<std::string>, | |
| 263 public OpContext { | |
| 264 public: | |
| 265 RetrievePolicyOpContext(SignedSettingsHelper::Callback* callback, | |
| 266 Delegate* delegate) | |
| 267 : OpContext(callback, delegate) { | |
| 268 } | |
| 269 | |
| 270 // chromeos::SignedSettings::Delegate implementation | |
| 271 virtual void OnSettingsCompleted(SignedSettings::ReturnCode code, | |
|
Chris Masone
2011/03/23 23:03:53
Again
Jakob Kummerow
2011/03/28 13:53:53
Done.
| |
| 272 std::string value) { | |
| 273 if (callback_) | |
| 274 callback_->OnRetrievePolicyCompleted(code, value); | |
| 275 OnOpCompleted(); | |
| 276 } | |
| 277 | |
| 278 protected: | |
| 279 // OpContext implementation | |
| 280 virtual void CreateOp() { | |
| 281 op_ = SignedSettings::CreateRetrievePolicyOp(this); | |
| 282 } | |
| 283 | |
| 284 private: | |
| 285 DISALLOW_COPY_AND_ASSIGN(RetrievePolicyOpContext); | |
| 286 }; | |
| 287 | |
| 232 } // namespace | 288 } // namespace |
| 233 | 289 |
| 234 | 290 |
| 235 class SignedSettingsHelperImpl : public SignedSettingsHelper, | 291 class SignedSettingsHelperImpl : public SignedSettingsHelper, |
| 236 public OpContext::Delegate { | 292 public OpContext::Delegate { |
| 237 public: | 293 public: |
| 238 // SignedSettingsHelper implementation | 294 // SignedSettingsHelper implementation |
| 239 virtual void StartCheckWhitelistOp(const std::string& email, | 295 virtual void StartCheckWhitelistOp(const std::string& email, |
| 240 Callback* callback); | 296 Callback* callback); |
| 241 virtual void StartWhitelistOp(const std::string& email, | 297 virtual void StartWhitelistOp(const std::string& email, |
| 242 bool add_to_whitelist, | 298 bool add_to_whitelist, |
| 243 Callback* callback); | 299 Callback* callback); |
| 244 virtual void StartStorePropertyOp(const std::string& name, | 300 virtual void StartStorePropertyOp(const std::string& name, |
| 245 const std::string& value, | 301 const std::string& value, |
| 246 Callback* callback); | 302 Callback* callback); |
| 247 virtual void StartRetrieveProperty(const std::string& name, | 303 virtual void StartRetrieveProperty(const std::string& name, |
| 248 Callback* callback); | 304 Callback* callback); |
| 305 virtual void StartStorePolicyOp(const std::string& value, | |
| 306 Callback* callback); | |
| 307 virtual void StartRetrievePolicyOp(Callback* callback); | |
| 249 virtual void CancelCallback(Callback* callback); | 308 virtual void CancelCallback(Callback* callback); |
| 250 | 309 |
| 251 // OpContext::Delegate implementation | 310 // OpContext::Delegate implementation |
| 252 virtual void OnOpCreated(OpContext* context); | 311 virtual void OnOpCreated(OpContext* context); |
| 253 virtual void OnOpStarted(OpContext* context); | 312 virtual void OnOpStarted(OpContext* context); |
| 254 virtual void OnOpCompleted(OpContext* context); | 313 virtual void OnOpCompleted(OpContext* context); |
| 255 | 314 |
| 256 private: | 315 private: |
| 257 SignedSettingsHelperImpl(); | 316 SignedSettingsHelperImpl(); |
| 258 ~SignedSettingsHelperImpl(); | 317 ~SignedSettingsHelperImpl(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 AddOpContext(new WhitelistOpContext( | 356 AddOpContext(new WhitelistOpContext( |
| 298 add_to_whitelist ? WhitelistOpContext::ADD : WhitelistOpContext::REMOVE, | 357 add_to_whitelist ? WhitelistOpContext::ADD : WhitelistOpContext::REMOVE, |
| 299 email, | 358 email, |
| 300 callback, | 359 callback, |
| 301 this)); | 360 this)); |
| 302 } | 361 } |
| 303 | 362 |
| 304 void SignedSettingsHelperImpl::StartStorePropertyOp( | 363 void SignedSettingsHelperImpl::StartStorePropertyOp( |
| 305 const std::string& name, | 364 const std::string& name, |
| 306 const std::string& value, | 365 const std::string& value, |
| 307 SignedSettingsHelper::SignedSettingsHelper::Callback* callback) { | 366 SignedSettingsHelper::Callback* callback) { |
| 308 AddOpContext(new StorePropertyOpContext( | 367 AddOpContext(new StorePropertyOpContext( |
| 309 name, | 368 name, |
| 310 value, | 369 value, |
| 311 callback, | 370 callback, |
| 312 this)); | 371 this)); |
| 313 } | 372 } |
| 314 | 373 |
| 315 void SignedSettingsHelperImpl::StartRetrieveProperty( | 374 void SignedSettingsHelperImpl::StartRetrieveProperty( |
| 316 const std::string& name, | 375 const std::string& name, |
| 317 SignedSettingsHelper::Callback* callback) { | 376 SignedSettingsHelper::Callback* callback) { |
| 318 AddOpContext(new RetrievePropertyOpContext( | 377 AddOpContext(new RetrievePropertyOpContext( |
| 319 name, | 378 name, |
| 320 callback, | 379 callback, |
| 321 this)); | 380 this)); |
| 322 } | 381 } |
| 323 | 382 |
| 383 void SignedSettingsHelperImpl::StartStorePolicyOp( | |
| 384 const std::string& value, | |
| 385 SignedSettingsHelper::Callback* callback) { | |
| 386 AddOpContext(new StorePolicyOpContext(value, callback, this)); | |
| 387 } | |
| 388 | |
| 389 void SignedSettingsHelperImpl::StartRetrievePolicyOp( | |
| 390 SignedSettingsHelper::Callback* callback) { | |
| 391 AddOpContext(new RetrievePolicyOpContext(callback, this)); | |
| 392 } | |
| 393 | |
| 324 void SignedSettingsHelperImpl::CancelCallback( | 394 void SignedSettingsHelperImpl::CancelCallback( |
| 325 SignedSettingsHelper::Callback* callback) { | 395 SignedSettingsHelper::Callback* callback) { |
| 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 327 | 397 |
| 328 for (size_t i = 0; i < pending_contexts_.size(); ++i) { | 398 for (size_t i = 0; i < pending_contexts_.size(); ++i) { |
| 329 if (pending_contexts_[i]->callback() == callback) { | 399 if (pending_contexts_[i]->callback() == callback) { |
| 330 pending_contexts_[i]->CancelCallback(); | 400 pending_contexts_[i]->CancelCallback(); |
| 331 } | 401 } |
| 332 } | 402 } |
| 333 } | 403 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 | 441 |
| 372 if (test_delegate_) | 442 if (test_delegate_) |
| 373 test_delegate_->OnOpCompleted(context->op()); | 443 test_delegate_->OnOpCompleted(context->op()); |
| 374 } | 444 } |
| 375 | 445 |
| 376 SignedSettingsHelper* SignedSettingsHelper::Get() { | 446 SignedSettingsHelper* SignedSettingsHelper::Get() { |
| 377 return g_signed_settings_helper_impl.Pointer(); | 447 return g_signed_settings_helper_impl.Pointer(); |
| 378 } | 448 } |
| 379 | 449 |
| 380 } // namespace chromeos | 450 } // namespace chromeos |
| OLD | NEW |