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/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 if (code != SignedSettings::SUCCESS) |
| 125 value = false; // Should be true already, but just to be sure. | |
|
Denis Lagno
2010/12/09 11:54:12
for my eye comment disagrees with the code
Chris Masone
2010/12/09 16:33:42
again, you are right!
| |
| 126 callback_->OnCheckWhitelistCompleted(code, value, email_); | |
| 129 break; | 127 break; |
| 130 case ADD: | 128 case ADD: |
| 131 callback_->OnWhitelistCompleted(value, email_); | 129 callback_->OnWhitelistCompleted(code, email_); |
| 132 break; | 130 break; |
| 133 case REMOVE: | 131 case REMOVE: |
| 134 callback_->OnUnwhitelistCompleted(value, email_); | 132 callback_->OnUnwhitelistCompleted(code, email_); |
| 135 break; | 133 break; |
| 136 default: | 134 default: |
| 137 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; | 135 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; |
| 138 break; | 136 break; |
| 139 } | 137 } |
| 140 } | 138 } |
| 141 | |
| 142 OnOpCompleted(); | 139 OnOpCompleted(); |
| 143 } | 140 } |
| 144 | 141 |
| 145 virtual void OnSettingsOpFailed(SignedSettings::FailureCode code) { | |
| 146 OnOpFailed(); | |
| 147 } | |
| 148 | |
| 149 protected: | 142 protected: |
| 150 // OpContext implemenetation | 143 // OpContext implemenetation |
| 151 virtual void CreateOp() { | 144 virtual void CreateOp() { |
| 152 switch (type_) { | 145 switch (type_) { |
| 153 case CHECK: | 146 case CHECK: |
| 154 op_ = SignedSettings::CreateCheckWhitelistOp(email_, this); | 147 op_ = SignedSettings::CreateCheckWhitelistOp(email_, this); |
| 155 break; | 148 break; |
| 156 case ADD: | 149 case ADD: |
| 157 op_ = SignedSettings::CreateWhitelistOp(email_, true, this); | 150 op_ = SignedSettings::CreateWhitelistOp(email_, true, this); |
| 158 break; | 151 break; |
| 159 case REMOVE: | 152 case REMOVE: |
| 160 op_ = SignedSettings::CreateWhitelistOp(email_, false, this); | 153 op_ = SignedSettings::CreateWhitelistOp(email_, false, this); |
| 161 break; | 154 break; |
| 162 default: | 155 default: |
| 163 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; | 156 LOG(ERROR) << "Unknown WhitelistOpContext type " << type_; |
| 164 break; | 157 break; |
| 165 } | 158 } |
| 166 } | 159 } |
| 167 | 160 |
| 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: | 161 private: |
| 190 Type type_; | 162 Type type_; |
| 191 std::string email_; | 163 std::string email_; |
| 192 | 164 |
| 193 DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); | 165 DISALLOW_COPY_AND_ASSIGN(WhitelistOpContext); |
| 194 }; | 166 }; |
| 195 | 167 |
| 196 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, | 168 class StorePropertyOpContext : public SignedSettings::Delegate<bool>, |
| 197 public OpContext { | 169 public OpContext { |
| 198 public: | 170 public: |
| 199 StorePropertyOpContext(const std::string& name, | 171 StorePropertyOpContext(const std::string& name, |
| 200 const std::string& value, | 172 const std::string& value, |
| 201 SignedSettingsHelper::Callback* callback, | 173 SignedSettingsHelper::Callback* callback, |
| 202 Delegate* delegate) | 174 Delegate* delegate) |
| 203 : OpContext(callback, delegate), | 175 : OpContext(callback, delegate), |
| 204 name_(name), | 176 name_(name), |
| 205 value_(value) { | 177 value_(value) { |
| 206 } | 178 } |
| 207 | 179 |
| 208 // chromeos::SignedSettings::Delegate implementation | 180 // chromeos::SignedSettings::Delegate implementation |
| 209 virtual void OnSettingsOpSucceeded(bool value) { | 181 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
| 182 bool unused) { | |
| 210 if (callback_) | 183 if (callback_) |
| 211 callback_->OnStorePropertyCompleted(true, name_, value_); | 184 callback_->OnStorePropertyCompleted(code, name_, value_); |
| 212 OnOpCompleted(); | 185 OnOpCompleted(); |
| 213 } | 186 } |
| 214 | 187 |
| 215 virtual void OnSettingsOpFailed(SignedSettings::FailureCode code) { | |
| 216 OnOpFailed(); | |
| 217 } | |
| 218 | |
| 219 protected: | 188 protected: |
| 220 // OpContext implemenetation | 189 // OpContext implemenetation |
| 221 virtual void CreateOp() { | 190 virtual void CreateOp() { |
| 222 op_ = SignedSettings::CreateStorePropertyOp(name_, value_, this); | 191 op_ = SignedSettings::CreateStorePropertyOp(name_, value_, this); |
| 223 } | 192 } |
| 224 | 193 |
| 225 virtual void OnOpFailed() { | |
| 226 if (callback_) | |
| 227 callback_->OnStorePropertyCompleted(false, name_, value_); | |
| 228 OnOpCompleted(); | |
| 229 } | |
| 230 | |
| 231 private: | 194 private: |
| 232 std::string name_; | 195 std::string name_; |
| 233 std::string value_; | 196 std::string value_; |
| 234 | 197 |
| 235 DISALLOW_COPY_AND_ASSIGN(StorePropertyOpContext); | 198 DISALLOW_COPY_AND_ASSIGN(StorePropertyOpContext); |
| 236 }; | 199 }; |
| 237 | 200 |
| 238 class RetrievePropertyOpContext | 201 class RetrievePropertyOpContext |
| 239 : public SignedSettings::Delegate<std::string>, | 202 : public SignedSettings::Delegate<std::string>, |
| 240 public OpContext { | 203 public OpContext { |
| 241 public: | 204 public: |
| 242 RetrievePropertyOpContext(const std::string& name, | 205 RetrievePropertyOpContext(const std::string& name, |
| 243 SignedSettingsHelper::Callback* callback, | 206 SignedSettingsHelper::Callback* callback, |
| 244 Delegate* delegate) | 207 Delegate* delegate) |
| 245 : OpContext(callback, delegate), | 208 : OpContext(callback, delegate), |
| 246 name_(name) { | 209 name_(name) { |
| 247 } | 210 } |
| 248 | 211 |
| 249 // chromeos::SignedSettings::Delegate implementation | 212 // chromeos::SignedSettings::Delegate implementation |
| 250 virtual void OnSettingsOpSucceeded(std::string value) { | 213 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
| 214 std::string value) { | |
| 251 if (callback_) | 215 if (callback_) |
| 252 callback_->OnRetrievePropertyCompleted(true, name_, value); | 216 callback_->OnRetrievePropertyCompleted(code, name_, value); |
| 253 | 217 |
| 254 OnOpCompleted(); | 218 OnOpCompleted(); |
| 255 } | 219 } |
| 256 | 220 |
| 257 virtual void OnSettingsOpFailed(SignedSettings::FailureCode code) { | |
| 258 OnOpFailed(); | |
| 259 } | |
| 260 | |
| 261 protected: | 221 protected: |
| 262 // OpContext implemenetation | 222 // OpContext implemenetation |
| 263 virtual void CreateOp() { | 223 virtual void CreateOp() { |
| 264 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); | 224 op_ = SignedSettings::CreateRetrievePropertyOp(name_, this); |
| 265 } | 225 } |
| 266 | 226 |
| 267 virtual void OnOpFailed() { | |
| 268 if (callback_) | |
| 269 callback_->OnRetrievePropertyCompleted(false, name_, std::string()); | |
| 270 OnOpCompleted(); | |
| 271 } | |
| 272 | |
| 273 private: | 227 private: |
| 274 std::string name_; | 228 std::string name_; |
| 275 | 229 |
| 276 DISALLOW_COPY_AND_ASSIGN(RetrievePropertyOpContext); | 230 DISALLOW_COPY_AND_ASSIGN(RetrievePropertyOpContext); |
| 277 }; | 231 }; |
| 278 | 232 |
| 279 } // namespace | 233 } // namespace |
| 280 | 234 |
| 281 | 235 |
| 282 class SignedSettingsHelperImpl : public SignedSettingsHelper, | 236 class SignedSettingsHelperImpl : public SignedSettingsHelper, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 | 369 |
| 416 if (test_delegate_) | 370 if (test_delegate_) |
| 417 test_delegate_->OnOpCompleted(context->op()); | 371 test_delegate_->OnOpCompleted(context->op()); |
| 418 } | 372 } |
| 419 | 373 |
| 420 SignedSettingsHelper* SignedSettingsHelper::Get() { | 374 SignedSettingsHelper* SignedSettingsHelper::Get() { |
| 421 return Singleton<SignedSettingsHelperImpl>::get(); | 375 return Singleton<SignedSettingsHelperImpl>::get(); |
| 422 } | 376 } |
| 423 | 377 |
| 424 } // namespace chromeos | 378 } // namespace chromeos |
| OLD | NEW |