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/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" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "chrome/browser/policy/enterprise_metrics.h" | 14 #include "chrome/browser/policy/enterprise_metrics.h" |
15 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
16 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 16 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
17 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 17 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
18 #include "chrome/browser/policy/proto/old_generic_format.pb.h" | 18 #include "chrome/browser/policy/proto/old_generic_format.pb.h" |
19 | 19 |
20 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
21 | 21 |
22 namespace policy { | 22 namespace policy { |
23 | 23 |
24 // Decodes a CloudPolicySettings object into a PolicyMap. All the policies will | 24 // Decodes a CloudPolicySettings object into a PolicyMap. All the policies will |
25 // be POLICY_SCOPE_USER. The PolicyLevel is decoded from the protobuf. | 25 // be POLICY_SCOPE_USER. The PolicyLevel is decoded from the protobuf. |
26 // The implementation is generated code in policy/cloud_policy_generated.cc. | 26 // The implementation is generated code in policy/cloud_policy_generated.cc. |
27 void DecodePolicy(const em::CloudPolicySettings& policy, PolicyMap* map); | 27 void DecodePolicy(const em::CloudPolicySettings& policy, PolicyMap* map); |
28 | 28 |
29 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path, | 29 UserPolicyCache::UserPolicyCache(const FilePath& backing_file_path, |
30 bool wait_for_policy_fetch) | 30 bool wait_for_policy_fetch, |
31 const base::Closure& callback) | |
31 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 32 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
32 disk_cache_ready_(false), | 33 disk_cache_ready_(false), |
33 fetch_ready_(!wait_for_policy_fetch) { | 34 fetch_ready_(!wait_for_policy_fetch), |
35 ready_callback_(callback) { | |
34 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(), | 36 disk_cache_ = new UserPolicyDiskCache(weak_ptr_factory_.GetWeakPtr(), |
35 backing_file_path); | 37 backing_file_path); |
36 } | 38 } |
37 | 39 |
38 UserPolicyCache::~UserPolicyCache() { | 40 UserPolicyCache::~UserPolicyCache() { |
39 } | 41 } |
40 | 42 |
41 void UserPolicyCache::Load() { | 43 void UserPolicyCache::Load() { |
42 disk_cache_->Load(); | 44 disk_cache_->Load(); |
43 } | 45 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 if (!policy.ParseFromString(policy_data.policy_value())) { | 112 if (!policy.ParseFromString(policy_data.policy_value())) { |
111 LOG(WARNING) << "Failed to parse CloudPolicySettings protobuf."; | 113 LOG(WARNING) << "Failed to parse CloudPolicySettings protobuf."; |
112 return false; | 114 return false; |
113 } | 115 } |
114 DecodePolicy(policy, policies); | 116 DecodePolicy(policy, policies); |
115 MaybeDecodeOldstylePolicy(policy_data.policy_value(), policies); | 117 MaybeDecodeOldstylePolicy(policy_data.policy_value(), policies); |
116 return true; | 118 return true; |
117 } | 119 } |
118 | 120 |
119 void UserPolicyCache::CheckIfReady() { | 121 void UserPolicyCache::CheckIfReady() { |
120 if (!IsReady() && disk_cache_ready_ && fetch_ready_) | 122 if (!IsReady() && disk_cache_ready_ && fetch_ready_) { |
121 SetReady(); | 123 SetReady(); |
Mattias Nissler (ping if slow)
2012/02/16 10:24:11
Are you going to clean up all the existing ready-s
| |
124 if (!ready_callback_.is_null()) { | |
125 ready_callback_.Run(); | |
126 ready_callback_.Reset(); | |
127 } | |
128 } | |
122 } | 129 } |
123 | 130 |
124 // Everything below is only needed for supporting old-style GenericNamedValue | 131 // Everything below is only needed for supporting old-style GenericNamedValue |
125 // based policy data and can be removed once this support is no longer needed. | 132 // based policy data and can be removed once this support is no longer needed. |
126 | 133 |
127 using google::protobuf::RepeatedField; | 134 using google::protobuf::RepeatedField; |
128 using google::protobuf::RepeatedPtrField; | 135 using google::protobuf::RepeatedPtrField; |
129 | 136 |
130 void UserPolicyCache::MaybeDecodeOldstylePolicy( | 137 void UserPolicyCache::MaybeDecodeOldstylePolicy( |
131 const std::string& policy_data, | 138 const std::string& policy_data, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 return list; | 238 return list; |
232 } | 239 } |
233 default: | 240 default: |
234 NOTREACHED() << "Unhandled value type"; | 241 NOTREACHED() << "Unhandled value type"; |
235 } | 242 } |
236 | 243 |
237 return NULL; | 244 return NULL; |
238 } | 245 } |
239 | 246 |
240 } // namespace policy | 247 } // namespace policy |
OLD | NEW |