| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cloud_policy_cache_base.h" | 5 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 12 #include "chrome/browser/policy/enterprise_metrics.h" |
| 12 #include "chrome/browser/policy/policy_notifier.h" | 13 #include "chrome/browser/policy/policy_notifier.h" |
| 13 | 14 |
| 14 namespace policy { | 15 namespace policy { |
| 15 | 16 |
| 17 namespace em = enterprise_management; |
| 18 |
| 16 // A thin ConfigurationPolicyProvider implementation sitting on top of | 19 // A thin ConfigurationPolicyProvider implementation sitting on top of |
| 17 // CloudPolicyCacheBase for hooking up with ConfigurationPolicyPrefStore. | 20 // CloudPolicyCacheBase for hooking up with ConfigurationPolicyPrefStore. |
| 18 class CloudPolicyCacheBase::CloudPolicyProvider | 21 class CloudPolicyCacheBase::CloudPolicyProvider |
| 19 : public ConfigurationPolicyProvider { | 22 : public ConfigurationPolicyProvider { |
| 20 public: | 23 public: |
| 21 CloudPolicyProvider(const PolicyDefinitionList* policy_list, | 24 CloudPolicyProvider(const PolicyDefinitionList* policy_list, |
| 22 CloudPolicyCacheBase* cache, | 25 CloudPolicyCacheBase* cache, |
| 23 CloudPolicyCacheBase::PolicyLevel level) | 26 CloudPolicyCacheBase::PolicyLevel level) |
| 24 : ConfigurationPolicyProvider(policy_list), | 27 : ConfigurationPolicyProvider(policy_list), |
| 25 cache_(cache), | 28 cache_(cache), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 bool initialization_was_not_complete = !initialization_complete_; | 94 bool initialization_was_not_complete = !initialization_complete_; |
| 92 is_unmanaged_ = false; | 95 is_unmanaged_ = false; |
| 93 PolicyMap mandatory_policy; | 96 PolicyMap mandatory_policy; |
| 94 PolicyMap recommended_policy; | 97 PolicyMap recommended_policy; |
| 95 base::Time temp_timestamp; | 98 base::Time temp_timestamp; |
| 96 PublicKeyVersion temp_public_key_version; | 99 PublicKeyVersion temp_public_key_version; |
| 97 bool ok = DecodePolicyResponse(policy, &mandatory_policy, &recommended_policy, | 100 bool ok = DecodePolicyResponse(policy, &mandatory_policy, &recommended_policy, |
| 98 &temp_timestamp, &temp_public_key_version); | 101 &temp_timestamp, &temp_public_key_version); |
| 99 if (!ok) { | 102 if (!ok) { |
| 100 LOG(WARNING) << "Decoding policy data failed."; | 103 LOG(WARNING) << "Decoding policy data failed."; |
| 104 em::LogPolicyOperation(em::kPolicyFetchInvalidPolicy); |
| 101 return false; | 105 return false; |
| 102 } | 106 } |
| 103 if (timestamp) { | 107 if (timestamp) { |
| 104 *timestamp = temp_timestamp; | 108 *timestamp = temp_timestamp; |
| 105 } | 109 } |
| 106 if (check_for_timestamp_validity && | 110 if (check_for_timestamp_validity && |
| 107 temp_timestamp > base::Time::NowFromSystemTime()) { | 111 temp_timestamp > base::Time::NowFromSystemTime()) { |
| 108 LOG(WARNING) << "Rejected policy data, file is from the future."; | 112 LOG(WARNING) << "Rejected policy data, file is from the future."; |
| 113 em::LogPolicyOperation(em::kPolicyFetchTimestampInFuture); |
| 109 return false; | 114 return false; |
| 110 } | 115 } |
| 111 public_key_version_.version = temp_public_key_version.version; | 116 public_key_version_.version = temp_public_key_version.version; |
| 112 public_key_version_.valid = temp_public_key_version.valid; | 117 public_key_version_.valid = temp_public_key_version.valid; |
| 113 | 118 |
| 114 const bool new_policy_differs = | 119 const bool new_policy_differs = |
| 115 !mandatory_policy_.Equals(mandatory_policy) || | 120 !mandatory_policy_.Equals(mandatory_policy) || |
| 116 !recommended_policy_.Equals(recommended_policy); | 121 !recommended_policy_.Equals(recommended_policy); |
| 117 mandatory_policy_.Swap(&mandatory_policy); | 122 mandatory_policy_.Swap(&mandatory_policy); |
| 118 recommended_policy_.Swap(&recommended_policy); | 123 recommended_policy_.Swap(&recommended_policy); |
| 119 initialization_complete_ = true; | 124 initialization_complete_ = true; |
| 120 | 125 |
| 126 if (!new_policy_differs) { |
| 127 em::LogPolicyOperation(em::kPolicyFetchNotModified); |
| 128 } |
| 129 |
| 121 if (new_policy_differs || initialization_was_not_complete) { | 130 if (new_policy_differs || initialization_was_not_complete) { |
| 122 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | 131 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
| 123 observer_list_, OnUpdatePolicy()); | 132 observer_list_, OnUpdatePolicy()); |
| 124 } | 133 } |
| 125 InformNotifier(CloudPolicySubsystem::SUCCESS, | 134 InformNotifier(CloudPolicySubsystem::SUCCESS, |
| 126 CloudPolicySubsystem::NO_DETAILS); | 135 CloudPolicySubsystem::NO_DETAILS); |
| 127 return true; | 136 return true; |
| 128 } | 137 } |
| 129 | 138 |
| 130 void CloudPolicyCacheBase::SetUnmanagedInternal(const base::Time& timestamp) { | 139 void CloudPolicyCacheBase::SetUnmanagedInternal(const base::Time& timestamp) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 void CloudPolicyCacheBase::InformNotifier( | 187 void CloudPolicyCacheBase::InformNotifier( |
| 179 CloudPolicySubsystem::PolicySubsystemState state, | 188 CloudPolicySubsystem::PolicySubsystemState state, |
| 180 CloudPolicySubsystem::ErrorDetails error_details) { | 189 CloudPolicySubsystem::ErrorDetails error_details) { |
| 181 // TODO(jkummerow): To obsolete this NULL-check, make all uses of | 190 // TODO(jkummerow): To obsolete this NULL-check, make all uses of |
| 182 // UserPolicyCache explicitly set a notifier using |set_policy_notifier()|. | 191 // UserPolicyCache explicitly set a notifier using |set_policy_notifier()|. |
| 183 if (notifier_) | 192 if (notifier_) |
| 184 notifier_->Inform(state, error_details, PolicyNotifier::POLICY_CACHE); | 193 notifier_->Inform(state, error_details, PolicyNotifier::POLICY_CACHE); |
| 185 } | 194 } |
| 186 | 195 |
| 187 } // namespace policy | 196 } // namespace policy |
| OLD | NEW |