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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 config_dir_(config_dir), | 38 config_dir_(config_dir), |
39 reload_task_(NULL), | 39 reload_task_(NULL), |
40 settle_interval_seconds_(settle_interval_seconds), | 40 settle_interval_seconds_(settle_interval_seconds), |
41 reload_interval_minutes_(reload_interval_minutes) { | 41 reload_interval_minutes_(reload_interval_minutes) { |
42 // Force an initial load, so GetPolicy() works. | 42 // Force an initial load, so GetPolicy() works. |
43 policy_.reset(Load()); | 43 policy_.reset(Load()); |
44 DCHECK(policy_.get()); | 44 DCHECK(policy_.get()); |
45 } | 45 } |
46 | 46 |
47 void PolicyDirLoader::Stop() { | 47 void PolicyDirLoader::Stop() { |
48 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { | 48 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
49 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, | 49 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
50 NewRunnableMethod(this, &PolicyDirLoader::Stop)); | 50 NewRunnableMethod(this, &PolicyDirLoader::Stop)); |
51 return; | 51 return; |
52 } | 52 } |
53 | 53 |
54 if (reload_task_) { | 54 if (reload_task_) { |
55 reload_task_->Cancel(); | 55 reload_task_->Cancel(); |
56 reload_task_ = NULL; | 56 reload_task_ = NULL; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void PolicyDirLoader::Reload() { | 60 void PolicyDirLoader::Reload() { |
61 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
62 | 62 |
63 // Check the directory time in order to see whether a reload is required. | 63 // Check the directory time in order to see whether a reload is required. |
64 base::TimeDelta delay; | 64 base::TimeDelta delay; |
65 base::Time now = base::Time::Now(); | 65 base::Time now = base::Time::Now(); |
66 if (!IsSafeToReloadPolicy(now, &delay)) { | 66 if (!IsSafeToReloadPolicy(now, &delay)) { |
67 ScheduleReloadTask(delay); | 67 ScheduleReloadTask(delay); |
68 return; | 68 return; |
69 } | 69 } |
70 | 70 |
71 // Load the policy definitions. | 71 // Load the policy definitions. |
(...skipping 24 matching lines...) Expand all Loading... |
96 // that'll make us recheck after a reasonable interval. | 96 // that'll make us recheck after a reasonable interval. |
97 ScheduleReloadTask(base::TimeDelta::FromMinutes(reload_interval_minutes_)); | 97 ScheduleReloadTask(base::TimeDelta::FromMinutes(reload_interval_minutes_)); |
98 } | 98 } |
99 | 99 |
100 DictionaryValue* PolicyDirLoader::GetPolicy() { | 100 DictionaryValue* PolicyDirLoader::GetPolicy() { |
101 AutoLock lock(lock_); | 101 AutoLock lock(lock_); |
102 return static_cast<DictionaryValue*>(policy_->DeepCopy()); | 102 return static_cast<DictionaryValue*>(policy_->DeepCopy()); |
103 } | 103 } |
104 | 104 |
105 void PolicyDirLoader::OnFilePathChanged(const FilePath& path) { | 105 void PolicyDirLoader::OnFilePathChanged(const FilePath& path) { |
106 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
107 Reload(); | 107 Reload(); |
108 } | 108 } |
109 | 109 |
110 void PolicyDirLoader::OnError() { | 110 void PolicyDirLoader::OnError() { |
111 LOG(ERROR) << "FileWatcher on " << config_dir_.value() << " failed."; | 111 LOG(ERROR) << "FileWatcher on " << config_dir_.value() << " failed."; |
112 } | 112 } |
113 | 113 |
114 DictionaryValue* PolicyDirLoader::Load() { | 114 DictionaryValue* PolicyDirLoader::Load() { |
115 // Enumerate the files and sort them lexicographically. | 115 // Enumerate the files and sort them lexicographically. |
116 std::set<FilePath> files; | 116 std::set<FilePath> files; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 base::TimeDelta age = now - last_modification_clock_; | 170 base::TimeDelta age = now - last_modification_clock_; |
171 if (age < settleInterval) { | 171 if (age < settleInterval) { |
172 *delay = settleInterval - age; | 172 *delay = settleInterval - age; |
173 return false; | 173 return false; |
174 } | 174 } |
175 | 175 |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 void PolicyDirLoader::ScheduleReloadTask(const base::TimeDelta& delay) { | 179 void PolicyDirLoader::ScheduleReloadTask(const base::TimeDelta& delay) { |
180 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
181 | 181 |
182 if (reload_task_) | 182 if (reload_task_) |
183 reload_task_->Cancel(); | 183 reload_task_->Cancel(); |
184 | 184 |
185 reload_task_ = NewRunnableMethod(this, &PolicyDirLoader::ReloadFromTask); | 185 reload_task_ = NewRunnableMethod(this, &PolicyDirLoader::ReloadFromTask); |
186 ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, reload_task_, | 186 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, reload_task_, |
187 delay.InMilliseconds()); | 187 delay.InMilliseconds()); |
188 } | 188 } |
189 | 189 |
190 void PolicyDirLoader::NotifyPolicyChanged() { | 190 void PolicyDirLoader::NotifyPolicyChanged() { |
191 DCHECK_EQ(origin_loop_, MessageLoop::current()); | 191 DCHECK_EQ(origin_loop_, MessageLoop::current()); |
192 if (provider_) | 192 if (provider_) |
193 provider_->NotifyStoreOfPolicyChange(); | 193 provider_->NotifyStoreOfPolicyChange(); |
194 } | 194 } |
195 | 195 |
196 void PolicyDirLoader::ReloadFromTask() { | 196 void PolicyDirLoader::ReloadFromTask() { |
197 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
198 | 198 |
199 // Drop the reference to the reload task, since the task might be the only | 199 // Drop the reference to the reload task, since the task might be the only |
200 // referer that keeps us alive, so we should not Cancel() it. | 200 // referer that keeps us alive, so we should not Cancel() it. |
201 reload_task_ = NULL; | 201 reload_task_ = NULL; |
202 | 202 |
203 Reload(); | 203 Reload(); |
204 } | 204 } |
205 | 205 |
206 // PolicyDirWatcher implementation: | 206 // PolicyDirWatcher implementation: |
207 | 207 |
208 void PolicyDirWatcher::Init(PolicyDirLoader* loader) { | 208 void PolicyDirWatcher::Init(PolicyDirLoader* loader) { |
209 // Initialization can happen early when the file thread is not yet available. | 209 // Initialization can happen early when the file thread is not yet available. |
210 // So post a task to ourselves on the UI thread which will run after threading | 210 // So post a task to ourselves on the UI thread which will run after threading |
211 // is up and schedule watch initialization on the file thread. | 211 // is up and schedule watch initialization on the file thread. |
212 ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, | 212 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
213 NewRunnableMethod(this, | 213 NewRunnableMethod(this, |
214 &PolicyDirWatcher::InitWatcher, | 214 &PolicyDirWatcher::InitWatcher, |
215 scoped_refptr<PolicyDirLoader>(loader))); | 215 scoped_refptr<PolicyDirLoader>(loader))); |
216 } | 216 } |
217 | 217 |
218 void PolicyDirWatcher::InitWatcher( | 218 void PolicyDirWatcher::InitWatcher( |
219 const scoped_refptr<PolicyDirLoader>& loader) { | 219 const scoped_refptr<PolicyDirLoader>& loader) { |
220 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { | 220 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
221 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, | 221 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
222 NewRunnableMethod(this, &PolicyDirWatcher::InitWatcher, loader)); | 222 NewRunnableMethod(this, &PolicyDirWatcher::InitWatcher, loader)); |
223 return; | 223 return; |
224 } | 224 } |
225 | 225 |
226 if (!watcher_.Watch(loader->config_dir(), loader.get())) | 226 if (!watcher_.Watch(loader->config_dir(), loader.get())) |
227 loader->OnError(); | 227 loader->OnError(); |
228 | 228 |
229 // There might have been changes to the directory in the time between | 229 // There might have been changes to the directory in the time between |
230 // construction of the loader and initialization of the watcher. Call reload | 230 // construction of the loader and initialization of the watcher. Call reload |
231 // to detect if that is the case. | 231 // to detect if that is the case. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 Value* value; | 265 Value* value; |
266 if (policies->Get(entry.name, &value) && value->IsType(entry.value_type)) | 266 if (policies->Get(entry.name, &value) && value->IsType(entry.value_type)) |
267 store->Apply(entry.policy_type, value->DeepCopy()); | 267 store->Apply(entry.policy_type, value->DeepCopy()); |
268 } | 268 } |
269 | 269 |
270 // TODO(mnissler): Handle preference overrides once |ConfigurationPolicyStore| | 270 // TODO(mnissler): Handle preference overrides once |ConfigurationPolicyStore| |
271 // supports it. | 271 // supports it. |
272 } | 272 } |
273 | 273 |
274 } // namespace policy | 274 } // namespace policy |
OLD | NEW |