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

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

Issue 22645011: policy: use JSON schema to deserialize entries from Windows registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 3rd party policy unit tests Created 7 years, 3 months 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
« no previous file with comments | « no previous file | chrome/browser/policy/async_policy_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 17 matching lines...) Expand all
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.
35 // LastModificationTime() is also invoked once on that thread at startup. 35 // LastModificationTime() is also invoked once on that thread at startup.
36 class AsyncPolicyLoader { 36 class AsyncPolicyLoader {
37 public: 37 public:
38 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback;
39
38 explicit AsyncPolicyLoader( 40 explicit AsyncPolicyLoader(
39 scoped_refptr<base::SequencedTaskRunner> task_runner); 41 scoped_refptr<base::SequencedTaskRunner> task_runner);
40 virtual ~AsyncPolicyLoader(); 42 virtual ~AsyncPolicyLoader();
41 43
42 // Gets a SequencedTaskRunner backed by the background thread. 44 // Gets a SequencedTaskRunner backed by the background thread.
43 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } 45 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); }
44 46
45 // Returns the currently configured policies. Load() is always invoked on 47 // Returns the currently configured policies. Load() is always invoked on
46 // the background thread, except for the initial Load() at startup which is 48 // the background thread, except for the initial Load() at startup which is
47 // invoked from the thread that owns the provider. 49 // invoked from the thread that owns the provider.
48 virtual scoped_ptr<PolicyBundle> Load() = 0; 50 virtual scoped_ptr<PolicyBundle> Load() = 0;
49 51
52 // Used by the AsyncPolicyProvider to install the |update_callback_|.
53 // Invoked on the background thread.
54 void Init(const UpdateCallback& update_callback);
55
50 // Allows implementations to finalize their initialization on the background 56 // Allows implementations to finalize their initialization on the background
51 // thread (e.g. setup file watchers). 57 // thread (e.g. setup file watchers).
52 virtual void InitOnBackgroundThread() = 0; 58 virtual void InitOnBackgroundThread() = 0;
53 59
54 // Implementations should return the time of the last modification detected, 60 // Implementations should return the time of the last modification detected,
55 // or base::Time() if it doesn't apply, which is the default. 61 // or base::Time() if it doesn't apply, which is the default.
56 virtual base::Time LastModificationTime(); 62 virtual base::Time LastModificationTime();
57 63
58 // Implementations should invoke Reload() when a change is detected. This 64 // Implementations should invoke Reload() when a change is detected. This
59 // must be invoked from the background thread and will trigger a Load(), 65 // must be invoked from the background thread and will trigger a Load(),
60 // and pass the returned bundle to the provider. 66 // and pass the returned bundle to the provider.
61 // The load is immediate when |force| is true. Otherwise, the loader 67 // The load is immediate when |force| is true. Otherwise, the loader
62 // reschedules the reload until the LastModificationTime() is a couple of 68 // reschedules the reload until the LastModificationTime() is a couple of
63 // seconds in the past. This mitigates the problem of reading files that are 69 // seconds in the past. This mitigates the problem of reading files that are
64 // currently being written to, and whose contents are incomplete. 70 // currently being written to, and whose contents are incomplete.
65 // A reload is posted periodically, if it hasn't been triggered recently. This 71 // 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. 72 // makes sure the policies are reloaded if the update events aren't triggered.
67 void Reload(bool force); 73 void Reload(bool force);
68 74
69 // Passes the current |descriptor| for a domain, which is used to determine 75 // Passes the current |descriptor| for a domain, which is used to determine
70 // which policy names are supported for each component. 76 // which policy names are supported for each component.
71 void RegisterPolicyDomain( 77 void RegisterPolicyDomain(
72 scoped_refptr<const PolicyDomainDescriptor> descriptor); 78 scoped_refptr<const PolicyDomainDescriptor> descriptor);
73 79
80 // Registers a policy domain without triggering a policy load.
81 void InitialRegisterPolicyDomain(
82 scoped_refptr<const PolicyDomainDescriptor> descriptor);
83
74 protected: 84 protected:
75 typedef std::map<PolicyDomain, scoped_refptr<const PolicyDomainDescriptor> > 85 typedef std::map<PolicyDomain, scoped_refptr<const PolicyDomainDescriptor> >
76 DescriptorMap; 86 DescriptorMap;
77 87
78 // Returns the current DescriptorMap. This can be used by implementations to 88 // Returns the current DescriptorMap. This can be used by implementations to
79 // determine the components registered for each domain, and to filter out 89 // determine the components registered for each domain, and to filter out
80 // unknonwn policies. 90 // unknonwn policies.
81 const DescriptorMap& descriptor_map() const { return descriptor_map_; } 91 const DescriptorMap& descriptor_map() const { return descriptor_map_; }
82 92
93 // Returns the desired descriptor if it exists, otherwise NULL.
94 scoped_refptr<const PolicyDomainDescriptor> get_descriptor(
95 PolicyDomain domain) const;
96
83 private: 97 private:
84 // Allow AsyncPolicyProvider to call Init(). 98 // Allow AsyncPolicyProvider to call Init().
85 friend class AsyncPolicyProvider; 99 friend class AsyncPolicyProvider;
86 100
87 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback;
88
89 // Used by the AsyncPolicyProvider to do the initial Load(). The first load 101 // Used by the AsyncPolicyProvider to do the initial Load(). The first load
90 // is also used to initialize |last_modification_time_|. 102 // is also used to initialize |last_modification_time_|.
91 scoped_ptr<PolicyBundle> InitialLoad(); 103 scoped_ptr<PolicyBundle> InitialLoad();
92 104
93 // Registers a policy domain without triggering a policy load.
94 void InitialRegisterPolicyDomain(
95 scoped_refptr<const PolicyDomainDescriptor> descriptor);
96
97 // Used by the AsyncPolicyProvider to install the |update_callback_|.
98 // Invoked on the background thread.
99 void Init(const UpdateCallback& update_callback);
100
101 // Cancels any pending periodic reload and posts one |delay| time units from 105 // Cancels any pending periodic reload and posts one |delay| time units from
102 // now. 106 // now.
103 void ScheduleNextReload(base::TimeDelta delay); 107 void ScheduleNextReload(base::TimeDelta delay);
104 108
105 // Checks if the underlying files haven't changed recently, by checking the 109 // Checks if the underlying files haven't changed recently, by checking the
106 // LastModificationTime(). |delay| is updated with a suggested time to wait 110 // LastModificationTime(). |delay| is updated with a suggested time to wait
107 // before retrying when this returns false. 111 // before retrying when this returns false.
108 bool IsSafeToReload(const base::Time& now, base::TimeDelta* delay); 112 bool IsSafeToReload(const base::Time& now, base::TimeDelta* delay);
109 113
110 // Task runner to run background threads. 114 // Task runner to run background threads.
(...skipping 16 matching lines...) Expand all
127 131
128 // A map of the currently registered domains and their descriptors. 132 // A map of the currently registered domains and their descriptors.
129 DescriptorMap descriptor_map_; 133 DescriptorMap descriptor_map_;
130 134
131 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); 135 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader);
132 }; 136 };
133 137
134 } // namespace policy 138 } // namespace policy
135 139
136 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_ 140 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/async_policy_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698