OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | |
6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | |
7 #pragma once | |
8 | |
9 #include "base/ref_counted.h" | |
10 #include "base/time.h" | |
11 #include "base/weak_ptr.h" | |
12 #include "chrome/browser/policy/configuration_policy_provider.h" | |
13 | |
14 class CancelableTask; | |
15 class MessageLoop; | |
16 | |
17 namespace policy { | |
18 | |
19 class AsynchronousPolicyLoader; | |
20 | |
21 // Policy provider that loads policy asynchronously. Providers subclass should | |
battre (please use the other)
2010/12/02 17:40:25
Nit: singular/plural in "Providers subclass"?
danno
2010/12/03 17:05:38
Done.
| |
22 // subclass from this class if loading the policy requires disk access or must | |
23 // for some other reason be performed on the file thread. The actual logic for | |
24 // loading policy is handled by a delegate passed at construction time. | |
25 class AsynchronousPolicyProvider | |
26 : public ConfigurationPolicyProvider, | |
27 public base::SupportsWeakPtr<AsynchronousPolicyProvider> { | |
28 public: | |
29 class PolicyChangeObserver; | |
30 | |
31 // Must be implemented by subclasses of the asynchronous policy provider to | |
32 // provide the implementation details of when and how policy is loaded. | |
33 class Delegate { | |
34 public: | |
35 Delegate() {} | |
36 virtual ~Delegate() {} | |
37 | |
38 // Called on the ui thread to provide the back channel with which delegates | |
39 // notify the provider that policy has changed and should be reloaded. | |
40 // The delegate assumes ownership of |observer|. | |
41 virtual void Init(PolicyChangeObserver* observer) = 0; | |
42 | |
43 // Called on the ui thread by the provider to indicate that the delegate | |
44 // should stop providing policy. The delegate must delete the observer that | |
45 // it was passed during Init at the very latest during this call. | |
battre (please use the other)
2010/12/02 17:40:25
Is it guaranteed that Stop() is called, i.e. the o
danno
2010/12/03 17:05:38
Done.
| |
46 virtual void Stop() = 0; | |
47 | |
48 // Load policies, returning a dictionary of the policy to value | |
49 // mappings. Will always be called on the file thread. | |
50 virtual DictionaryValue* Load() = 0; | |
51 | |
52 // Checks whether policy information is safe to read. If not, returns | |
53 // false and the delay until it is considered safe to reload in |delay|. | |
battre (please use the other)
2010/12/02 17:40:25
Nit: "then" "delays"
danno
2010/12/03 17:05:38
Done.
| |
54 // Will always be called on the file thread. | |
55 virtual bool IsSafeToReloadPolicy(const base::Time& now, | |
56 base::TimeDelta* delay) = 0; | |
57 | |
58 private: | |
59 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
60 }; | |
61 | |
62 // Assumes ownership of |delegate|. | |
63 AsynchronousPolicyProvider( | |
64 const PolicyDefinitionList* policy_list, | |
65 Delegate* delegate); | |
66 virtual ~AsynchronousPolicyProvider(); | |
67 | |
68 // ConfigurationPolicyProvider implementation. | |
69 virtual bool Provide(ConfigurationPolicyStoreInterface* store); | |
70 | |
71 private: | |
72 // The loader object used internally. | |
73 scoped_refptr<AsynchronousPolicyLoader> loader_; | |
74 | |
75 // The policy provider delegate. | |
76 Delegate* delegate_; // weak, owned by loader | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyProvider); | |
79 }; | |
80 | |
81 // Observer interface implemented by the asynchronous policy provider and passed | |
82 // to policy provider delegates as a back channel to indicate when policy should | |
83 // be reloaded. | |
84 class AsynchronousPolicyProvider::PolicyChangeObserver { | |
85 public: | |
86 virtual ~PolicyChangeObserver() {} | |
87 | |
88 virtual void OnPolicyChange() = 0; | |
89 | |
90 protected: | |
91 PolicyChangeObserver() {} | |
92 | |
93 private: | |
94 DISALLOW_COPY_AND_ASSIGN(PolicyChangeObserver); | |
95 }; | |
96 | |
97 } // namespace policy | |
98 | |
99 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | |
OLD | NEW |