OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CLOUD_POLICY_CACHE_BASE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/gtest_prod_util.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
12 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
13 #include "base/time.h" | 11 #include "base/time.h" |
14 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 12 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
15 #include "chrome/browser/policy/configuration_policy_provider.h" | |
16 #include "chrome/browser/policy/policy_map.h" | 13 #include "chrome/browser/policy/policy_map.h" |
17 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
18 | 15 |
19 namespace policy { | 16 namespace policy { |
20 | 17 |
21 class PolicyMap; | |
22 class PolicyNotifier; | 18 class PolicyNotifier; |
23 | 19 |
24 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
25 | 21 |
26 // Caches policy information, as set by calls to |SetPolicy()|, persists | 22 // Caches policy information, as set by calls to |SetPolicy()|, persists |
27 // it to disk or session_manager (depending on subclass implementation), | 23 // it to disk or session_manager (depending on subclass implementation), |
28 // and makes it available via policy providers. | 24 // and makes it available via policy providers. |
29 class CloudPolicyCacheBase : public base::NonThreadSafe { | 25 class CloudPolicyCacheBase : public base::NonThreadSafe { |
30 public: | 26 public: |
31 // Used to distinguish mandatory from recommended policies. | 27 // Used to distinguish mandatory from recommended policies. |
32 enum PolicyLevel { | 28 enum PolicyLevel { |
33 // Policy is forced upon the user and should always take effect. | 29 // Policy is forced upon the user and should always take effect. |
34 POLICY_LEVEL_MANDATORY, | 30 POLICY_LEVEL_MANDATORY, |
35 // The value is just a recommendation that the user may override. | 31 // The value is just a recommendation that the user may override. |
36 POLICY_LEVEL_RECOMMENDED, | 32 POLICY_LEVEL_RECOMMENDED, |
37 }; | 33 }; |
38 | 34 |
35 class Observer { | |
36 public: | |
37 virtual ~Observer() {} | |
38 virtual void OnCacheGoingAway(CloudPolicyCacheBase*) = 0; | |
39 virtual void OnCacheUpdate(CloudPolicyCacheBase*) = 0; | |
40 }; | |
41 | |
39 CloudPolicyCacheBase(); | 42 CloudPolicyCacheBase(); |
40 virtual ~CloudPolicyCacheBase(); | 43 virtual ~CloudPolicyCacheBase(); |
41 | 44 |
42 void set_policy_notifier(PolicyNotifier* notifier) { | 45 void set_policy_notifier(PolicyNotifier* notifier) { |
43 notifier_ = notifier; | 46 notifier_ = notifier; |
44 } | 47 } |
45 | 48 |
46 // Loads persisted policy information. | 49 // Loads persisted policy information. |
47 virtual void Load() = 0; | 50 virtual void Load() = 0; |
48 | 51 |
49 // Resets the policy information. | 52 // Resets the policy information. |
50 virtual void SetPolicy(const em::PolicyFetchResponse& policy) = 0; | 53 virtual void SetPolicy(const em::PolicyFetchResponse& policy) = 0; |
51 | 54 |
52 ConfigurationPolicyProvider* GetManagedPolicyProvider(); | |
53 ConfigurationPolicyProvider* GetRecommendedPolicyProvider(); | |
54 | |
55 virtual void SetUnmanaged() = 0; | 55 virtual void SetUnmanaged() = 0; |
56 bool is_unmanaged() const { | 56 bool is_unmanaged() const { |
57 return is_unmanaged_; | 57 return is_unmanaged_; |
58 } | 58 } |
59 | 59 |
60 // Returns the time at which the policy was last fetched. | 60 // Returns the time at which the policy was last fetched. |
61 base::Time last_policy_refresh_time() const { | 61 base::Time last_policy_refresh_time() const { |
62 return last_policy_refresh_time_; | 62 return last_policy_refresh_time_; |
63 } | 63 } |
64 | 64 |
65 // Get the version of the encryption key currently used for decoding policy. | 65 // Get the version of the encryption key currently used for decoding policy. |
66 // Returns true if the version is available, in which case |version| is filled | 66 // Returns true if the version is available, in which case |version| is filled |
67 // in. | 67 // in. |
68 bool GetPublicKeyVersion(int* version); | 68 bool GetPublicKeyVersion(int* version); |
69 | 69 |
70 void AddObserver(Observer* observer); | |
71 void RemoveObserver(Observer* observer); | |
72 | |
73 // Accessor for underlying PolicyMaps. | |
74 const PolicyMap* mandatory_policy(); | |
75 const PolicyMap* recommended_policy(); | |
76 | |
77 // Convenience function calling either mandatory_policy() or | |
78 // recommended_policy() depending on |level|. | |
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
Do we need the accessors above then? Seems we shou
sfeuz
2011/06/13 06:53:53
I agree and think we should go with the policy() o
| |
79 const PolicyMap* policy(PolicyLevel level); | |
80 | |
81 // See comment for |initialization_complete_|. | |
82 bool initialization_complete() { | |
83 return initialization_complete_; | |
84 } | |
85 | |
70 protected: | 86 protected: |
71 // Wraps public key version and validity. | 87 // Wraps public key version and validity. |
72 struct PublicKeyVersion { | 88 struct PublicKeyVersion { |
73 int version; | 89 int version; |
74 bool valid; | 90 bool valid; |
75 }; | 91 }; |
76 | 92 |
77 // Decodes the given |policy| using |DecodePolicyResponse()|, applies the | 93 // Decodes the given |policy| using |DecodePolicyResponse()|, applies the |
78 // contents to |{mandatory,recommended}_policy_|, and notifies observers. | 94 // contents to |{mandatory,recommended}_policy_|, and notifies observers. |
79 // |timestamp| returns the timestamp embedded in |policy|, callers can pass | 95 // |timestamp| returns the timestamp embedded in |policy|, callers can pass |
(...skipping 16 matching lines...) Expand all Loading... | |
96 // Also performs verification, returns NULL if any check fails. | 112 // Also performs verification, returns NULL if any check fails. |
97 bool DecodePolicyResponse(const em::PolicyFetchResponse& policy_response, | 113 bool DecodePolicyResponse(const em::PolicyFetchResponse& policy_response, |
98 PolicyMap* mandatory, | 114 PolicyMap* mandatory, |
99 PolicyMap* recommended, | 115 PolicyMap* recommended, |
100 base::Time* timestamp, | 116 base::Time* timestamp, |
101 PublicKeyVersion* public_key_version); | 117 PublicKeyVersion* public_key_version); |
102 | 118 |
103 void InformNotifier(CloudPolicySubsystem::PolicySubsystemState state, | 119 void InformNotifier(CloudPolicySubsystem::PolicySubsystemState state, |
104 CloudPolicySubsystem::ErrorDetails error_details); | 120 CloudPolicySubsystem::ErrorDetails error_details); |
105 | 121 |
106 // See comment for |initialization_complete_|. | |
107 bool initialization_complete() { | |
108 return initialization_complete_; | |
109 } | |
110 | |
111 void set_last_policy_refresh_time(base::Time timestamp) { | 122 void set_last_policy_refresh_time(base::Time timestamp) { |
112 last_policy_refresh_time_ = timestamp; | 123 last_policy_refresh_time_ = timestamp; |
113 } | 124 } |
114 | 125 |
115 private: | 126 private: |
116 class CloudPolicyProvider; | |
117 | |
118 friend class DevicePolicyCacheTest; | 127 friend class DevicePolicyCacheTest; |
119 friend class UserPolicyCacheTest; | 128 friend class UserPolicyCacheTest; |
129 friend class MockCloudPolicyCacheBase; | |
120 | 130 |
121 // Policy key-value information. | 131 // Policy key-value information. |
122 PolicyMap mandatory_policy_; | 132 PolicyMap mandatory_policy_; |
123 PolicyMap recommended_policy_; | 133 PolicyMap recommended_policy_; |
124 | 134 |
125 // Policy providers. | |
126 scoped_ptr<ConfigurationPolicyProvider> managed_policy_provider_; | |
127 scoped_ptr<ConfigurationPolicyProvider> recommended_policy_provider_; | |
128 | |
129 PolicyNotifier* notifier_; | 135 PolicyNotifier* notifier_; |
130 | 136 |
131 // The time at which the policy was last refreshed. Is updated both upon | 137 // The time at which the policy was last refreshed. Is updated both upon |
132 // successful and unsuccessful refresh attempts. | 138 // successful and unsuccessful refresh attempts. |
133 base::Time last_policy_refresh_time_; | 139 base::Time last_policy_refresh_time_; |
134 | 140 |
135 // Whether initialization has been completed. This is the case when we have | 141 // Whether initialization has been completed. This is the case when we have |
136 // valid policy, learned that the device is unmanaged or ran into | 142 // valid policy, learned that the device is unmanaged or ran into |
137 // unrecoverable errors. | 143 // unrecoverable errors. |
138 bool initialization_complete_; | 144 bool initialization_complete_; |
139 | 145 |
140 // Whether the the server has indicated this device is unmanaged. | 146 // Whether the the server has indicated this device is unmanaged. |
141 bool is_unmanaged_; | 147 bool is_unmanaged_; |
142 | 148 |
143 // Currently used public key version, if available. | 149 // Currently used public key version, if available. |
144 PublicKeyVersion public_key_version_; | 150 PublicKeyVersion public_key_version_; |
145 | 151 |
146 // Provider observers that are registered with this cache's providers. | 152 // Cache observers that are registered with this cache. |
147 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; | 153 ObserverList<Observer, true> observer_list_; |
148 | 154 |
149 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCacheBase); | 155 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCacheBase); |
150 }; | 156 }; |
151 | 157 |
152 } // namespace policy | 158 } // namespace policy |
153 | 159 |
154 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ | 160 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ |
OLD | NEW |