Chromium Code Reviews| 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/user_policy_cache.h" | 5 #include "chrome/browser/policy/user_policy_cache.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "policy/policy_constants.h" | 21 #include "policy/policy_constants.h" |
| 22 | 22 |
| 23 namespace policy { | 23 namespace policy { |
| 24 | 24 |
| 25 // Decodes a CloudPolicySettings object into two maps with mandatory and | 25 // Decodes a CloudPolicySettings object into two maps with mandatory and |
| 26 // recommended settings, respectively. The implementation is generated code | 26 // recommended settings, respectively. The implementation is generated code |
| 27 // in policy/cloud_policy_generated.cc. | 27 // in policy/cloud_policy_generated.cc. |
| 28 void DecodePolicy(const em::CloudPolicySettings& policy, | 28 void DecodePolicy(const em::CloudPolicySettings& policy, |
| 29 PolicyMap* mandatory, PolicyMap* recommended); | 29 PolicyMap* mandatory, PolicyMap* recommended); |
| 30 | 30 |
| 31 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path) | 31 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path, |
| 32 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 32 bool wait_for_policy_fetch) |
| 33 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | |
| 34 disk_cache_ready_(false), | |
| 35 fetch_ready_(!wait_for_policy_fetch) { | |
| 33 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(), | 36 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(), |
| 34 backing_file_path); | 37 backing_file_path); |
| 35 } | 38 } |
| 36 | 39 |
| 37 UserPolicyCache::~UserPolicyCache() { | 40 UserPolicyCache::~UserPolicyCache() { |
| 38 } | 41 } |
| 39 | 42 |
| 40 void UserPolicyCache::Load() { | 43 void UserPolicyCache::Load() { |
| 41 disk_cache_->Load(); | 44 disk_cache_->Load(); |
| 42 } | 45 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 65 void UserPolicyCache::SetUnmanaged() { | 68 void UserPolicyCache::SetUnmanaged() { |
| 66 DCHECK(CalledOnValidThread()); | 69 DCHECK(CalledOnValidThread()); |
| 67 SetUnmanagedInternal(base::Time::NowFromSystemTime()); | 70 SetUnmanagedInternal(base::Time::NowFromSystemTime()); |
| 68 | 71 |
| 69 em::CachedCloudPolicyResponse cached_policy; | 72 em::CachedCloudPolicyResponse cached_policy; |
| 70 cached_policy.set_unmanaged(true); | 73 cached_policy.set_unmanaged(true); |
| 71 cached_policy.set_timestamp(base::Time::NowFromSystemTime().ToTimeT()); | 74 cached_policy.set_timestamp(base::Time::NowFromSystemTime().ToTimeT()); |
| 72 disk_cache_->Store(cached_policy); | 75 disk_cache_->Store(cached_policy); |
| 73 } | 76 } |
| 74 | 77 |
| 78 void UserPolicyCache::SetFetchingDone() { | |
| 79 if (!fetch_ready_) | |
| 80 VLOG(1) << "SetFetchingDone, cache is now fetch_ready_"; | |
|
Mattias Nissler (ping if slow)
2011/11/11 11:41:23
all VLOGs should probably be DVLOGs per that recen
Joao da Silva
2011/11/11 12:55:14
Done.
| |
| 81 fetch_ready_ = true; | |
| 82 CheckIfReady(); | |
| 83 } | |
| 84 | |
| 75 void UserPolicyCache::OnDiskCacheLoaded( | 85 void UserPolicyCache::OnDiskCacheLoaded( |
| 76 UserPolicyDiskCache::LoadResult result, | 86 UserPolicyDiskCache::LoadResult result, |
| 77 const em::CachedCloudPolicyResponse& cached_response) { | 87 const em::CachedCloudPolicyResponse& cached_response) { |
| 78 if (IsReady()) | 88 if (IsReady()) |
| 79 return; | 89 return; |
| 80 | 90 |
| 81 if (result == UserPolicyDiskCache::LOAD_RESULT_SUCCESS) { | 91 if (result == UserPolicyDiskCache::LOAD_RESULT_SUCCESS) { |
| 82 if (cached_response.unmanaged()) { | 92 if (cached_response.unmanaged()) { |
| 83 SetUnmanagedInternal(base::Time::FromTimeT(cached_response.timestamp())); | 93 SetUnmanagedInternal(base::Time::FromTimeT(cached_response.timestamp())); |
| 84 } else if (cached_response.has_cloud_policy()) { | 94 } else if (cached_response.has_cloud_policy()) { |
| 85 base::Time timestamp; | 95 base::Time timestamp; |
| 86 if (SetPolicyInternal(cached_response.cloud_policy(), ×tamp, true)) | 96 if (SetPolicyInternal(cached_response.cloud_policy(), ×tamp, true)) |
| 87 set_last_policy_refresh_time(timestamp); | 97 set_last_policy_refresh_time(timestamp); |
| 88 } | 98 } |
| 89 } | 99 } |
| 90 | 100 |
| 91 // Ready to feed policy up the chain! | 101 // Ready to feed policy up the chain! |
| 92 SetReady(); | 102 disk_cache_ready_ = true; |
| 103 CheckIfReady(); | |
| 93 } | 104 } |
| 94 | 105 |
| 95 bool UserPolicyCache::DecodePolicyData(const em::PolicyData& policy_data, | 106 bool UserPolicyCache::DecodePolicyData(const em::PolicyData& policy_data, |
| 96 PolicyMap* mandatory, | 107 PolicyMap* mandatory, |
| 97 PolicyMap* recommended) { | 108 PolicyMap* recommended) { |
| 98 // TODO(jkummerow): Verify policy_data.device_token(). Needs final | 109 // TODO(jkummerow): Verify policy_data.device_token(). Needs final |
| 99 // specification which token we're actually sending / expecting to get back. | 110 // specification which token we're actually sending / expecting to get back. |
| 100 em::CloudPolicySettings policy; | 111 em::CloudPolicySettings policy; |
| 101 if (!policy.ParseFromString(policy_data.policy_value())) { | 112 if (!policy.ParseFromString(policy_data.policy_value())) { |
| 102 LOG(WARNING) << "Failed to parse CloudPolicySettings protobuf."; | 113 LOG(WARNING) << "Failed to parse CloudPolicySettings protobuf."; |
| 103 return false; | 114 return false; |
| 104 } | 115 } |
| 105 DecodePolicy(policy, mandatory, recommended); | 116 DecodePolicy(policy, mandatory, recommended); |
| 106 MaybeDecodeOldstylePolicy(policy_data.policy_value(), mandatory, recommended); | 117 MaybeDecodeOldstylePolicy(policy_data.policy_value(), mandatory, recommended); |
| 107 return true; | 118 return true; |
| 108 } | 119 } |
| 109 | 120 |
| 121 void UserPolicyCache::CheckIfReady() { | |
| 122 if (!IsReady() && disk_cache_ready_ && fetch_ready_) | |
| 123 SetReady(); | |
| 124 } | |
| 125 | |
| 110 // Everything below is only needed for supporting old-style GenericNamedValue | 126 // Everything below is only needed for supporting old-style GenericNamedValue |
| 111 // based policy data and can be removed once this support is no longer needed. | 127 // based policy data and can be removed once this support is no longer needed. |
| 112 | 128 |
| 113 using google::protobuf::RepeatedField; | 129 using google::protobuf::RepeatedField; |
| 114 using google::protobuf::RepeatedPtrField; | 130 using google::protobuf::RepeatedPtrField; |
| 115 | 131 |
| 116 void UserPolicyCache::MaybeDecodeOldstylePolicy( | 132 void UserPolicyCache::MaybeDecodeOldstylePolicy( |
| 117 const std::string& policy_data, | 133 const std::string& policy_data, |
| 118 PolicyMap* mandatory, | 134 PolicyMap* mandatory, |
| 119 PolicyMap* recommended) { | 135 PolicyMap* recommended) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 return list; | 234 return list; |
| 219 } | 235 } |
| 220 default: | 236 default: |
| 221 NOTREACHED() << "Unhandled value type"; | 237 NOTREACHED() << "Unhandled value type"; |
| 222 } | 238 } |
| 223 | 239 |
| 224 return NULL; | 240 return NULL; |
| 225 } | 241 } |
| 226 | 242 |
| 227 } // namespace policy | 243 } // namespace policy |
| OLD | NEW |