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