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_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/observer_list.h" | |
12 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/threading/non_thread_safe.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "chrome/browser/policy/configuration_policy_provider.h" | 17 #include "chrome/browser/policy/configuration_policy_provider.h" |
17 #include "chrome/browser/policy/policy_map.h" | 18 #include "chrome/browser/policy/policy_map.h" |
18 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 19 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
19 #include "policy/configuration_policy_type.h" | 20 #include "policy/configuration_policy_type.h" |
20 | 21 |
21 class DictionaryValue; | 22 class DictionaryValue; |
22 class ListValue; | 23 class ListValue; |
23 class Value; | 24 class Value; |
24 | 25 |
25 using google::protobuf::RepeatedPtrField; | 26 using google::protobuf::RepeatedPtrField; |
26 | 27 |
27 namespace policy { | 28 namespace policy { |
28 | 29 |
29 namespace em = enterprise_management; | 30 namespace em = enterprise_management; |
30 | 31 |
31 // Keeps the authoritative copy of cloud policy information as read from the | 32 // Keeps the authoritative copy of cloud policy information as read from the |
32 // persistence file or determined by the policy backend. The cache doesn't talk | 33 // persistence file or determined by the policy backend. The cache doesn't talk |
33 // to the service directly, but receives updated policy information through | 34 // to the service directly, but receives updated policy information through |
34 // SetPolicy() calls, which is then persisted and decoded into the internal | 35 // SetPolicy() calls, which is then persisted and decoded into the internal |
35 // Value representation chrome uses. | 36 // Value representation chrome uses. |
36 class CloudPolicyCache { | 37 class CloudPolicyCache : public base::NonThreadSafe { |
Mattias Nissler (ping if slow)
2011/02/21 14:39:13
I don't know who requested to derive from NonThrea
Jakob Kummerow
2011/02/22 10:02:33
As discussed offline, we'll leave it as is.
| |
37 public: | 38 public: |
39 // Used to distinguish mandatory from recommended policies. | |
40 enum PolicyLevel { | |
41 // Policy is forced upon the user and should always take effect. | |
42 POLICY_LEVEL_MANDATORY, | |
43 // The value is just a recommendation that the user may override. | |
44 POLICY_LEVEL_RECOMMENDED, | |
45 }; | |
46 | |
38 explicit CloudPolicyCache(const FilePath& backing_file_path); | 47 explicit CloudPolicyCache(const FilePath& backing_file_path); |
39 ~CloudPolicyCache(); | 48 ~CloudPolicyCache(); |
40 | 49 |
41 // Loads policy information from the backing file. Non-existing or erroneous | 50 // Loads policy information from the backing file. Non-existing or erroneous |
42 // cache files are ignored. | 51 // cache files are ignored. |
43 void LoadPolicyFromFile(); | 52 void LoadFromFile(); |
44 | 53 |
45 // Resets the policy information. Returns true if the new policy is different | 54 // Resets the policy information. |
46 // from the previously stored policy. | 55 void SetPolicy(const em::CloudPolicyResponse& policy); |
47 bool SetPolicy(const em::CloudPolicyResponse& policy); | 56 void SetDevicePolicy(const em::DevicePolicyResponse& policy); |
48 bool SetDevicePolicy(const em::DevicePolicyResponse& policy); | |
49 | 57 |
50 // Gets the policy information. Ownership of the return value is transferred | 58 ConfigurationPolicyProvider* GetManagedPolicyProvider(); |
51 // to the caller. | 59 ConfigurationPolicyProvider* GetRecommendedPolicyProvider(); |
52 DictionaryValue* GetDevicePolicy(); | |
53 const PolicyMap* GetMandatoryPolicy() const; | |
54 const PolicyMap* GetRecommendedPolicy() const; | |
55 | 60 |
56 void SetUnmanaged(); | 61 void SetUnmanaged(); |
57 bool is_unmanaged() const { | 62 bool is_unmanaged() const { |
58 return is_unmanaged_; | 63 return is_unmanaged_; |
59 } | 64 } |
60 | 65 |
61 // Returns the time at which the policy was last fetched. | 66 // Returns the time at which the policy was last fetched. |
62 base::Time last_policy_refresh_time() const { | 67 base::Time last_policy_refresh_time() const { |
63 return last_policy_refresh_time_; | 68 return last_policy_refresh_time_; |
64 } | 69 } |
65 | 70 |
66 // Returns true if this cache holds (old-style) device policy that should be | 71 // Returns true if this cache holds (old-style) device policy that should be |
67 // given preference over (new-style) mandatory/recommended policy. | 72 // given preference over (new-style) mandatory/recommended policy. |
68 bool has_device_policy() const { | 73 bool has_device_policy() const { |
69 return has_device_policy_; | 74 return has_device_policy_; |
70 } | 75 } |
71 | 76 |
72 private: | 77 private: |
78 class CloudPolicyProvider; | |
79 | |
73 friend class CloudPolicyCacheTest; | 80 friend class CloudPolicyCacheTest; |
81 friend class DeviceManagementPolicyCacheTest; | |
74 friend class DeviceManagementPolicyCacheDecodeTest; | 82 friend class DeviceManagementPolicyCacheDecodeTest; |
75 | 83 |
76 // Decodes a CloudPolicyResponse into two (ConfigurationPolicyType -> Value*) | 84 // Decodes a CloudPolicyResponse into two (ConfigurationPolicyType -> Value*) |
77 // maps and a timestamp. Also performs verification, returns NULL if any | 85 // maps and a timestamp. Also performs verification, returns NULL if any |
78 // check fails. | 86 // check fails. |
79 static bool DecodePolicyResponse( | 87 static bool DecodePolicyResponse( |
80 const em::CloudPolicyResponse& policy_response, | 88 const em::CloudPolicyResponse& policy_response, |
81 PolicyMap* mandatory, | 89 PolicyMap* mandatory, |
82 PolicyMap* recommended, | 90 PolicyMap* recommended, |
83 base::Time* timestamp); | 91 base::Time* timestamp); |
(...skipping 15 matching lines...) Expand all Loading... | |
99 static Value* DecodeValue(const em::GenericValue& value); | 107 static Value* DecodeValue(const em::GenericValue& value); |
100 | 108 |
101 // Decodes a policy message and returns it in Value representation. Ownership | 109 // Decodes a policy message and returns it in Value representation. Ownership |
102 // of the returned dictionary is transferred to the caller. | 110 // of the returned dictionary is transferred to the caller. |
103 static DictionaryValue* DecodeDevicePolicy( | 111 static DictionaryValue* DecodeDevicePolicy( |
104 const em::DevicePolicyResponse& response); | 112 const em::DevicePolicyResponse& response); |
105 | 113 |
106 // The file in which we store a cached version of the policy information. | 114 // The file in which we store a cached version of the policy information. |
107 const FilePath backing_file_path_; | 115 const FilePath backing_file_path_; |
108 | 116 |
109 // Protects both |mandatory_policy_| and |recommended_policy_| as well as | |
110 // |device_policy_|. | |
111 base::Lock lock_; | |
112 | |
113 // Policy key-value information. | 117 // Policy key-value information. |
114 PolicyMap mandatory_policy_; | 118 PolicyMap mandatory_policy_; |
115 PolicyMap recommended_policy_; | 119 PolicyMap recommended_policy_; |
116 scoped_ptr<DictionaryValue> device_policy_; | 120 scoped_ptr<DictionaryValue> device_policy_; |
117 | 121 |
118 // Tracks whether the store received a SetPolicy() call, which overrides any | 122 // Whether initialization has been completed. This is the case when we have |
119 // information loaded from the file. | 123 // valid policy, learned that the device is unmanaged or ran into |
120 bool fresh_policy_; | 124 // unrecoverable errors. |
125 bool initialization_complete_; | |
121 | 126 |
127 // Whether the the server has indicated this device is unmanaged. | |
122 bool is_unmanaged_; | 128 bool is_unmanaged_; |
123 | 129 |
124 // Tracks whether the cache currently stores |device_policy_| that should be | 130 // Tracks whether the cache currently stores |device_policy_| that should be |
125 // given preference over |mandatory_policy_| and |recommended_policy_|. | 131 // given preference over |mandatory_policy_| and |recommended_policy_|. |
126 bool has_device_policy_; | 132 bool has_device_policy_; |
127 | 133 |
128 // The time at which the policy was last refreshed. | 134 // The time at which the policy was last refreshed. |
129 base::Time last_policy_refresh_time_; | 135 base::Time last_policy_refresh_time_; |
136 | |
137 // Policy providers. | |
138 scoped_ptr<ConfigurationPolicyProvider> managed_policy_provider_; | |
139 scoped_ptr<ConfigurationPolicyProvider> recommended_policy_provider_; | |
140 | |
141 // Provider observers that are registered with this cache's providers. | |
142 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; | |
Mattias Nissler (ping if slow)
2011/02/21 14:39:13
DISALLOW_COPY_AND_ASSIGN
Jakob Kummerow
2011/02/22 10:02:33
Done.
| |
130 }; | 143 }; |
131 | 144 |
132 } // namespace policy | 145 } // namespace policy |
133 | 146 |
134 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ | 147 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_ |
OLD | NEW |