OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/config_dir_policy_provider.h" | 5 #include "chrome/browser/policy/config_dir_policy_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/task.h" |
11 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chrome_thread.h" |
13 #include "chrome/common/json_value_serializer.h" | 16 #include "chrome/common/json_value_serializer.h" |
14 | 17 |
15 namespace { | 18 namespace { |
16 | 19 |
17 // Amount of time we wait for the files in the policy directory to settle before | 20 // Amount of time we wait for the files in the policy directory to settle before |
18 // trying to load it. This alleviates the problem of reading partially written | 21 // trying to load it. This alleviates the problem of reading partially written |
19 // files and allows to batch quasi-simultaneous changes. | 22 // files and allows to batch quasi-simultaneous changes. |
20 const int kSettleIntervalSeconds = 5; | 23 const int kSettleIntervalSeconds = 5; |
21 | 24 |
22 // The time interval for rechecking policy. This is our fallback in case the | 25 // The time interval for rechecking policy. This is our fallback in case the |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 218 } |
216 | 219 |
217 void PolicyDirWatcher::InitWatcher( | 220 void PolicyDirWatcher::InitWatcher( |
218 const scoped_refptr<PolicyDirLoader>& loader) { | 221 const scoped_refptr<PolicyDirLoader>& loader) { |
219 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { | 222 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { |
220 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, | 223 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, |
221 NewRunnableMethod(this, &PolicyDirWatcher::InitWatcher, loader)); | 224 NewRunnableMethod(this, &PolicyDirWatcher::InitWatcher, loader)); |
222 return; | 225 return; |
223 } | 226 } |
224 | 227 |
225 if (!Watch(loader->config_dir(), loader.get())) | 228 if (!watcher_.Watch(loader->config_dir(), loader.get())) |
226 loader->OnError(); | 229 loader->OnError(); |
227 | 230 |
228 // There might have been changes to the directory in the time between | 231 // There might have been changes to the directory in the time between |
229 // construction of the loader and initialization of the watcher. Call reload | 232 // construction of the loader and initialization of the watcher. Call reload |
230 // to detect if that is the case. | 233 // to detect if that is the case. |
231 loader->Reload(); | 234 loader->Reload(); |
232 } | 235 } |
233 | 236 |
234 // ConfigDirPolicyProvider implementation: | 237 // ConfigDirPolicyProvider implementation: |
235 | 238 |
(...skipping 23 matching lines...) Expand all Loading... |
259 i != mapping->end(); ++i) { | 262 i != mapping->end(); ++i) { |
260 const PolicyValueMapEntry& entry(*i); | 263 const PolicyValueMapEntry& entry(*i); |
261 Value* value; | 264 Value* value; |
262 if (policies->Get(entry.name, &value) && value->IsType(entry.value_type)) | 265 if (policies->Get(entry.name, &value) && value->IsType(entry.value_type)) |
263 store->Apply(entry.policy_type, value->DeepCopy()); | 266 store->Apply(entry.policy_type, value->DeepCopy()); |
264 } | 267 } |
265 | 268 |
266 // TODO(mnissler): Handle preference overrides once |ConfigurationPolicyStore| | 269 // TODO(mnissler): Handle preference overrides once |ConfigurationPolicyStore| |
267 // supports it. | 270 // supports it. |
268 } | 271 } |
OLD | NEW |