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

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

Issue 6312121: Add initial device policy infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup/compile fixes. Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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_DEVICE_MANAGEMENT_POLICY_CACHE_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_
6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_CACHE_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/observer_list.h"
10 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
11 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
12 #include "base/synchronization/lock.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/browser/policy/configuration_policy_provider.h"
14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 15 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
15 16
16 class DictionaryValue; 17 class DictionaryValue;
17 class Value; 18 class Value;
18 19
19 namespace policy { 20 namespace policy {
20 21
21 namespace em = enterprise_management; 22 namespace em = enterprise_management;
22 23
23 // Keeps the authoritative copy of cloud policy information as read from the 24 // Keeps the authoritative copy of cloud policy information as read from the
24 // persistence file or determined by the policy backend. The cache doesn't talk 25 // persistence file or determined by the policy backend. The cache doesn't talk
25 // to the service directly, but receives updated policy information through 26 // to the service directly, but receives updated policy information through
26 // SetPolicy() calls, which is then persisted and decoded into the internal 27 // SetPolicy() calls, which is then persisted and decoded into the internal
27 // Value representation chrome uses. 28 // Value representation chrome uses.
28 class DeviceManagementPolicyCache { 29 class CloudPolicyCache {
danno 2011/02/04 16:01:33 CloudPolicyOracle? :-)
Jakob Kummerow 2011/02/14 13:50:34 Nope.
29 public: 30 public:
30 explicit DeviceManagementPolicyCache(const FilePath& backing_file_path); 31 // Used to distinguish mandatory from recommended policies.
31 ~DeviceManagementPolicyCache(); 32 enum PolicyLevel {
33 // Policy is forced upon the user and should always take effect.
34 POLICY_LEVEL_MANDATORY,
35 // The value is just a recommendation that the user may override.
36 POLICY_LEVEL_RECOMMENDED,
37 };
38
39 explicit CloudPolicyCache(const FilePath& backing_file_path);
40 ~CloudPolicyCache();
32 41
33 // Loads policy information from the backing file. Non-existing or erroneous 42 // Loads policy information from the backing file. Non-existing or erroneous
34 // cache files are ignored. 43 // cache files are ignored.
35 void LoadPolicyFromFile(); 44 void LoadFromFile();
36 45
37 // Resets the policy information. Returns true if the new policy is different 46 // Resets the policy information. Returns true if the new policy is different
38 // from the previously stored policy. 47 // from the previously stored policy.
39 bool SetPolicy(const em::DevicePolicyResponse& policy); 48 bool SetPolicy(const em::DevicePolicyResponse& policy);
40 49
41 // Gets the policy information. Ownership of the return value is transferred 50 ConfigurationPolicyProvider* GetManagedPolicyProvider();
42 // to the caller. 51 ConfigurationPolicyProvider* GetRecommendedPolicyProvider();
43 DictionaryValue* GetPolicy();
44 52
45 void SetDeviceUnmanaged(); 53 void SetDeviceUnmanaged();
46 bool is_device_unmanaged() const { 54 bool is_device_unmanaged() const {
47 return is_device_unmanaged_; 55 return is_device_unmanaged_;
48 } 56 }
49 57
50 // Returns the time as which the policy was last fetched. 58 // Returns the time as which the policy was last fetched.
51 base::Time last_policy_refresh_time() const { 59 base::Time last_policy_refresh_time() const {
52 return last_policy_refresh_time_; 60 return last_policy_refresh_time_;
53 } 61 }
54 62
55 private: 63 private:
56 friend class DeviceManagementPolicyCacheDecodeTest; 64 class CloudPolicyProvider;
57 FRIEND_TEST_ALL_PREFIXES(DeviceManagementPolicyCacheDecodeTest, DecodePolicy); 65
66 friend class CloudPolicyCacheDecodeTest;
67 FRIEND_TEST_ALL_PREFIXES(CloudPolicyCacheDecodeTest, DecodePolicy);
58 68
59 // Decodes an int64 value. Checks whether the passed value fits the numeric 69 // Decodes an int64 value. Checks whether the passed value fits the numeric
60 // limits of the value representation. Returns a value (ownership is 70 // limits of the value representation. Returns a value (ownership is
61 // transferred to the caller) on success, NULL on failure. 71 // transferred to the caller) on success, NULL on failure.
62 static Value* DecodeIntegerValue(google::protobuf::int64 value); 72 static Value* DecodeIntegerValue(google::protobuf::int64 value);
63 73
64 // Decode a GenericValue message to the Value representation used internally. 74 // Decode a GenericValue message to the Value representation used internally.
65 // Returns NULL if |value| is invalid (i.e. contains no actual value). 75 // Returns NULL if |value| is invalid (i.e. contains no actual value).
66 static Value* DecodeValue(const em::GenericValue& value); 76 static Value* DecodeValue(const em::GenericValue& value);
67 77
68 // Decodes a policy message and returns it in Value representation. Ownership 78 // Decodes a policy message and returns it in Value representation. Ownership
69 // of the returned dictionary is transferred to the caller. 79 // of the returned dictionary is transferred to the caller.
70 static DictionaryValue* DecodePolicy( 80 static DictionaryValue* DecodePolicy(
71 const em::DevicePolicyResponse& response); 81 const em::DevicePolicyResponse& response);
72 82
73 // The file in which we store a cached version of the policy information. 83 // The file in which we store a cached version of the policy information.
74 const FilePath backing_file_path_; 84 const FilePath backing_file_path_;
75 85
76 // Protects |policy_|.
77 base::Lock lock_;
78
79 // Policy key-value information. 86 // Policy key-value information.
80 scoped_ptr<DictionaryValue> policy_; 87 scoped_ptr<DictionaryValue> policy_;
81 88
82 // Tracks whether the store received a SetPolicy() call, which overrides any 89 // Whether initialization has been completed. This is the case when we have
83 // information loaded from the file. 90 // valid policy, learned that the device is unmanaged or ran into
84 bool fresh_policy_; 91 // unrecoverrable errors.
92 bool initialization_complete_;
85 93
94 // Whether the the server has indicated this device is unmanaged.
86 bool is_device_unmanaged_; 95 bool is_device_unmanaged_;
87 96
88 // The time at which the policy was last refreshed. 97 // The time at which the policy was last refreshed.
89 base::Time last_policy_refresh_time_; 98 base::Time last_policy_refresh_time_;
99
100 // Policy providers.
101 scoped_ptr<ConfigurationPolicyProvider> managed_policy_provider_;
102 scoped_ptr<ConfigurationPolicyProvider> recommended_policy_provider_;
103
104 // Provider observers that are registered with this cache's providers.
105 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
90 }; 106 };
91 107
92 } // namespace policy 108 } // namespace policy
93 109
94 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_CACHE_H_ 110 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698