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