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/file_based_policy_loader.h" | 5 #include "chrome/browser/policy/file_based_policy_loader.h" |
6 | 6 |
| 7 #include "content/browser/browser_thread.h" |
| 8 |
7 namespace { | 9 namespace { |
8 | 10 |
9 // Amount of time we wait for the files on disk to settle before trying to load | 11 // Amount of time we wait for the files on disk to settle before trying to load |
10 // them. This alleviates the problem of reading partially written files and | 12 // them. This alleviates the problem of reading partially written files and |
11 // makes it possible to batch quasi-simultaneous changes. | 13 // makes it possible to batch quasi-simultaneous changes. |
12 const int kSettleIntervalSeconds = 5; | 14 const int kSettleIntervalSeconds = 5; |
13 | 15 |
14 // The time interval for rechecking policy. This is our fallback in case the | 16 // The time interval for rechecking policy. This is our fallback in case the |
15 // delegate never reports a change to the ReloadObserver. | 17 // delegate never reports a change to the ReloadObserver. |
16 const int kReloadIntervalMinutes = 15; | 18 const int kReloadIntervalMinutes = 15; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 PostUpdatePolicyTask(new_policy.release()); | 89 PostUpdatePolicyTask(new_policy.release()); |
88 | 90 |
89 ScheduleFallbackReloadTask(); | 91 ScheduleFallbackReloadTask(); |
90 } | 92 } |
91 | 93 |
92 void FileBasedPolicyLoader::InitOnFileThread() { | 94 void FileBasedPolicyLoader::InitOnFileThread() { |
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
94 watcher_.reset(new FilePathWatcher); | 96 watcher_.reset(new FilePathWatcher); |
95 if (!config_file_path().empty() && | 97 if (!config_file_path().empty() && |
96 !watcher_->Watch(config_file_path(), | 98 !watcher_->Watch( |
97 new FileBasedPolicyWatcherDelegate(this))) { | 99 config_file_path(), |
| 100 new FileBasedPolicyWatcherDelegate(this), |
| 101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI))) { |
98 OnError(); | 102 OnError(); |
99 } | 103 } |
100 | 104 |
101 // There might have been changes to the directory in the time between | 105 // There might have been changes to the directory in the time between |
102 // construction of the loader and initialization of the watcher. Call reload | 106 // construction of the loader and initialization of the watcher. Call reload |
103 // to detect if that is the case. | 107 // to detect if that is the case. |
104 Reload(); | 108 Reload(); |
105 | 109 |
106 ScheduleFallbackReloadTask(); | 110 ScheduleFallbackReloadTask(); |
107 } | 111 } |
(...skipping 27 matching lines...) Expand all Loading... |
135 base::TimeDelta age = now - last_modification_clock_; | 139 base::TimeDelta age = now - last_modification_clock_; |
136 if (age < settle_interval_) { | 140 if (age < settle_interval_) { |
137 *delay = settle_interval_ - age; | 141 *delay = settle_interval_ - age; |
138 return false; | 142 return false; |
139 } | 143 } |
140 | 144 |
141 return true; | 145 return true; |
142 } | 146 } |
143 | 147 |
144 } // namespace policy | 148 } // namespace policy |
OLD | NEW |