| 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_DEVICE_MANAGEMENT_POLICY_CACHE_H_ | |
| 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_CACHE_H_ | |
| 7 | |
| 8 #include "base/file_path.h" | |
| 9 #include "base/gtest_prod_util.h" | |
| 10 #include "base/ref_counted.h" | |
| 11 #include "base/scoped_ptr.h" | |
| 12 #include "base/synchronization/lock.h" | |
| 13 #include "base/time.h" | |
| 14 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | |
| 15 | |
| 16 class DictionaryValue; | |
| 17 class Value; | |
| 18 | |
| 19 namespace policy { | |
| 20 | |
| 21 namespace em = enterprise_management; | |
| 22 | |
| 23 // 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 // to the service directly, but receives updated policy information through | |
| 26 // SetPolicy() calls, which is then persisted and decoded into the internal | |
| 27 // Value representation chrome uses. | |
| 28 class DeviceManagementPolicyCache { | |
| 29 public: | |
| 30 explicit DeviceManagementPolicyCache(const FilePath& backing_file_path); | |
| 31 ~DeviceManagementPolicyCache(); | |
| 32 | |
| 33 // Loads policy information from the backing file. Non-existing or erroneous | |
| 34 // cache files are ignored. | |
| 35 void LoadPolicyFromFile(); | |
| 36 | |
| 37 // Resets the policy information. Returns true if the new policy is different | |
| 38 // from the previously stored policy. | |
| 39 bool SetPolicy(const em::DevicePolicyResponse& policy); | |
| 40 | |
| 41 // Gets the policy information. Ownership of the return value is transferred | |
| 42 // to the caller. | |
| 43 DictionaryValue* GetPolicy(); | |
| 44 | |
| 45 void SetDeviceUnmanaged(); | |
| 46 bool is_device_unmanaged() const { | |
| 47 return is_device_unmanaged_; | |
| 48 } | |
| 49 | |
| 50 // Returns the time as which the policy was last fetched. | |
| 51 base::Time last_policy_refresh_time() const { | |
| 52 return last_policy_refresh_time_; | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 friend class DeviceManagementPolicyCacheDecodeTest; | |
| 57 FRIEND_TEST_ALL_PREFIXES(DeviceManagementPolicyCacheDecodeTest, DecodePolicy); | |
| 58 | |
| 59 // Decodes an int64 value. Checks whether the passed value fits the numeric | |
| 60 // limits of the value representation. Returns a value (ownership is | |
| 61 // transferred to the caller) on success, NULL on failure. | |
| 62 static Value* DecodeIntegerValue(google::protobuf::int64 value); | |
| 63 | |
| 64 // Decode a GenericValue message to the Value representation used internally. | |
| 65 // Returns NULL if |value| is invalid (i.e. contains no actual value). | |
| 66 static Value* DecodeValue(const em::GenericValue& value); | |
| 67 | |
| 68 // Decodes a policy message and returns it in Value representation. Ownership | |
| 69 // of the returned dictionary is transferred to the caller. | |
| 70 static DictionaryValue* DecodePolicy( | |
| 71 const em::DevicePolicyResponse& response); | |
| 72 | |
| 73 // The file in which we store a cached version of the policy information. | |
| 74 const FilePath backing_file_path_; | |
| 75 | |
| 76 // Protects |policy_|. | |
| 77 base::Lock lock_; | |
| 78 | |
| 79 // Policy key-value information. | |
| 80 scoped_ptr<DictionaryValue> policy_; | |
| 81 | |
| 82 // Tracks whether the store received a SetPolicy() call, which overrides any | |
| 83 // information loaded from the file. | |
| 84 bool fresh_policy_; | |
| 85 | |
| 86 bool is_device_unmanaged_; | |
| 87 | |
| 88 // The time at which the policy was last refreshed. | |
| 89 base::Time last_policy_refresh_time_; | |
| 90 }; | |
| 91 | |
| 92 } // namespace policy | |
| 93 | |
| 94 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_CACHE_H_ | |
| OLD | NEW |