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/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/cros_settings.h" | 18 #include "chrome/browser/chromeos/cros_settings.h" |
| 19 #include "chrome/browser/chromeos/login/ownership_service.h" | |
| 20 #include "chrome/browser/chromeos/login/signed_settings_helper.h" | |
| 21 #include "chrome/browser/policy/app_pack_updater.h" | 19 #include "chrome/browser/policy/app_pack_updater.h" |
| 22 #include "chrome/browser/policy/cloud_policy_data_store.h" | 20 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 23 #include "chrome/browser/policy/enterprise_install_attributes.h" | 21 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| 24 #include "chrome/browser/policy/enterprise_metrics.h" | 22 #include "chrome/browser/policy/enterprise_metrics.h" |
| 25 #include "chrome/browser/policy/policy_map.h" | 23 #include "chrome/browser/policy/policy_map.h" |
| 26 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 24 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
| 27 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 25 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 28 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 26 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
| 29 #include "chrome/common/net/gaia/gaia_auth_util.h" | 27 #include "chrome/common/net/gaia/gaia_auth_util.h" |
| 30 #include "chromeos/dbus/dbus_thread_manager.h" | 28 #include "chromeos/dbus/dbus_thread_manager.h" |
| 31 #include "chromeos/dbus/update_engine_client.h" | 29 #include "chromeos/dbus/update_engine_client.h" |
| 32 #include "policy/policy_constants.h" | 30 #include "policy/policy_constants.h" |
| 33 #include "third_party/cros_system_api/dbus/service_constants.h" | 31 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 34 | 32 |
| 35 using google::protobuf::RepeatedField; | 33 using google::protobuf::RepeatedField; |
| 36 using google::protobuf::RepeatedPtrField; | 34 using google::protobuf::RepeatedPtrField; |
| 37 | 35 |
| 38 namespace em = enterprise_management; | 36 namespace em = enterprise_management; |
| 39 | 37 |
| 40 namespace { | 38 namespace { |
| 41 | 39 |
| 42 // Stores policy, updates the owner key if required and reports the status | |
| 43 // through a callback. | |
| 44 class StorePolicyOperation : public chromeos::OwnerManager::KeyUpdateDelegate { | |
| 45 public: | |
| 46 typedef base::Callback<void(chromeos::SignedSettings::ReturnCode)> Callback; | |
| 47 | |
| 48 StorePolicyOperation(chromeos::SignedSettingsHelper* signed_settings_helper, | |
| 49 const em::PolicyFetchResponse& policy, | |
| 50 const Callback& callback) | |
| 51 : signed_settings_helper_(signed_settings_helper), | |
| 52 policy_(policy), | |
| 53 callback_(callback), | |
| 54 weak_ptr_factory_(this) { | |
| 55 signed_settings_helper_->StartStorePolicyOp( | |
| 56 policy, | |
| 57 base::Bind(&StorePolicyOperation::OnStorePolicyCompleted, | |
| 58 weak_ptr_factory_.GetWeakPtr())); | |
| 59 } | |
| 60 virtual ~StorePolicyOperation() { | |
| 61 } | |
| 62 | |
| 63 void OnStorePolicyCompleted(chromeos::SignedSettings::ReturnCode code) { | |
| 64 if (code != chromeos::SignedSettings::SUCCESS) { | |
| 65 callback_.Run(code); | |
| 66 delete this; | |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 if (policy_.has_new_public_key()) { | |
| 71 // The session manager has successfully done a key rotation. Replace the | |
| 72 // owner key also in chrome. | |
| 73 const std::string& new_key = policy_.new_public_key(); | |
| 74 const std::vector<uint8> new_key_data(new_key.c_str(), | |
| 75 new_key.c_str() + new_key.size()); | |
| 76 chromeos::OwnershipService::GetSharedInstance()->StartUpdateOwnerKey( | |
| 77 new_key_data, this); | |
| 78 return; | |
| 79 } else { | |
| 80 chromeos::CrosSettings::Get()->ReloadProviders(); | |
| 81 callback_.Run(chromeos::SignedSettings::SUCCESS); | |
| 82 delete this; | |
| 83 return; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 // OwnerManager::KeyUpdateDelegate implementation: | |
| 88 virtual void OnKeyUpdated() OVERRIDE { | |
| 89 chromeos::CrosSettings::Get()->ReloadProviders(); | |
| 90 callback_.Run(chromeos::SignedSettings::SUCCESS); | |
| 91 delete this; | |
| 92 } | |
| 93 | |
| 94 private: | |
| 95 | |
| 96 chromeos::SignedSettingsHelper* signed_settings_helper_; | |
| 97 em::PolicyFetchResponse policy_; | |
| 98 Callback callback_; | |
| 99 | |
| 100 base::WeakPtrFactory<StorePolicyOperation> weak_ptr_factory_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(StorePolicyOperation); | |
| 103 }; | |
| 104 | |
| 105 // Decodes a protobuf integer to an IntegerValue. The caller assumes ownership | 40 // Decodes a protobuf integer to an IntegerValue. The caller assumes ownership |
| 106 // of the return Value*. Returns NULL in case the input value is out of bounds. | 41 // of the return Value*. Returns NULL in case the input value is out of bounds. |
| 107 Value* DecodeIntegerValue(google::protobuf::int64 value) { | 42 Value* DecodeIntegerValue(google::protobuf::int64 value) { |
| 108 if (value < std::numeric_limits<int>::min() || | 43 if (value < std::numeric_limits<int>::min() || |
| 109 value > std::numeric_limits<int>::max()) { | 44 value > std::numeric_limits<int>::max()) { |
| 110 LOG(WARNING) << "Integer value " << value | 45 LOG(WARNING) << "Integer value " << value |
| 111 << " out of numeric limits, ignoring."; | 46 << " out of numeric limits, ignoring."; |
| 112 return NULL; | 47 return NULL; |
| 113 } | 48 } |
| 114 | 49 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 132 | 67 |
| 133 } // namespace | 68 } // namespace |
| 134 | 69 |
| 135 namespace policy { | 70 namespace policy { |
| 136 | 71 |
| 137 DevicePolicyCache::DevicePolicyCache( | 72 DevicePolicyCache::DevicePolicyCache( |
| 138 CloudPolicyDataStore* data_store, | 73 CloudPolicyDataStore* data_store, |
| 139 EnterpriseInstallAttributes* install_attributes) | 74 EnterpriseInstallAttributes* install_attributes) |
| 140 : data_store_(data_store), | 75 : data_store_(data_store), |
| 141 install_attributes_(install_attributes), | 76 install_attributes_(install_attributes), |
| 142 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), | 77 device_settings_service_(chromeos::DeviceSettingsService::Get()), |
| 143 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 78 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 144 policy_fetch_pending_(false) { | 79 policy_fetch_pending_(false) { |
| 80 device_settings_service_->AddObserver(this); | |
| 145 } | 81 } |
| 146 | 82 |
| 147 DevicePolicyCache::DevicePolicyCache( | 83 DevicePolicyCache::DevicePolicyCache( |
| 148 CloudPolicyDataStore* data_store, | 84 CloudPolicyDataStore* data_store, |
| 149 EnterpriseInstallAttributes* install_attributes, | 85 EnterpriseInstallAttributes* install_attributes, |
| 150 chromeos::SignedSettingsHelper* signed_settings_helper) | 86 chromeos::DeviceSettingsService* device_settings_service) |
| 151 : data_store_(data_store), | 87 : data_store_(data_store), |
| 152 install_attributes_(install_attributes), | 88 install_attributes_(install_attributes), |
| 153 signed_settings_helper_(signed_settings_helper), | 89 device_settings_service_(device_settings_service), |
| 154 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 90 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 155 policy_fetch_pending_(false) { | 91 policy_fetch_pending_(false) { |
| 92 device_settings_service_->AddObserver(this); | |
| 156 } | 93 } |
| 157 | 94 |
| 158 DevicePolicyCache::~DevicePolicyCache() { | 95 DevicePolicyCache::~DevicePolicyCache() { |
| 96 device_settings_service_->RemoveObserver(this); | |
| 159 } | 97 } |
| 160 | 98 |
| 161 void DevicePolicyCache::Load() { | 99 void DevicePolicyCache::Load() { |
| 162 signed_settings_helper_->StartRetrievePolicyOp( | 100 DeviceSettingsUpdated(); |
| 163 base::Bind(&DevicePolicyCache::OnRetrievePolicyCompleted, | |
| 164 weak_ptr_factory_.GetWeakPtr())); | |
| 165 } | 101 } |
| 166 | 102 |
| 167 bool DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { | 103 bool DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { |
| 168 DCHECK(IsReady()); | 104 DCHECK(IsReady()); |
| 169 | 105 |
| 170 // Make sure we have an enterprise device. | 106 // Make sure we have an enterprise device. |
| 171 std::string registration_domain(install_attributes_->GetDomain()); | 107 std::string registration_domain(install_attributes_->GetDomain()); |
| 172 if (registration_domain.empty()) { | 108 if (registration_domain.empty()) { |
| 173 LOG(WARNING) << "Refusing to accept policy on non-enterprise device."; | 109 LOG(WARNING) << "Refusing to accept policy on non-enterprise device."; |
| 174 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, | 110 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 198 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchUserMismatch, | 134 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchUserMismatch, |
| 199 kMetricPolicySize); | 135 kMetricPolicySize); |
| 200 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 136 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 201 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 137 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 202 return false; | 138 return false; |
| 203 } | 139 } |
| 204 | 140 |
| 205 set_last_policy_refresh_time(base::Time::NowFromSystemTime()); | 141 set_last_policy_refresh_time(base::Time::NowFromSystemTime()); |
| 206 | 142 |
| 207 // Start a store operation. | 143 // Start a store operation. |
| 208 StorePolicyOperation::Callback callback = | 144 policy_fetch_pending_ = true; |
| 145 device_settings_service_->Store( | |
| 146 policy.SerializeAsString(), | |
| 209 base::Bind(&DevicePolicyCache::PolicyStoreOpCompleted, | 147 base::Bind(&DevicePolicyCache::PolicyStoreOpCompleted, |
| 210 weak_ptr_factory_.GetWeakPtr()); | 148 weak_ptr_factory_.GetWeakPtr())); |
| 211 new StorePolicyOperation(signed_settings_helper_, policy, callback); | |
| 212 policy_fetch_pending_ = true; | |
| 213 return true; | 149 return true; |
| 214 } | 150 } |
| 215 | 151 |
| 216 void DevicePolicyCache::SetUnmanaged() { | 152 void DevicePolicyCache::SetUnmanaged() { |
| 217 LOG(WARNING) << "Tried to set DevicePolicyCache to 'unmanaged'!"; | 153 LOG(WARNING) << "Tried to set DevicePolicyCache to 'unmanaged'!"; |
| 218 // This is not supported for DevicePolicyCache. | 154 // This is not supported for DevicePolicyCache. |
| 219 } | 155 } |
| 220 | 156 |
| 221 void DevicePolicyCache::SetFetchingDone() { | 157 void DevicePolicyCache::SetFetchingDone() { |
| 222 // Don't send the notification just yet if there is a pending policy | 158 // Don't send the notification just yet if there is a pending policy |
| 223 // store/reload cycle. | 159 // store/reload cycle. |
| 224 if (!policy_fetch_pending_) | 160 if (!policy_fetch_pending_) |
| 225 CloudPolicyCacheBase::SetFetchingDone(); | 161 CloudPolicyCacheBase::SetFetchingDone(); |
| 226 } | 162 } |
| 227 | 163 |
| 228 void DevicePolicyCache::OnRetrievePolicyCompleted( | 164 void DevicePolicyCache::OwnershipStatusChanged() {} |
| 229 chromeos::SignedSettings::ReturnCode code, | 165 |
| 230 const em::PolicyFetchResponse& policy) { | 166 void DevicePolicyCache::DeviceSettingsUpdated() { |
| 231 DCHECK(CalledOnValidThread()); | 167 DCHECK(CalledOnValidThread()); |
| 168 chromeos::DeviceSettingsService::Status status = | |
| 169 device_settings_service_->status(); | |
| 170 const em::PolicyData* policy_data = device_settings_service_->policy_data(); | |
| 171 if (status == chromeos::DeviceSettingsService::STORE_SUCCESS && | |
| 172 !policy_data) { | |
| 173 // Initial policy load is still pending. | |
| 174 return; | |
| 175 } | |
| 176 | |
| 232 if (!IsReady()) { | 177 if (!IsReady()) { |
| 233 std::string device_token; | 178 std::string device_token; |
| 234 InstallInitialPolicy(code, policy, &device_token); | 179 InstallInitialPolicy(status, policy_data, &device_token); |
| 235 SetTokenAndFlagReady(device_token); | 180 SetTokenAndFlagReady(device_token); |
| 236 } else { // In other words, IsReady() == true | 181 } else { // In other words, IsReady() == true |
| 237 if (code != chromeos::SignedSettings::SUCCESS) { | 182 if (status != chromeos::DeviceSettingsService::STORE_SUCCESS || |
| 238 if (code == chromeos::SignedSettings::BAD_SIGNATURE) { | 183 !policy_data) { |
| 184 if (status == chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR) { | |
| 239 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadSignature, | 185 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadSignature, |
| 240 kMetricPolicySize); | 186 kMetricPolicySize); |
| 241 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 187 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 242 CloudPolicySubsystem::SIGNATURE_MISMATCH); | 188 CloudPolicySubsystem::SIGNATURE_MISMATCH); |
| 243 } else { | 189 } else { |
| 244 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOtherFailed, | 190 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOtherFailed, |
| 245 kMetricPolicySize); | 191 kMetricPolicySize); |
| 246 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 192 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 247 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 193 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 248 } | 194 } |
| 249 } else { | 195 } else { |
| 250 bool ok = SetPolicyInternal(policy, NULL, false); | 196 em::PolicyFetchResponse policy_response; |
| 197 CHECK(policy_data->SerializeToString( | |
| 198 policy_response.mutable_policy_data())); | |
| 199 bool ok = SetPolicyInternal(policy_response, NULL, false); | |
| 251 if (ok) { | 200 if (ok) { |
| 252 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOK, | 201 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOK, |
| 253 kMetricPolicySize); | 202 kMetricPolicySize); |
| 254 } | 203 } |
| 255 } | 204 } |
| 256 } | 205 } |
| 257 CheckFetchingDone(); | |
| 258 } | 206 } |
| 259 | 207 |
| 260 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data, | 208 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data, |
| 261 PolicyMap* policies) { | 209 PolicyMap* policies) { |
| 262 em::ChromeDeviceSettingsProto policy; | 210 em::ChromeDeviceSettingsProto policy; |
| 263 if (!policy.ParseFromString(policy_data.policy_value())) { | 211 if (!policy.ParseFromString(policy_data.policy_value())) { |
| 264 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto."; | 212 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto."; |
| 265 return false; | 213 return false; |
| 266 } | 214 } |
| 267 DecodeDevicePolicy(policy, policies); | 215 DecodeDevicePolicy(policy, policies); |
| 268 return true; | 216 return true; |
| 269 } | 217 } |
| 270 | 218 |
| 271 void DevicePolicyCache::PolicyStoreOpCompleted( | 219 void DevicePolicyCache::PolicyStoreOpCompleted() { |
| 272 chromeos::SignedSettings::ReturnCode code) { | |
| 273 DCHECK(CalledOnValidThread()); | 220 DCHECK(CalledOnValidThread()); |
| 274 if (code != chromeos::SignedSettings::SUCCESS) { | 221 chromeos::DeviceSettingsService::Status status = |
| 222 device_settings_service_->status(); | |
| 223 if (status != chromeos::DeviceSettingsService::STORE_SUCCESS) { | |
| 275 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreFailed, | 224 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreFailed, |
| 276 kMetricPolicySize); | 225 kMetricPolicySize); |
| 277 if (code == chromeos::SignedSettings::BAD_SIGNATURE) { | 226 if (status == chromeos::DeviceSettingsService::STORE_VALIDATION_ERROR) { |
| 278 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadSignature, | 227 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadSignature, |
| 279 kMetricPolicySize); | 228 kMetricPolicySize); |
| 280 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 229 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 281 CloudPolicySubsystem::SIGNATURE_MISMATCH); | 230 CloudPolicySubsystem::SIGNATURE_MISMATCH); |
| 282 } else { | 231 } else { |
| 283 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOtherFailed, | 232 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchOtherFailed, |
| 284 kMetricPolicySize); | 233 kMetricPolicySize); |
| 285 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 234 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 286 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 235 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 287 } | 236 } |
| 288 CheckFetchingDone(); | 237 CheckFetchingDone(); |
| 289 return; | 238 return; |
| 290 } | 239 } |
| 291 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreSucceeded, | 240 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyStoreSucceeded, |
| 292 kMetricPolicySize); | 241 kMetricPolicySize); |
| 293 signed_settings_helper_->StartRetrievePolicyOp( | 242 |
| 294 base::Bind(&DevicePolicyCache::OnRetrievePolicyCompleted, | 243 CheckFetchingDone(); |
| 295 weak_ptr_factory_.GetWeakPtr())); | |
| 296 } | 244 } |
| 297 | 245 |
| 298 void DevicePolicyCache::InstallInitialPolicy( | 246 void DevicePolicyCache::InstallInitialPolicy( |
| 299 chromeos::SignedSettings::ReturnCode code, | 247 chromeos::DeviceSettingsService::Status status, |
| 300 const em::PolicyFetchResponse& policy, | 248 const em::PolicyData* policy_data, |
| 301 std::string* device_token) { | 249 std::string* device_token) { |
| 302 if (code == chromeos::SignedSettings::NOT_FOUND || | 250 if (status == chromeos::DeviceSettingsService::STORE_NO_POLICY || |
| 303 code == chromeos::SignedSettings::KEY_UNAVAILABLE || | 251 status == chromeos::DeviceSettingsService::STORE_KEY_UNAVAILABLE) { |
| 304 !policy.has_policy_data()) { | |
| 305 InformNotifier(CloudPolicySubsystem::UNENROLLED, | 252 InformNotifier(CloudPolicySubsystem::UNENROLLED, |
| 306 CloudPolicySubsystem::NO_DETAILS); | 253 CloudPolicySubsystem::NO_DETAILS); |
| 307 return; | 254 return; |
| 308 } | 255 } |
| 309 em::PolicyData policy_data; | 256 if (!policy_data) { |
| 310 if (!policy_data.ParseFromString(policy.policy_data())) { | |
| 311 LOG(WARNING) << "Failed to parse PolicyData protobuf."; | 257 LOG(WARNING) << "Failed to parse PolicyData protobuf."; |
| 312 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed, | 258 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed, |
| 313 kMetricPolicySize); | 259 kMetricPolicySize); |
| 314 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 260 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 315 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 261 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 316 return; | 262 return; |
| 317 } | 263 } |
| 318 if (!policy_data.has_request_token() || | 264 if (!policy_data->has_request_token() || |
| 319 policy_data.request_token().empty()) { | 265 policy_data->request_token().empty()) { |
| 320 SetUnmanagedInternal(base::Time::NowFromSystemTime()); | 266 SetUnmanagedInternal(base::Time::NowFromSystemTime()); |
| 321 InformNotifier(CloudPolicySubsystem::UNMANAGED, | 267 InformNotifier(CloudPolicySubsystem::UNMANAGED, |
| 322 CloudPolicySubsystem::NO_DETAILS); | 268 CloudPolicySubsystem::NO_DETAILS); |
| 323 // TODO(jkummerow): Reminder: When we want to feed device-wide settings | 269 // TODO(jkummerow): Reminder: When we want to feed device-wide settings |
| 324 // made by a local owner into this cache, we need to call | 270 // made by a local owner into this cache, we need to call |
| 325 // SetPolicyInternal() here. | 271 // SetPolicyInternal() here. |
| 326 return; | 272 return; |
| 327 } | 273 } |
| 328 if (!policy_data.has_username() || !policy_data.has_device_id()) { | 274 if (!policy_data->has_username() || !policy_data->has_device_id()) { |
| 329 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed, | 275 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadFailed, |
| 330 kMetricPolicySize); | 276 kMetricPolicySize); |
| 331 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | 277 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, |
| 332 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | 278 CloudPolicySubsystem::POLICY_LOCAL_ERROR); |
| 333 return; | 279 return; |
| 334 } | 280 } |
| 335 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadSucceeded, | 281 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadSucceeded, |
| 336 kMetricPolicySize); | 282 kMetricPolicySize); |
| 337 data_store_->set_user_name(policy_data.username()); | 283 data_store_->set_user_name(policy_data->username()); |
| 338 data_store_->set_device_id(policy_data.device_id()); | 284 data_store_->set_device_id(policy_data->device_id()); |
| 339 *device_token = policy_data.request_token(); | 285 *device_token = policy_data->request_token(); |
| 340 base::Time timestamp; | 286 base::Time timestamp; |
| 341 if (SetPolicyInternal(policy, ×tamp, true)) | 287 em::PolicyFetchResponse policy_response; |
| 288 CHECK(policy_data->SerializeToString(policy_response.mutable_policy_data())); | |
| 289 if (SetPolicyInternal(policy_response, ×tamp, true)) | |
| 342 set_last_policy_refresh_time(timestamp); | 290 set_last_policy_refresh_time(timestamp); |
| 343 } | 291 } |
| 344 | 292 |
| 345 void DevicePolicyCache::SetTokenAndFlagReady(const std::string& device_token) { | 293 void DevicePolicyCache::SetTokenAndFlagReady(const std::string& device_token) { |
| 346 // Make sure that we only start device policy fetches once device settings are | |
| 347 // available in order to ensure the first device policy fetch uploads the | |
| 348 // configured reporting bits. | |
|
pastarmovj
2012/07/30 13:55:02
Are you sure this is not needed anymore? I remembe
Mattias Nissler (ping if slow)
2012/08/02 12:01:52
The issue was that the policy stuff would start ta
| |
| 349 if (chromeos::CrosSettingsProvider::TEMPORARILY_UNTRUSTED == | |
| 350 chromeos::CrosSettings::Get()->PrepareTrustedValues( | |
| 351 base::Bind(&DevicePolicyCache::SetTokenAndFlagReady, | |
| 352 weak_ptr_factory_.GetWeakPtr(), | |
| 353 device_token))) { | |
| 354 return; | |
| 355 } | |
| 356 | |
| 357 // We need to call SetDeviceToken unconditionally to indicate the cache has | 294 // We need to call SetDeviceToken unconditionally to indicate the cache has |
| 358 // finished loading. | 295 // finished loading. |
| 359 data_store_->SetDeviceToken(device_token, true); | 296 data_store_->SetDeviceToken(device_token, true); |
| 360 SetReady(); | 297 SetReady(); |
| 361 } | 298 } |
| 362 | 299 |
| 363 void DevicePolicyCache::CheckFetchingDone() { | 300 void DevicePolicyCache::CheckFetchingDone() { |
| 364 if (policy_fetch_pending_) { | 301 if (policy_fetch_pending_) { |
| 365 CloudPolicyCacheBase::SetFetchingDone(); | 302 CloudPolicyCacheBase::SetFetchingDone(); |
| 366 policy_fetch_pending_ = false; | 303 policy_fetch_pending_ = false; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 } | 655 } |
| 719 policies->Set(key::kDeviceStartUpUrls, | 656 policies->Set(key::kDeviceStartUpUrls, |
| 720 POLICY_LEVEL_MANDATORY, | 657 POLICY_LEVEL_MANDATORY, |
| 721 POLICY_SCOPE_MACHINE, | 658 POLICY_SCOPE_MACHINE, |
| 722 urls); | 659 urls); |
| 723 } | 660 } |
| 724 } | 661 } |
| 725 } | 662 } |
| 726 | 663 |
| 727 } // namespace policy | 664 } // namespace policy |
| OLD | NEW |