Chromium Code Reviews| 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" | |
|
bartfab (slow)
2013/05/21 12:10:56
Nit: Would a forward-declaration of PolicyDomainDe
Joao da Silva
2013/05/21 17:50:14
Done.
| |
| 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 determine | |
| 60 // which policy names are supported for each component. | |
| 61 void RegisterPolicyDomain( | |
| 62 scoped_refptr<const PolicyDomainDescriptor> descriptor); | |
| 63 | |
| 64 protected: | |
| 65 typedef std::map<PolicyDomain, scoped_refptr<const PolicyDomainDescriptor> > | |
| 66 DescriptorMap; | |
| 67 | |
| 68 // Returns the current DescriptorMap. This can be used by implementations to | |
| 69 // determine the components registered for each domain, and to filter out | |
| 70 // unknonwn policies. | |
| 71 const DescriptorMap& descriptor_map() const { return descriptor_map_; } | |
| 72 | |
| 55 private: | 73 private: |
| 56 // Allow AsyncPolicyProvider to call Init(). | 74 // Allow AsyncPolicyProvider to call Init(). |
| 57 friend class AsyncPolicyProvider; | 75 friend class AsyncPolicyProvider; |
| 58 | 76 |
| 59 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; | 77 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; |
| 60 | 78 |
| 61 // Used by the AsyncPolicyProvider to do the initial Load(). The first load | 79 // Used by the AsyncPolicyProvider to do the initial Load(). The first load |
| 62 // is also used to initialize |last_modification_time_|. | 80 // is also used to initialize |last_modification_time_|. |
| 63 scoped_ptr<PolicyBundle> InitialLoad(); | 81 scoped_ptr<PolicyBundle> InitialLoad(); |
| 64 | 82 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 83 | 101 |
| 84 // Records last known modification timestamp. | 102 // Records last known modification timestamp. |
| 85 base::Time last_modification_time_; | 103 base::Time last_modification_time_; |
| 86 | 104 |
| 87 // The wall clock time at which the last modification timestamp was | 105 // 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 | 106 // 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 | 107 // wall clock times come from the same source, just in case there is some |
| 90 // non-local filesystem involved. | 108 // non-local filesystem involved. |
| 91 base::Time last_modification_clock_; | 109 base::Time last_modification_clock_; |
| 92 | 110 |
| 111 // A map of the currently registered domains and their descriptors. | |
| 112 DescriptorMap descriptor_map_; | |
| 113 | |
| 93 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); | 114 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); |
| 94 }; | 115 }; |
| 95 | 116 |
| 96 } // namespace policy | 117 } // namespace policy |
| 97 | 118 |
| 98 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ | 119 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ |
| OLD | NEW |