Chromium Code Reviews| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 validator->policy().Pass(), | 122 validator->policy().Pass(), |
| 121 base::Bind(&DeviceCloudPolicyStoreChromeOS::OnPolicyStored, | 123 base::Bind(&DeviceCloudPolicyStoreChromeOS::OnPolicyStored, |
| 122 weak_factory_.GetWeakPtr())); | 124 weak_factory_.GetWeakPtr())); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void DeviceCloudPolicyStoreChromeOS::OnPolicyStored() { | 127 void DeviceCloudPolicyStoreChromeOS::OnPolicyStored() { |
| 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()) { |
|
Mattias Nissler (ping if slow)
2014/05/26 07:54:11
It would make sense to change the reporting code t
Thiemo Nagel
2014/05/26 10:53:55
That's going to be subject of a separate CL.
| |
| 131 status_ = STATUS_BAD_STATE; | 133 status_ = STATUS_BAD_STATE; |
| 132 NotifyStoreError(); | 134 NotifyStoreError(); |
| 133 return; | 135 return; |
| 134 } | 136 } |
| 135 | 137 |
| 136 switch (device_settings_service_->status()) { | 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(); | |
|
Mattias Nissler (ping if slow)
2014/05/26 07:54:11
nit: equals sign goes on previous line.
Thiemo Nagel
2014/05/26 10:53:55
Done.
| |
| 142 if (!uma_done_ && | |
| 143 status != chromeos::DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR) { | |
| 144 uma_done_ = true; | |
| 145 int uma_status = static_cast<int>(status); | |
| 146 if (status == chromeos::DeviceSettingsService::STORE_SUCCESS && | |
| 147 !device_settings_service_->policy_data()->has_request_token()) | |
|
Mattias Nissler (ping if slow)
2014/05/26 07:54:11
You're dereferencing policy_data() here without ch
Thiemo Nagel
2014/05/26 10:53:55
Thanks. I've added a check. (I'd like to keep th
| |
| 148 uma_status = 7; // Success but has no DM token. | |
|
Mattias Nissler (ping if slow)
2014/05/26 07:54:11
This is dangerous, as whatever changes we make to
Thiemo Nagel
2014/05/26 10:53:55
I've simplified the CL so that this doesn't apply
| |
| 149 UMA_HISTOGRAM_SPARSE_SLOWLY("Enterprise.EnrolledPolicyLoad", uma_status); | |
| 150 } | |
| 151 | |
| 152 switch (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(), |
| 146 &new_policy_map, install_attributes_); | 162 &new_policy_map, install_attributes_); |
| (...skipping 15 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 |