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/policy/device_policy_cache.h" | 5 #include "chrome/browser/policy/device_policy_cache.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/string_util.h" | |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/cros_settings.h" | 19 #include "chrome/browser/chromeos/cros_settings.h" |
| 19 #include "chrome/browser/chromeos/login/authenticator.h" | 20 #include "chrome/browser/chromeos/login/authenticator.h" |
| 20 #include "chrome/browser/chromeos/login/ownership_service.h" | 21 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 21 #include "chrome/browser/chromeos/login/signed_settings_helper.h" | 22 #include "chrome/browser/chromeos/login/signed_settings_helper.h" |
| 22 #include "chrome/browser/policy/app_pack_updater.h" | 23 #include "chrome/browser/policy/app_pack_updater.h" |
| 23 #include "chrome/browser/policy/cloud_policy_data_store.h" | 24 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 24 #include "chrome/browser/policy/enterprise_install_attributes.h" | 25 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| 25 #include "chrome/browser/policy/enterprise_metrics.h" | 26 #include "chrome/browser/policy/enterprise_metrics.h" |
| 26 #include "chrome/browser/policy/policy_map.h" | 27 #include "chrome/browser/policy/policy_map.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 void DevicePolicyCache::Load() { | 161 void DevicePolicyCache::Load() { |
| 161 signed_settings_helper_->StartRetrievePolicyOp( | 162 signed_settings_helper_->StartRetrievePolicyOp( |
| 162 base::Bind(&DevicePolicyCache::OnRetrievePolicyCompleted, | 163 base::Bind(&DevicePolicyCache::OnRetrievePolicyCompleted, |
| 163 weak_ptr_factory_.GetWeakPtr())); | 164 weak_ptr_factory_.GetWeakPtr())); |
| 164 } | 165 } |
| 165 | 166 |
| 166 bool DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { | 167 bool DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { |
| 167 DCHECK(IsReady()); | 168 DCHECK(IsReady()); |
| 168 | 169 |
| 169 // Make sure we have an enterprise device. | 170 // Make sure we have an enterprise device. |
| 170 std::string registration_user(install_attributes_->GetRegistrationUser()); | 171 std::string registration_domain( |
| 171 if (registration_user.empty()) { | 172 chromeos::Authenticator::ExtractDomainName( |
| 173 install_attributes_->GetRegistrationUser())); | |
|
Mattias Nissler (ping if slow)
2012/06/08 15:24:36
I though GetRegistrationUser() is meant to go away
pastarmovj
2012/06/18 14:57:27
Done.
| |
| 174 if (registration_domain.empty()) { | |
| 172 LOG(WARNING) << "Refusing to accept policy on non-enterprise device."; | 175 LOG(WARNING) << "Refusing to accept policy on non-enterprise device."; |
| 173 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, | 176 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, |
| 174 kMetricPolicyFetchNonEnterpriseDevice, | 177 kMetricPolicyFetchNonEnterpriseDevice, |
| 175 kMetricPolicySize); | 178 kMetricPolicySize); |
| 176 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 179 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 177 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 180 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 178 return false; | 181 return false; |
| 179 } | 182 } |
| 180 | 183 |
| 181 // Check the user this policy is for against the device-locked name. | 184 // Check the user this policy is for against the device-locked name. |
| 182 em::PolicyData policy_data; | 185 em::PolicyData policy_data; |
| 183 if (!policy_data.ParseFromString(policy.policy_data())) { | 186 if (!policy_data.ParseFromString(policy.policy_data())) { |
| 184 LOG(WARNING) << "Invalid policy protobuf"; | 187 LOG(WARNING) << "Invalid policy protobuf"; |
| 185 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchInvalidPolicy, | 188 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchInvalidPolicy, |
| 186 kMetricPolicySize); | 189 kMetricPolicySize); |
| 187 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 190 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 188 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 191 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 189 return false; | 192 return false; |
| 190 } | 193 } |
| 191 | 194 |
| 192 // Existing installations may not have a canonicalized version of the | 195 // Existing installations may not have a canonicalized version of the |
| 193 // registration user name in install attributes, so re-canonicalize here. | 196 // registration domain in install attributes, so lower-case the data here. |
| 194 if (chromeos::Authenticator::Canonicalize(registration_user) != | 197 if (registration_domain != |
| 195 chromeos::Authenticator::Canonicalize(policy_data.username())) { | 198 chromeos::Authenticator::ExtractDomainName(policy_data.username())) { |
| 196 LOG(WARNING) << "Refusing policy blob for " << policy_data.username() | 199 LOG(WARNING) << "Refusing policy blob for " << policy_data.username() |
| 197 << " which doesn't match " << registration_user; | 200 << " which doesn't match domain " << registration_domain; |
| 198 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchUserMismatch, | 201 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchUserMismatch, |
| 199 kMetricPolicySize); | 202 kMetricPolicySize); |
| 200 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 203 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 201 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 204 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 202 return false; | 205 return false; |
| 203 } | 206 } |
| 204 | 207 |
| 205 set_last_policy_refresh_time(base::Time::NowFromSystemTime()); | 208 set_last_policy_refresh_time(base::Time::NowFromSystemTime()); |
| 206 | 209 |
| 207 // Start a store operation. | 210 // Start a store operation. |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 } | 721 } |
| 719 policies->Set(key::kDeviceStartUpUrls, | 722 policies->Set(key::kDeviceStartUpUrls, |
| 720 POLICY_LEVEL_MANDATORY, | 723 POLICY_LEVEL_MANDATORY, |
| 721 POLICY_SCOPE_MACHINE, | 724 POLICY_SCOPE_MACHINE, |
| 722 urls); | 725 urls); |
| 723 } | 726 } |
| 724 } | 727 } |
| 725 } | 728 } |
| 726 | 729 |
| 727 } // namespace policy | 730 } // namespace policy |
| OLD | NEW |