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_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/sparse_histogram.h" | |
8 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
9 #include "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h" | 10 #include "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h" |
10 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 11 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
11 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
12 #include "policy/proto/device_management_backend.pb.h" | 13 #include "policy/proto/device_management_backend.pb.h" |
13 | 14 |
14 namespace em = enterprise_management; | 15 namespace em = enterprise_management; |
15 | 16 |
16 namespace policy { | 17 namespace policy { |
17 | 18 |
18 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS( | 19 DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS( |
19 chromeos::DeviceSettingsService* device_settings_service, | 20 chromeos::DeviceSettingsService* device_settings_service, |
20 EnterpriseInstallAttributes* install_attributes, | 21 EnterpriseInstallAttributes* install_attributes, |
21 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 22 scoped_refptr<base::SequencedTaskRunner> background_task_runner) |
22 : device_settings_service_(device_settings_service), | 23 : device_settings_service_(device_settings_service), |
23 install_attributes_(install_attributes), | 24 install_attributes_(install_attributes), |
24 background_task_runner_(background_task_runner), | 25 background_task_runner_(background_task_runner), |
26 uma_done_(false), | |
25 weak_factory_(this) { | 27 weak_factory_(this) { |
26 device_settings_service_->AddObserver(this); | 28 device_settings_service_->AddObserver(this); |
27 } | 29 } |
28 | 30 |
29 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() { | 31 DeviceCloudPolicyStoreChromeOS::~DeviceCloudPolicyStoreChromeOS() { |
30 device_settings_service_->RemoveObserver(this); | 32 device_settings_service_->RemoveObserver(this); |
31 } | 33 } |
32 | 34 |
33 void DeviceCloudPolicyStoreChromeOS::Store( | 35 void DeviceCloudPolicyStoreChromeOS::Store( |
34 const em::PolicyFetchResponse& policy) { | 36 const em::PolicyFetchResponse& policy) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 UpdateFromService(); | 128 UpdateFromService(); |
127 } | 129 } |
128 | 130 |
129 void DeviceCloudPolicyStoreChromeOS::UpdateFromService() { | 131 void DeviceCloudPolicyStoreChromeOS::UpdateFromService() { |
130 if (!install_attributes_->IsEnterpriseDevice()) { | 132 if (!install_attributes_->IsEnterpriseDevice()) { |
131 status_ = STATUS_BAD_STATE; | 133 status_ = STATUS_BAD_STATE; |
132 NotifyStoreError(); | 134 NotifyStoreError(); |
133 return; | 135 return; |
134 } | 136 } |
135 | 137 |
138 // Fill UMA histogram once per session. Skip temp validation error because it | |
139 // is not a definitive result (policy load will be retried). | |
140 const chromeos::DeviceSettingsService::Status status = | |
141 device_settings_service_->status(); | |
142 if (!uma_done_ && | |
143 status != chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR) { | |
144 uma_done_ = true; | |
145 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
146 "Enterprise.EnrolledPolicyHasDMToken", | |
Alexei Svitkine (slow)
2014/05/26 17:27:11
This looks like a boolean histogram, so there's no
Thiemo Nagel
2014/05/26 17:54:30
Thanks for catching this! I had started with a mo
| |
147 status == chromeos::DeviceSettingsService::STORE_SUCCESS && | |
148 device_settings_service_->policy_data() && | |
149 !device_settings_service_->policy_data()->has_request_token()); | |
Alexei Svitkine (slow)
2014/05/26 17:27:11
Nit: Refactor this into a local bool and use that
Thiemo Nagel
2014/05/26 17:54:30
Done.
| |
150 } | |
151 | |
136 switch (device_settings_service_->status()) { | 152 switch (device_settings_service_->status()) { |
137 case chromeos::DeviceSettingsService::STORE_SUCCESS: { | 153 case chromeos::DeviceSettingsService::STORE_SUCCESS: { |
138 status_ = STATUS_OK; | 154 status_ = STATUS_OK; |
139 policy_.reset(new em::PolicyData()); | 155 policy_.reset(new em::PolicyData()); |
140 if (device_settings_service_->policy_data()) | 156 if (device_settings_service_->policy_data()) |
141 policy_->MergeFrom(*device_settings_service_->policy_data()); | 157 policy_->MergeFrom(*device_settings_service_->policy_data()); |
142 | 158 |
143 PolicyMap new_policy_map; | 159 PolicyMap new_policy_map; |
144 if (is_managed()) { | 160 if (is_managed()) { |
145 DecodeDevicePolicy(*device_settings_service_->device_settings(), | 161 DecodeDevicePolicy(*device_settings_service_->device_settings(), |
(...skipping 16 matching lines...) Expand all Loading... | |
162 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: | 178 case chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR: |
163 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: | 179 case chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR: |
164 status_ = STATUS_LOAD_ERROR; | 180 status_ = STATUS_LOAD_ERROR; |
165 break; | 181 break; |
166 } | 182 } |
167 | 183 |
168 NotifyStoreError(); | 184 NotifyStoreError(); |
169 } | 185 } |
170 | 186 |
171 } // namespace policy | 187 } // namespace policy |
OLD | NEW |