| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 delete this; | 94 delete this; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool executing_; | 97 bool executing_; |
| 98 Delegate* delegate_; | 98 Delegate* delegate_; |
| 99 | 99 |
| 100 scoped_refptr<SignedSettings> op_; | 100 scoped_refptr<SignedSettings> op_; |
| 101 SignedSettingsHelper::Callback* callback_; | 101 SignedSettingsHelper::Callback* callback_; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 class WhitelistOpContext : public SignedSettings::Delegate<bool>, | |
| 105 public OpContext { | |
| 106 public: | |
| 107 enum Type { | |
| 108 CHECK, | |
| 109 ADD, | |
| 110 REMOVE, | |
| 111 }; | |
| 112 | |
| 113 WhitelistOpContext(Type type, | |
| 114 const std::string& email, | |
| 115 SignedSettingsHelper::Callback* callback, | |
| 116 OpContext::Delegate* delegate) | |
| 117 : OpContext(callback, delegate), | |
| 118 type_(type), | |
| 119 email_(email) { | |
| 120 } | |
| 121 | |
| 122 // chromeos::SignedSettings::Delegate implementation | |
| 123 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, | |
| 124 bool value) OVERRIDE { | |
| 125 if (callback_) { | |
| 126 switch (type_) { | |
| 127 case CHECK: | |
| 128 callback_->OnCheckWhitelistCompleted(code, email_); | |
| 129 break; | |
| 130 case ADD: | |
| 131 callback_->OnWhitelistCompleted(code, email_); | |
| 132 break; | |
| 133 case REMOVE: | |
| 134 callback_->OnUnwhitelistCompleted(code, email_); | |
| 135 break; | |
| 136 default: | |
| 137 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; | |
| 138 break; | |
| 139 } | |
| 140 } | |
| 141 OnOpCompleted(); | |
| 142 } | |
| 143 | |
| 144 protected: | |
| 145 // OpContext implemenetation | |
| 146 virtual void CreateOp() OVERRIDE { | |
| 147 switch (type_) { | |
| 148 case CHECK: | |
| 149 op_ = SignedSettings::CreateCheckWhitelistOp(email_, this); | |
| 150 break; | |
| 151 case ADD: | |
| 152 op_ = SignedSettings::CreateWhitelistOp(email_, true, this); | |
| 153 break; | |
| 154 case REMOVE: | |
| 155 op_ = SignedSettings::CreateWhitelistOp(email_, false, this); | |
| 156 break; | |
| 157 default: | |
| 158 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; | |
| 159 break; | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 private: | |
| 164 Type type_; | |
| 165 std::string email_; | |
| 166 | |
| 167 DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); | |
| 168 }; | |
| 169 | |
| 170 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, | 104 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, |
| 171 public OpContext { | 105 public OpContext { |
| 172 public: | 106 public: |
| 173 StorePropertyOpContext(const std::string& name, | 107 StorePropertyOpContext(const std::string& name, |
| 174 const base::Value& value, | 108 const base::Value& value, |
| 175 SignedSettingsHelper::Callback* callback, | 109 SignedSettingsHelper::Callback* callback, |
| 176 OpContext::Delegate* delegate) | 110 OpContext::Delegate* delegate) |
| 177 : OpContext(callback, delegate), | 111 : OpContext(callback, delegate), |
| 178 name_(name), | 112 name_(name), |
| 179 value_(value.DeepCopy()) { | 113 value_(value.DeepCopy()) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 DISALLOW_COPY_AND_ASSIGN(RetrievePolicyOpContext); | 225 DISALLOW_COPY_AND_ASSIGN(RetrievePolicyOpContext); |
| 292 }; | 226 }; |
| 293 | 227 |
| 294 } // namespace | 228 } // namespace |
| 295 | 229 |
| 296 | 230 |
| 297 class SignedSettingsHelperImpl : public SignedSettingsHelper, | 231 class SignedSettingsHelperImpl : public SignedSettingsHelper, |
| 298 public OpContext::Delegate { | 232 public OpContext::Delegate { |
| 299 public: | 233 public: |
| 300 // SignedSettingsHelper implementation | 234 // SignedSettingsHelper implementation |
| 301 virtual void StartCheckWhitelistOp(const std::string& email, | |
| 302 Callback* callback) OVERRIDE; | |
| 303 virtual void StartWhitelistOp(const std::string& email, | |
| 304 bool add_to_whitelist, | |
| 305 Callback* callback) OVERRIDE; | |
| 306 virtual void StartStorePropertyOp(const std::string& name, | 235 virtual void StartStorePropertyOp(const std::string& name, |
| 307 const base::Value& value, | 236 const base::Value& value, |
| 308 Callback* callback) OVERRIDE; | 237 Callback* callback) OVERRIDE; |
| 309 virtual void StartRetrieveProperty(const std::string& name, | 238 virtual void StartRetrieveProperty(const std::string& name, |
| 310 Callback* callback) OVERRIDE; | 239 Callback* callback) OVERRIDE; |
| 311 virtual void StartStorePolicyOp(const em::PolicyFetchResponse& policy, | 240 virtual void StartStorePolicyOp(const em::PolicyFetchResponse& policy, |
| 312 Callback* callback) OVERRIDE; | 241 Callback* callback) OVERRIDE; |
| 313 virtual void StartRetrievePolicyOp(Callback* callback) OVERRIDE; | 242 virtual void StartRetrievePolicyOp(Callback* callback) OVERRIDE; |
| 314 virtual void CancelCallback(Callback* callback) OVERRIDE; | 243 virtual void CancelCallback(Callback* callback) OVERRIDE; |
| 315 | 244 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 338 } | 267 } |
| 339 | 268 |
| 340 SignedSettingsHelperImpl::~SignedSettingsHelperImpl() { | 269 SignedSettingsHelperImpl::~SignedSettingsHelperImpl() { |
| 341 if (!pending_contexts_.empty()) { | 270 if (!pending_contexts_.empty()) { |
| 342 LOG(WARNING) << "SignedSettingsHelperImpl shutdown with pending ops, " | 271 LOG(WARNING) << "SignedSettingsHelperImpl shutdown with pending ops, " |
| 343 << "changes will be lost."; | 272 << "changes will be lost."; |
| 344 ClearAll(); | 273 ClearAll(); |
| 345 } | 274 } |
| 346 } | 275 } |
| 347 | 276 |
| 348 void SignedSettingsHelperImpl::StartCheckWhitelistOp( | |
| 349 const std::string&email, | |
| 350 SignedSettingsHelper::Callback* callback) { | |
| 351 AddOpContext(new WhitelistOpContext( | |
| 352 WhitelistOpContext::CHECK, | |
| 353 email, | |
| 354 callback, | |
| 355 this)); | |
| 356 } | |
| 357 | |
| 358 void SignedSettingsHelperImpl::StartWhitelistOp( | |
| 359 const std::string&email, | |
| 360 bool add_to_whitelist, | |
| 361 SignedSettingsHelper::Callback* callback) { | |
| 362 AddOpContext(new WhitelistOpContext( | |
| 363 add_to_whitelist ? WhitelistOpContext::ADD : WhitelistOpContext::REMOVE, | |
| 364 email, | |
| 365 callback, | |
| 366 this)); | |
| 367 } | |
| 368 | |
| 369 void SignedSettingsHelperImpl::StartStorePropertyOp( | 277 void SignedSettingsHelperImpl::StartStorePropertyOp( |
| 370 const std::string& name, | 278 const std::string& name, |
| 371 const base::Value& value, | 279 const base::Value& value, |
| 372 SignedSettingsHelper::Callback* callback) { | 280 SignedSettingsHelper::Callback* callback) { |
| 373 AddOpContext(new StorePropertyOpContext( | 281 AddOpContext(new StorePropertyOpContext( |
| 374 name, | 282 name, |
| 375 value, | 283 value, |
| 376 callback, | 284 callback, |
| 377 this)); | 285 this)); |
| 378 } | 286 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 355 |
| 448 if (test_delegate_) | 356 if (test_delegate_) |
| 449 test_delegate_->OnOpCompleted(context->op()); | 357 test_delegate_->OnOpCompleted(context->op()); |
| 450 } | 358 } |
| 451 | 359 |
| 452 SignedSettingsHelper* SignedSettingsHelper::Get() { | 360 SignedSettingsHelper* SignedSettingsHelper::Get() { |
| 453 return g_signed_settings_helper_impl.Pointer(); | 361 return g_signed_settings_helper_impl.Pointer(); |
| 454 } | 362 } |
| 455 | 363 |
| 456 } // namespace chromeos | 364 } // namespace chromeos |
| OLD | NEW |