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 // Most of this code is copied from various classes in | 5 // Most of this code is copied from various classes in |
6 // src/chrome/browser/policy. In particular, look at | 6 // src/chrome/browser/policy. In particular, look at |
7 // | 7 // |
8 // file_based_policy_loader.{h,cc} | 8 // file_based_policy_loader.{h,cc} |
9 // config_dir_policy_provider.{h,cc} | 9 // config_dir_policy_provider.{h,cc} |
10 // | 10 // |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 JSONFileValueSerializer deserializer(*config_file_iter); | 174 JSONFileValueSerializer deserializer(*config_file_iter); |
175 int error_code = 0; | 175 int error_code = 0; |
176 std::string error_msg; | 176 std::string error_msg; |
177 scoped_ptr<Value> value( | 177 scoped_ptr<Value> value( |
178 deserializer.Deserialize(&error_code, &error_msg)); | 178 deserializer.Deserialize(&error_code, &error_msg)); |
179 if (!value.get()) { | 179 if (!value.get()) { |
180 LOG(WARNING) << "Failed to read configuration file " | 180 LOG(WARNING) << "Failed to read configuration file " |
181 << config_file_iter->value() << ": " << error_msg; | 181 << config_file_iter->value() << ": " << error_msg; |
182 continue; | 182 continue; |
183 } | 183 } |
184 if (!value->IsType(Value::TYPE_DICTIONARY)) { | 184 if (!value->IsDictionary()) { |
185 LOG(WARNING) << "Expected JSON dictionary in configuration file " | 185 LOG(WARNING) << "Expected JSON dictionary in configuration file " |
186 << config_file_iter->value(); | 186 << config_file_iter->value(); |
187 continue; | 187 continue; |
188 } | 188 } |
189 policy->MergeDictionary(static_cast<DictionaryValue*>(value.get())); | 189 policy->MergeDictionary(static_cast<DictionaryValue*>(value.get())); |
190 } | 190 } |
191 | 191 |
192 return policy; | 192 return policy; |
193 } | 193 } |
194 | 194 |
195 void Reload() { | 195 void Reload() { |
196 DCHECK(OnPolicyThread()); | 196 DCHECK(OnPolicyThread()); |
197 // Check the directory time in order to see whether a reload is required. | 197 // Check the directory time in order to see whether a reload is required. |
198 base::TimeDelta delay; | 198 base::TimeDelta delay; |
199 base::Time now = base::Time::Now(); | 199 base::Time now = base::Time::Now(); |
200 if (!IsSafeToReloadPolicy(now, &delay)) { | 200 if (!IsSafeToReloadPolicy(now, &delay)) { |
201 ScheduleReloadTask(delay); | 201 ScheduleReloadTask(delay); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
205 // Check again in case the directory has changed while reading it. | 205 // Check again in case the directory has changed while reading it. |
206 if (!IsSafeToReloadPolicy(now, &delay)) { | 206 if (!IsSafeToReloadPolicy(now, &delay)) { |
207 ScheduleReloadTask(delay); | 207 ScheduleReloadTask(delay); |
208 return; | 208 return; |
209 } | 209 } |
210 | 210 |
211 // Load the policy definitions. | 211 // Load the policy definitions. |
212 scoped_ptr<DictionaryValue> new_policy(Load()); | 212 scoped_ptr<base::DictionaryValue> new_policy(Load()); |
tony
2011/08/19 17:24:21
Why is this necessary here? There are lots of oth
tfarina
2011/08/19 18:40:47
Done.
| |
213 UpdateNatPolicy(new_policy.get()); | 213 UpdateNatPolicy(new_policy.get()); |
214 | 214 |
215 ScheduleFallbackReloadTask(); | 215 ScheduleFallbackReloadTask(); |
216 } | 216 } |
217 | 217 |
218 bool IsSafeToReloadPolicy(const base::Time& now, base::TimeDelta* delay) { | 218 bool IsSafeToReloadPolicy(const base::Time& now, base::TimeDelta* delay) { |
219 DCHECK(OnPolicyThread()); | 219 DCHECK(OnPolicyThread()); |
220 DCHECK(delay); | 220 DCHECK(delay); |
221 const base::TimeDelta kSettleInterval = | 221 const base::TimeDelta kSettleInterval = |
222 base::TimeDelta::FromSeconds(kSettleIntervalSeconds); | 222 base::TimeDelta::FromSeconds(kSettleIntervalSeconds); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 base::WeakPtrFactory<NatPolicyLinux> weak_factory_; | 266 base::WeakPtrFactory<NatPolicyLinux> weak_factory_; |
267 }; | 267 }; |
268 | 268 |
269 NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { | 269 NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { |
270 FilePath policy_dir(kPolicyDir); | 270 FilePath policy_dir(kPolicyDir); |
271 return new NatPolicyLinux(message_loop_proxy, policy_dir); | 271 return new NatPolicyLinux(message_loop_proxy, policy_dir); |
272 } | 272 } |
273 | 273 |
274 } // namespace policy_hack | 274 } // namespace policy_hack |
275 } // namespace remoting | 275 } // namespace remoting |
OLD | NEW |