Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/policy/async_policy_loader.h

Issue 56623005: Policy providers all get a SchemaRegistry to work with. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-9-purge-with-callback
Patch Set: Fixed mac tests Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 8 #include <map>
bartfab (slow) 2013/11/05 15:53:04 Nit: No longer used.
Joao da Silva 2013/11/07 13:15:00 Done.
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/policy/schema_map.h"
15 #include "components/policy/core/common/policy_namespace.h" 16 #include "components/policy/core/common/policy_namespace.h"
bartfab (slow) 2013/11/05 15:53:04 Nit: No longer used.
Joao da Silva 2013/11/07 13:15:00 Done.
16 17
17 namespace base { 18 namespace base {
18 class SequencedTaskRunner; 19 class SequencedTaskRunner;
19 } 20 }
20 21
21 namespace policy { 22 namespace policy {
22 23
23 class PolicyBundle; 24 class PolicyBundle;
24 class PolicyDomainDescriptor;
25 25
26 // Base implementation for platform-specific policy loaders. Together with the 26 // Base implementation for platform-specific policy loaders. Together with the
27 // AsyncPolicyProvider, this base implementation takes care of the initial load, 27 // AsyncPolicyProvider, this base implementation takes care of the initial load,
28 // periodic reloads, watching file changes, refreshing policies and object 28 // periodic reloads, watching file changes, refreshing policies and object
29 // lifetime. 29 // lifetime.
30 // 30 //
31 // All methods are invoked on the background |task_runner_|, including the 31 // All methods are invoked on the background |task_runner_|, including the
32 // destructor. The only exceptions are the constructor (which may be called on 32 // destructor. The only exceptions are the constructor (which may be called on
33 // any thread), and the initial Load() which is called on the thread that owns 33 // any thread), and the initial Load() which is called on the thread that owns
34 // the provider. 34 // the provider.
(...skipping 13 matching lines...) Expand all
48 virtual scoped_ptr<PolicyBundle> Load() = 0; 48 virtual scoped_ptr<PolicyBundle> Load() = 0;
49 49
50 // Allows implementations to finalize their initialization on the background 50 // Allows implementations to finalize their initialization on the background
51 // thread (e.g. setup file watchers). 51 // thread (e.g. setup file watchers).
52 virtual void InitOnBackgroundThread() = 0; 52 virtual void InitOnBackgroundThread() = 0;
53 53
54 // Implementations should return the time of the last modification detected, 54 // Implementations should return the time of the last modification detected,
55 // or base::Time() if it doesn't apply, which is the default. 55 // or base::Time() if it doesn't apply, which is the default.
56 virtual base::Time LastModificationTime(); 56 virtual base::Time LastModificationTime();
57 57
58 // Used by the AsyncPolicyProvider to do the initial Load(). The first load
59 // is also used to initialize |last_modification_time_| and
60 // |schema_map_|.
61 scoped_ptr<PolicyBundle> InitialLoad(const scoped_refptr<SchemaMap>& schemas);
62
58 // Implementations should invoke Reload() when a change is detected. This 63 // Implementations should invoke Reload() when a change is detected. This
59 // must be invoked from the background thread and will trigger a Load(), 64 // must be invoked from the background thread and will trigger a Load(),
60 // and pass the returned bundle to the provider. 65 // and pass the returned bundle to the provider.
61 // The load is immediate when |force| is true. Otherwise, the loader 66 // The load is immediate when |force| is true. Otherwise, the loader
62 // reschedules the reload until the LastModificationTime() is a couple of 67 // reschedules the reload until the LastModificationTime() is a couple of
63 // seconds in the past. This mitigates the problem of reading files that are 68 // seconds in the past. This mitigates the problem of reading files that are
64 // currently being written to, and whose contents are incomplete. 69 // currently being written to, and whose contents are incomplete.
65 // A reload is posted periodically, if it hasn't been triggered recently. This 70 // A reload is posted periodically, if it hasn't been triggered recently. This
66 // makes sure the policies are reloaded if the update events aren't triggered. 71 // makes sure the policies are reloaded if the update events aren't triggered.
67 void Reload(bool force); 72 void Reload(bool force);
68 73
69 // Passes the current |descriptor| for a domain, which is used to determine 74 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; }
70 // which policy names are supported for each component.
71 void RegisterPolicyDomain(
72 scoped_refptr<const PolicyDomainDescriptor> descriptor);
73
74 protected:
75 typedef std::map<PolicyDomain, scoped_refptr<const PolicyDomainDescriptor> >
76 DescriptorMap;
77
78 // Returns the current DescriptorMap. This can be used by implementations to
79 // determine the components registered for each domain, and to filter out
80 // unknonwn policies.
81 const DescriptorMap& descriptor_map() const { return descriptor_map_; }
82 75
83 private: 76 private:
84 // Allow AsyncPolicyProvider to call Init(). 77 // Allow AsyncPolicyProvider to call Init().
85 friend class AsyncPolicyProvider; 78 friend class AsyncPolicyProvider;
86 79
87 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; 80 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback;
88 81
89 // Used by the AsyncPolicyProvider to do the initial Load(). The first load
90 // is also used to initialize |last_modification_time_|.
91 scoped_ptr<PolicyBundle> InitialLoad();
92
93 // Used by the AsyncPolicyProvider to install the |update_callback_|. 82 // Used by the AsyncPolicyProvider to install the |update_callback_|.
94 // Invoked on the background thread. 83 // Invoked on the background thread.
95 void Init(const UpdateCallback& update_callback); 84 void Init(const UpdateCallback& update_callback);
96 85
86 // Used by the AsyncPolicyProvider to reload with an updated SchemaMap.
87 void RefreshPolicies(scoped_refptr<SchemaMap> schema_map);
88
97 // Cancels any pending periodic reload and posts one |delay| time units from 89 // Cancels any pending periodic reload and posts one |delay| time units from
98 // now. 90 // now.
99 void ScheduleNextReload(base::TimeDelta delay); 91 void ScheduleNextReload(base::TimeDelta delay);
100 92
101 // Checks if the underlying files haven't changed recently, by checking the 93 // Checks if the underlying files haven't changed recently, by checking the
102 // LastModificationTime(). |delay| is updated with a suggested time to wait 94 // LastModificationTime(). |delay| is updated with a suggested time to wait
103 // before retrying when this returns false. 95 // before retrying when this returns false.
104 bool IsSafeToReload(const base::Time& now, base::TimeDelta* delay); 96 bool IsSafeToReload(const base::Time& now, base::TimeDelta* delay);
105 97
106 // Task runner to run background threads. 98 // Task runner to run background threads.
107 scoped_refptr<base::SequencedTaskRunner> task_runner_; 99 scoped_refptr<base::SequencedTaskRunner> task_runner_;
108 100
109 // Callback for updates, passed in Init(). 101 // Callback for updates, passed in Init().
110 UpdateCallback update_callback_; 102 UpdateCallback update_callback_;
111 103
112 // Used to get WeakPtrs for the periodic reload task. 104 // Used to get WeakPtrs for the periodic reload task.
113 base::WeakPtrFactory<AsyncPolicyLoader> weak_factory_; 105 base::WeakPtrFactory<AsyncPolicyLoader> weak_factory_;
114 106
115 // Records last known modification timestamp. 107 // Records last known modification timestamp.
116 base::Time last_modification_time_; 108 base::Time last_modification_time_;
117 109
118 // The wall clock time at which the last modification timestamp was 110 // The wall clock time at which the last modification timestamp was
119 // recorded. It's better to not assume the file notification time and the 111 // recorded. It's better to not assume the file notification time and the
120 // wall clock times come from the same source, just in case there is some 112 // wall clock times come from the same source, just in case there is some
121 // non-local filesystem involved. 113 // non-local filesystem involved.
122 base::Time last_modification_clock_; 114 base::Time last_modification_clock_;
123 115
124 // A map of the currently registered domains and their descriptors. 116 // The current policy schemas that this provider should load.
125 DescriptorMap descriptor_map_; 117 scoped_refptr<SchemaMap> schema_map_;
126 118
127 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); 119 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader);
128 }; 120 };
129 121
130 } // namespace policy 122 } // namespace policy
131 123
132 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ 124 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698