| 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 #ifndef CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ |
| 6 #define CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ | 6 #define CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 11 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "chrome/browser/policy/policy_domain_descriptor.h" |
| 12 | 16 |
| 13 namespace policy { | 17 namespace policy { |
| 14 | 18 |
| 15 class PolicyBundle; | 19 class PolicyBundle; |
| 16 | 20 |
| 17 // Base implementation for platform-specific policy loaders. Together with the | 21 // Base implementation for platform-specific policy loaders. Together with the |
| 18 // AsyncPolicyProvider, this base implementation takes care of the initial load, | 22 // AsyncPolicyProvider, this base implementation takes care of the initial load, |
| 19 // periodic reloads, watching file changes, refreshing policies and object | 23 // periodic reloads, watching file changes, refreshing policies and object |
| 20 // lifetime. | 24 // lifetime. |
| 21 // | 25 // |
| (...skipping 23 matching lines...) Expand all Loading... |
| 45 // must be invoked from the FILE thread and will trigger a Load(), and pass | 49 // must be invoked from the FILE thread and will trigger a Load(), and pass |
| 46 // the returned bundle to the provider. | 50 // the returned bundle to the provider. |
| 47 // The load is immediate when |force| is true. Otherwise, the loader | 51 // The load is immediate when |force| is true. Otherwise, the loader |
| 48 // reschedules the reload until the LastModificationTime() is a couple of | 52 // reschedules the reload until the LastModificationTime() is a couple of |
| 49 // seconds in the past. This mitigates the problem of reading files that are | 53 // seconds in the past. This mitigates the problem of reading files that are |
| 50 // currently being written to, and whose contents are incomplete. | 54 // currently being written to, and whose contents are incomplete. |
| 51 // A reload is posted periodically, if it hasn't been triggered recently. This | 55 // A reload is posted periodically, if it hasn't been triggered recently. This |
| 52 // makes sure the policies are reloaded if the update events aren't triggered. | 56 // makes sure the policies are reloaded if the update events aren't triggered. |
| 53 void Reload(bool force); | 57 void Reload(bool force); |
| 54 | 58 |
| 59 // Passes the current |descriptor| for a domain, which is used to filter out |
| 60 // policies that aren't registered, or whose type doesn't match the expected |
| 61 // type. |
| 62 void RegisterPolicyDomain( |
| 63 scoped_refptr<const PolicyDomainDescriptor> descriptor); |
| 64 |
| 65 protected: |
| 66 typedef std::map<PolicyDomain, scoped_refptr<const PolicyDomainDescriptor> > |
| 67 DescriptorMap; |
| 68 |
| 69 // Returns the current DescriptorMap. This can be used by implementations to |
| 70 // determine the components registered for each domain, and to filter out |
| 71 // unknonwn policies. |
| 72 const DescriptorMap& descriptor_map() const { return descriptor_map_; } |
| 73 |
| 55 private: | 74 private: |
| 56 // Allow AsyncPolicyProvider to call Init(). | 75 // Allow AsyncPolicyProvider to call Init(). |
| 57 friend class AsyncPolicyProvider; | 76 friend class AsyncPolicyProvider; |
| 58 | 77 |
| 59 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; | 78 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; |
| 60 | 79 |
| 61 // Used by the AsyncPolicyProvider to do the initial Load(). The first load | 80 // Used by the AsyncPolicyProvider to do the initial Load(). The first load |
| 62 // is also used to initialize |last_modification_time_|. | 81 // is also used to initialize |last_modification_time_|. |
| 63 scoped_ptr<PolicyBundle> InitialLoad(); | 82 scoped_ptr<PolicyBundle> InitialLoad(); |
| 64 | 83 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 | 102 |
| 84 // Records last known modification timestamp. | 103 // Records last known modification timestamp. |
| 85 base::Time last_modification_time_; | 104 base::Time last_modification_time_; |
| 86 | 105 |
| 87 // The wall clock time at which the last modification timestamp was | 106 // The wall clock time at which the last modification timestamp was |
| 88 // recorded. It's better to not assume the file notification time and the | 107 // recorded. It's better to not assume the file notification time and the |
| 89 // wall clock times come from the same source, just in case there is some | 108 // wall clock times come from the same source, just in case there is some |
| 90 // non-local filesystem involved. | 109 // non-local filesystem involved. |
| 91 base::Time last_modification_clock_; | 110 base::Time last_modification_clock_; |
| 92 | 111 |
| 112 // A map of the currently registered domains and their descriptors. |
| 113 DescriptorMap descriptor_map_; |
| 114 |
| 93 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); | 115 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); |
| 94 }; | 116 }; |
| 95 | 117 |
| 96 } // namespace policy | 118 } // namespace policy |
| 97 | 119 |
| 98 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ | 120 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ |
| OLD | NEW |