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