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_service.h" |
12 | 16 |
13 namespace policy { | 17 namespace policy { |
14 | 18 |
15 class PolicyBundle; | 19 class PolicyBundle; |
| 20 class PolicyDomainDescriptor; |
16 | 21 |
17 // Base implementation for platform-specific policy loaders. Together with the | 22 // Base implementation for platform-specific policy loaders. Together with the |
18 // AsyncPolicyProvider, this base implementation takes care of the initial load, | 23 // AsyncPolicyProvider, this base implementation takes care of the initial load, |
19 // periodic reloads, watching file changes, refreshing policies and object | 24 // periodic reloads, watching file changes, refreshing policies and object |
20 // lifetime. | 25 // lifetime. |
21 // | 26 // |
22 // All methods are invoked on the FILE thread, including the destructor. | 27 // All methods are invoked on the FILE thread, including the destructor. |
23 // The only exceptions are the constructor (which may be called on any thread), | 28 // The only exceptions are the constructor (which may be called on any thread), |
24 // and the initial Load() which is called on the thread that owns the provider. | 29 // and the initial Load() which is called on the thread that owns the provider. |
25 // LastModificationTime() is also invoked once on that thread at startup. | 30 // LastModificationTime() is also invoked once on that thread at startup. |
(...skipping 19 matching lines...) Expand all Loading... |
45 // must be invoked from the FILE thread and will trigger a Load(), and pass | 50 // must be invoked from the FILE thread and will trigger a Load(), and pass |
46 // the returned bundle to the provider. | 51 // the returned bundle to the provider. |
47 // The load is immediate when |force| is true. Otherwise, the loader | 52 // The load is immediate when |force| is true. Otherwise, the loader |
48 // reschedules the reload until the LastModificationTime() is a couple of | 53 // reschedules the reload until the LastModificationTime() is a couple of |
49 // seconds in the past. This mitigates the problem of reading files that are | 54 // seconds in the past. This mitigates the problem of reading files that are |
50 // currently being written to, and whose contents are incomplete. | 55 // currently being written to, and whose contents are incomplete. |
51 // A reload is posted periodically, if it hasn't been triggered recently. This | 56 // 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. | 57 // makes sure the policies are reloaded if the update events aren't triggered. |
53 void Reload(bool force); | 58 void Reload(bool force); |
54 | 59 |
| 60 // Passes the current |descriptor| for a domain, which is used to determine |
| 61 // which policy names are supported for each component. |
| 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 |