| 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 // 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 class PolicyWatcherLinux : public PolicyWatcher { | 48 class PolicyWatcherLinux : public PolicyWatcher { |
| 49 public: | 49 public: |
| 50 PolicyWatcherLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 50 PolicyWatcherLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 51 const base::FilePath& config_dir) | 51 const base::FilePath& config_dir) |
| 52 : PolicyWatcher(task_runner), | 52 : PolicyWatcher(task_runner), |
| 53 config_dir_(config_dir), | 53 config_dir_(config_dir), |
| 54 weak_factory_(this) { | 54 weak_factory_(this) { |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual ~PolicyWatcherLinux() {} | 57 ~PolicyWatcherLinux() override {} |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 virtual void StartWatchingInternal() override { | 60 void StartWatchingInternal() override { |
| 61 DCHECK(OnPolicyWatcherThread()); | 61 DCHECK(OnPolicyWatcherThread()); |
| 62 watcher_.reset(new base::FilePathWatcher()); | 62 watcher_.reset(new base::FilePathWatcher()); |
| 63 | 63 |
| 64 if (!config_dir_.empty() && | 64 if (!config_dir_.empty() && |
| 65 !watcher_->Watch( | 65 !watcher_->Watch( |
| 66 config_dir_, false, | 66 config_dir_, false, |
| 67 base::Bind(&PolicyWatcherLinux::OnFilePathChanged, | 67 base::Bind(&PolicyWatcherLinux::OnFilePathChanged, |
| 68 weak_factory_.GetWeakPtr()))) { | 68 weak_factory_.GetWeakPtr()))) { |
| 69 OnFilePathChanged(config_dir_, true); | 69 OnFilePathChanged(config_dir_, true); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // There might have been changes to the directory in the time between | 72 // There might have been changes to the directory in the time between |
| 73 // construction of the loader and initialization of the watcher. Call reload | 73 // construction of the loader and initialization of the watcher. Call reload |
| 74 // to detect if that is the case. | 74 // to detect if that is the case. |
| 75 Reload(); | 75 Reload(); |
| 76 | 76 |
| 77 ScheduleFallbackReloadTask(); | 77 ScheduleFallbackReloadTask(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual void StopWatchingInternal() override { | 80 void StopWatchingInternal() override { |
| 81 DCHECK(OnPolicyWatcherThread()); | 81 DCHECK(OnPolicyWatcherThread()); |
| 82 | 82 |
| 83 // Stop watching for changes to files in the policies directory. | 83 // Stop watching for changes to files in the policies directory. |
| 84 watcher_.reset(); | 84 watcher_.reset(); |
| 85 | 85 |
| 86 // Orphan any pending OnFilePathChanged tasks. | 86 // Orphan any pending OnFilePathChanged tasks. |
| 87 weak_factory_.InvalidateWeakPtrs(); | 87 weak_factory_.InvalidateWeakPtrs(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 private: | 90 private: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 LOG(WARNING) << "Expected JSON dictionary in configuration file " | 155 LOG(WARNING) << "Expected JSON dictionary in configuration file " |
| 156 << config_file_iter->value(); | 156 << config_file_iter->value(); |
| 157 return nullptr; | 157 return nullptr; |
| 158 } | 158 } |
| 159 policy->MergeDictionary(static_cast<base::DictionaryValue*>(value.get())); | 159 policy->MergeDictionary(static_cast<base::DictionaryValue*>(value.get())); |
| 160 } | 160 } |
| 161 | 161 |
| 162 return policy.Pass(); | 162 return policy.Pass(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 virtual void Reload() override { | 165 void Reload() override { |
| 166 DCHECK(OnPolicyWatcherThread()); | 166 DCHECK(OnPolicyWatcherThread()); |
| 167 // Check the directory time in order to see whether a reload is required. | 167 // Check the directory time in order to see whether a reload is required. |
| 168 base::TimeDelta delay; | 168 base::TimeDelta delay; |
| 169 base::Time now = base::Time::Now(); | 169 base::Time now = base::Time::Now(); |
| 170 if (!IsSafeToReloadPolicy(now, &delay)) { | 170 if (!IsSafeToReloadPolicy(now, &delay)) { |
| 171 ScheduleReloadTask(delay); | 171 ScheduleReloadTask(delay); |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Check again in case the directory has changed while reading it. | 175 // Check again in case the directory has changed while reading it. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 PolicyWatcher* PolicyWatcher::Create( | 247 PolicyWatcher* PolicyWatcher::Create( |
| 248 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 248 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 249 base::FilePath policy_dir(kPolicyDir); | 249 base::FilePath policy_dir(kPolicyDir); |
| 250 return new PolicyWatcherLinux(task_runner, policy_dir); | 250 return new PolicyWatcherLinux(task_runner, policy_dir); |
| 251 } | 251 } |
| 252 | 252 |
| 253 } // namespace policy_hack | 253 } // namespace policy_hack |
| 254 } // namespace remoting | 254 } // namespace remoting |
| OLD | NEW |