OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/policy/user_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 new em::PolicyFetchResponse(policy)); | 190 new em::PolicyFetchResponse(policy)); |
191 EnsurePolicyKeyLoaded( | 191 EnsurePolicyKeyLoaded( |
192 base::Bind(&UserCloudPolicyStoreChromeOS::ValidatePolicyForStore, | 192 base::Bind(&UserCloudPolicyStoreChromeOS::ValidatePolicyForStore, |
193 weak_factory_.GetWeakPtr(), | 193 weak_factory_.GetWeakPtr(), |
194 base::Passed(&response))); | 194 base::Passed(&response))); |
195 } | 195 } |
196 | 196 |
197 void UserCloudPolicyStoreChromeOS::Load() { | 197 void UserCloudPolicyStoreChromeOS::Load() { |
198 // Cancel all pending requests. | 198 // Cancel all pending requests. |
199 weak_factory_.InvalidateWeakPtrs(); | 199 weak_factory_.InvalidateWeakPtrs(); |
200 session_manager_client_->RetrieveUserPolicy( | 200 session_manager_client_->RetrievePolicyForUser( |
| 201 username_, |
201 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, | 202 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, |
202 weak_factory_.GetWeakPtr())); | 203 weak_factory_.GetWeakPtr())); |
203 } | 204 } |
204 | 205 |
205 void UserCloudPolicyStoreChromeOS::ValidatePolicyForStore( | 206 void UserCloudPolicyStoreChromeOS::ValidatePolicyForStore( |
206 scoped_ptr<em::PolicyFetchResponse> policy) { | 207 scoped_ptr<em::PolicyFetchResponse> policy) { |
207 // Create and configure a validator. | 208 // Create and configure a validator. |
208 scoped_ptr<UserCloudPolicyValidator> validator = | 209 scoped_ptr<UserCloudPolicyValidator> validator = |
209 CreateValidator(policy.Pass()); | 210 CreateValidator(policy.Pass()); |
210 validator->ValidateUsername(username_); | 211 validator->ValidateUsername(username_); |
(...skipping 26 matching lines...) Expand all Loading... |
237 return; | 238 return; |
238 } | 239 } |
239 | 240 |
240 std::string policy_blob; | 241 std::string policy_blob; |
241 if (!validator->policy()->SerializeToString(&policy_blob)) { | 242 if (!validator->policy()->SerializeToString(&policy_blob)) { |
242 status_ = STATUS_SERIALIZE_ERROR; | 243 status_ = STATUS_SERIALIZE_ERROR; |
243 NotifyStoreError(); | 244 NotifyStoreError(); |
244 return; | 245 return; |
245 } | 246 } |
246 | 247 |
247 session_manager_client_->StoreUserPolicy( | 248 session_manager_client_->StorePolicyForUser( |
| 249 username_, |
248 policy_blob, | 250 policy_blob, |
| 251 validator->policy()->new_public_key(), |
249 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyStored, | 252 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyStored, |
250 weak_factory_.GetWeakPtr())); | 253 weak_factory_.GetWeakPtr())); |
251 } | 254 } |
252 | 255 |
253 void UserCloudPolicyStoreChromeOS::OnPolicyStored(bool success) { | 256 void UserCloudPolicyStoreChromeOS::OnPolicyStored(bool success) { |
254 if (!success) { | 257 if (!success) { |
255 status_ = STATUS_STORE_ERROR; | 258 status_ = STATUS_STORE_ERROR; |
256 NotifyStoreError(); | 259 NotifyStoreError(); |
257 } else { | 260 } else { |
258 // Load the policy right after storing it, to make sure it was accepted by | 261 // Load the policy right after storing it, to make sure it was accepted by |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 !sanitized_username.empty()) { | 488 !sanitized_username.empty()) { |
486 policy_key_path_ = user_policy_key_dir_.Append( | 489 policy_key_path_ = user_policy_key_dir_.Append( |
487 base::StringPrintf(kPolicyKeyFile, sanitized_username.c_str())); | 490 base::StringPrintf(kPolicyKeyFile, sanitized_username.c_str())); |
488 } else { | 491 } else { |
489 SampleValidationFailure(VALIDATION_FAILURE_DBUS); | 492 SampleValidationFailure(VALIDATION_FAILURE_DBUS); |
490 } | 493 } |
491 ReloadPolicyKey(callback); | 494 ReloadPolicyKey(callback); |
492 } | 495 } |
493 | 496 |
494 } // namespace policy | 497 } // namespace policy |
OLD | NEW |