| 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 #ifndef CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ |
| 6 #define CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ | 6 #define CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/files/file_path_watcher.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time.h" |
| 10 #include "chrome/browser/policy/asynchronous_policy_loader.h" | 13 #include "chrome/browser/policy/asynchronous_policy_loader.h" |
| 11 #include "chrome/browser/policy/file_based_policy_provider.h" | 14 #include "chrome/browser/policy/file_based_policy_provider.h" |
| 12 | 15 |
| 16 namespace base { |
| 17 namespace files { |
| 18 |
| 19 class FilePathWatcher; |
| 20 |
| 21 } // namespace files |
| 22 } // namespace base |
| 23 |
| 13 namespace policy { | 24 namespace policy { |
| 14 | 25 |
| 15 // A customized asynchronous policy loader that handles loading policy from a | 26 // A customized asynchronous policy loader that handles loading policy from a |
| 16 // file using a FilePathWatcher. The loader creates a fallback task to load | 27 // file using a FilePathWatcher. The loader creates a fallback task to load |
| 17 // policy periodically in case the watcher fails and retries policy loads when | 28 // policy periodically in case the watcher fails and retries policy loads when |
| 18 // the watched file is in flux. | 29 // the watched file is in flux. |
| 19 class FileBasedPolicyLoader : public AsynchronousPolicyLoader { | 30 class FileBasedPolicyLoader : public AsynchronousPolicyLoader { |
| 20 public: | 31 public: |
| 21 FileBasedPolicyLoader( | 32 explicit FileBasedPolicyLoader( |
| 22 FileBasedPolicyProvider::ProviderDelegate* provider_delegate); | 33 FileBasedPolicyProvider::ProviderDelegate* provider_delegate); |
| 23 | 34 |
| 24 // AsynchronousPolicyLoader overrides: | 35 // AsynchronousPolicyLoader overrides: |
| 25 virtual void Reload(); | 36 virtual void Reload() OVERRIDE; |
| 26 | 37 |
| 27 void OnFilePathChanged(const FilePath& path); | 38 void OnFilePathChanged(const FilePath& path); |
| 28 void OnFilePathError(const FilePath& path); | 39 void OnFilePathError(const FilePath& path); |
| 29 | 40 |
| 30 protected: | 41 protected: |
| 31 // FileBasedPolicyLoader objects should only be deleted by | 42 // FileBasedPolicyLoader objects should only be deleted by |
| 32 // RefCountedThreadSafe. | 43 // RefCountedThreadSafe. |
| 33 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; | 44 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; |
| 34 virtual ~FileBasedPolicyLoader(); | 45 virtual ~FileBasedPolicyLoader(); |
| 35 | 46 |
| 36 const FilePath& config_file_path() { return config_file_path_; } | 47 const FilePath& config_file_path() { return config_file_path_; } |
| 37 | 48 |
| 38 // AsynchronousPolicyLoader overrides: | 49 // AsynchronousPolicyLoader overrides: |
| 39 | 50 |
| 40 // Creates the file path watcher and configures it to watch | 51 // Creates the file path watcher and configures it to watch |
| 41 // |config_file_path_|. Must be called on the file thread. | 52 // |config_file_path_|. Must be called on the file thread. |
| 42 virtual void InitOnFileThread(); | 53 virtual void InitOnFileThread() OVERRIDE; |
| 43 virtual void StopOnFileThread(); | 54 virtual void StopOnFileThread() OVERRIDE; |
| 44 | 55 |
| 45 private: | 56 private: |
| 46 // Checks whether policy information is safe to read. If not, returns false | 57 // Checks whether policy information is safe to read. If not, returns false |
| 47 // and then delays until it is considered safe to reload in |delay|. | 58 // and then delays until it is considered safe to reload in |delay|. |
| 48 // Must be called on the file thread. | 59 // Must be called on the file thread. |
| 49 bool IsSafeToReloadPolicy(const base::Time& now, base::TimeDelta* delay); | 60 bool IsSafeToReloadPolicy(const base::Time& now, base::TimeDelta* delay); |
| 50 | 61 |
| 51 // The path at which we look for configuration files. | 62 // The path at which we look for configuration files. |
| 52 const FilePath config_file_path_; | 63 const FilePath config_file_path_; |
| 53 | 64 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 // wall clock times come from the same source, just in case there is some | 80 // wall clock times come from the same source, just in case there is some |
| 70 // non-local filesystem involved. | 81 // non-local filesystem involved. |
| 71 base::Time last_modification_clock_; | 82 base::Time last_modification_clock_; |
| 72 | 83 |
| 73 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyLoader); | 84 DISALLOW_COPY_AND_ASSIGN(FileBasedPolicyLoader); |
| 74 }; | 85 }; |
| 75 | 86 |
| 76 } // namespace policy | 87 } // namespace policy |
| 77 | 88 |
| 78 #endif // CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ | 89 #endif // CHROME_BROWSER_POLICY_FILE_BASED_POLICY_LOADER_H_ |
| OLD | NEW |