| 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/device_local_account_policy_store.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "chromeos/dbus/session_manager_client.h" | |
| 13 #include "components/ownership/owner_key_util.h" | 12 #include "components/ownership/owner_key_util.h" |
| 14 #include "components/policy/core/common/cloud/device_management_service.h" | 13 #include "components/policy/core/common/cloud/device_management_service.h" |
| 15 #include "components/policy/core/common/external_data_fetcher.h" | 14 #include "components/policy/core/common/external_data_fetcher.h" |
| 16 #include "components/policy/core/common/policy_map.h" | 15 #include "components/policy/core/common/policy_map.h" |
| 17 #include "components/policy/core/common/policy_types.h" | 16 #include "components/policy/core/common/policy_types.h" |
| 18 #include "components/policy/proto/cloud_policy.pb.h" | 17 #include "components/policy/proto/cloud_policy.pb.h" |
| 19 #include "components/policy/proto/device_management_backend.pb.h" | 18 #include "components/policy/proto/device_management_backend.pb.h" |
| 20 | 19 |
| 21 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
| 22 | 21 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 // on Chrome OS happens whenever the browser is restarted into the same | 48 // on Chrome OS happens whenever the browser is restarted into the same |
| 50 // session, that is when the browser crashes, or right after signin if | 49 // session, that is when the browser crashes, or right after signin if |
| 51 // the user has flags configured in about:flags. | 50 // the user has flags configured in about:flags. |
| 52 // However, on those paths we must load policy synchronously so that the | 51 // However, on those paths we must load policy synchronously so that the |
| 53 // Profile initialization never sees unmanaged prefs, which would lead to | 52 // Profile initialization never sees unmanaged prefs, which would lead to |
| 54 // data loss. http://crbug.com/263061 | 53 // data loss. http://crbug.com/263061 |
| 55 | 54 |
| 56 // Cancel all running async loads. | 55 // Cancel all running async loads. |
| 57 weak_factory_.InvalidateWeakPtrs(); | 56 weak_factory_.InvalidateWeakPtrs(); |
| 58 | 57 |
| 59 const std::string policy_blob = | 58 std::string policy_blob; |
| 59 chromeos::SessionManagerClient::RetrievePolicyResponseType response = |
| 60 session_manager_client_->BlockingRetrieveDeviceLocalAccountPolicy( | 60 session_manager_client_->BlockingRetrieveDeviceLocalAccountPolicy( |
| 61 account_id_); | 61 account_id_, &policy_blob); |
| 62 ValidateLoadedPolicyBlob(false /*validate_in_background*/, policy_blob); | 62 ValidateLoadedPolicyBlob(false /*validate_in_background*/, policy_blob, |
| 63 response); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void DeviceLocalAccountPolicyStore::Store( | 66 void DeviceLocalAccountPolicyStore::Store( |
| 66 const em::PolicyFetchResponse& policy) { | 67 const em::PolicyFetchResponse& policy) { |
| 67 weak_factory_.InvalidateWeakPtrs(); | 68 weak_factory_.InvalidateWeakPtrs(); |
| 68 CheckKeyAndValidate( | 69 CheckKeyAndValidate( |
| 69 true, base::MakeUnique<em::PolicyFetchResponse>(policy), | 70 true, base::MakeUnique<em::PolicyFetchResponse>(policy), |
| 70 true /*validate_in_background*/, | 71 true /*validate_in_background*/, |
| 71 base::Bind(&DeviceLocalAccountPolicyStore::StoreValidatedPolicy, | 72 base::Bind(&DeviceLocalAccountPolicyStore::StoreValidatedPolicy, |
| 72 weak_factory_.GetWeakPtr())); | 73 weak_factory_.GetWeakPtr())); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void DeviceLocalAccountPolicyStore::ValidateLoadedPolicyBlob( | 76 void DeviceLocalAccountPolicyStore::ValidateLoadedPolicyBlob( |
| 76 bool validate_in_background, | 77 bool validate_in_background, |
| 77 const std::string& policy_blob) { | 78 const std::string& policy_blob, |
| 78 if (policy_blob.empty()) { | 79 chromeos::SessionManagerClient::RetrievePolicyResponseType response_type) { |
| 80 if (response_type != |
| 81 chromeos::SessionManagerClient::RetrievePolicyResponseType::SUCCESS || |
| 82 policy_blob.empty()) { |
| 79 status_ = CloudPolicyStore::STATUS_LOAD_ERROR; | 83 status_ = CloudPolicyStore::STATUS_LOAD_ERROR; |
| 80 NotifyStoreError(); | 84 NotifyStoreError(); |
| 81 } else { | 85 } else { |
| 82 std::unique_ptr<em::PolicyFetchResponse> policy( | 86 std::unique_ptr<em::PolicyFetchResponse> policy( |
| 83 new em::PolicyFetchResponse()); | 87 new em::PolicyFetchResponse()); |
| 84 if (policy->ParseFromString(policy_blob)) { | 88 if (policy->ParseFromString(policy_blob)) { |
| 85 CheckKeyAndValidate( | 89 CheckKeyAndValidate( |
| 86 false, std::move(policy), validate_in_background, | 90 false, std::move(policy), validate_in_background, |
| 87 base::Bind(&DeviceLocalAccountPolicyStore::UpdatePolicy, | 91 base::Bind(&DeviceLocalAccountPolicyStore::UpdatePolicy, |
| 88 weak_factory_.GetWeakPtr())); | 92 weak_factory_.GetWeakPtr())); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 validator.release()->StartValidation( | 221 validator.release()->StartValidation( |
| 218 base::Bind(callback, key->as_string())); | 222 base::Bind(callback, key->as_string())); |
| 219 } else { | 223 } else { |
| 220 validator->RunValidation(); | 224 validator->RunValidation(); |
| 221 | 225 |
| 222 UpdatePolicy(key->as_string(), validator.get()); | 226 UpdatePolicy(key->as_string(), validator.get()); |
| 223 } | 227 } |
| 224 } | 228 } |
| 225 | 229 |
| 226 } // namespace policy | 230 } // namespace policy |
| OLD | NEW |