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