Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/gtest_prod_util.h" | |
| 10 #include "base/observer_list.h" | |
|
Mattias Nissler (ping if slow)
2011/03/29 08:58:39
alphabetize
Jakob Kummerow
2011/03/29 09:33:37
Done.
| |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/threading/non_thread_safe.h" | |
| 13 #include "base/time.h" | |
| 14 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 15 #include "chrome/browser/policy/policy_map.h" | |
| 16 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | |
| 17 | |
| 18 namespace policy { | |
| 19 | |
| 20 class PolicyMap; | |
| 21 | |
| 22 namespace em = enterprise_management; | |
| 23 | |
| 24 // Caches policy information, as set by calls to |SetPolicy()|, persists | |
| 25 // it to disk or session_manager (depending on subclass implementation), | |
| 26 // and makes it available via policy providers. | |
| 27 class CloudPolicyCacheBase : public base::NonThreadSafe { | |
| 28 public: | |
| 29 // Used to distinguish mandatory from recommended policies. | |
| 30 enum PolicyLevel { | |
| 31 // Policy is forced upon the user and should always take effect. | |
| 32 POLICY_LEVEL_MANDATORY, | |
| 33 // The value is just a recommendation that the user may override. | |
| 34 POLICY_LEVEL_RECOMMENDED, | |
| 35 }; | |
| 36 | |
| 37 CloudPolicyCacheBase(); | |
| 38 virtual ~CloudPolicyCacheBase(); | |
| 39 | |
| 40 // Loads persisted policy information. | |
| 41 virtual void Load() = 0; | |
| 42 | |
| 43 // Resets the policy information. | |
| 44 virtual void SetPolicy(const em::PolicyFetchResponse& policy) = 0; | |
| 45 | |
| 46 ConfigurationPolicyProvider* GetManagedPolicyProvider(); | |
| 47 ConfigurationPolicyProvider* GetRecommendedPolicyProvider(); | |
| 48 | |
| 49 virtual void SetUnmanaged() = 0; | |
| 50 bool is_unmanaged() const { | |
| 51 return is_unmanaged_; | |
| 52 } | |
| 53 | |
| 54 // Returns the time at which the policy was last fetched. | |
| 55 base::Time last_policy_refresh_time() const { | |
| 56 return last_policy_refresh_time_; | |
| 57 } | |
| 58 | |
| 59 protected: | |
| 60 // Decodes the given |policy| using |DecodePolicyResponse()|, applies the | |
| 61 // contents to |{mandatory,recommended}_policy_|, and notifies observers. | |
| 62 // |timestamp| returns the timestamp embedded in |policy|, callers can pass | |
| 63 // NULL if they don't care. |check_for_timestamp_validity| tells this method | |
| 64 // to discard policy data with a timestamp from the future. | |
| 65 // Returns true upon success. | |
| 66 bool SetPolicyInternal(const em::PolicyFetchResponse& policy, | |
| 67 base::Time* timestamp, | |
| 68 bool check_for_timestamp_validity); | |
| 69 | |
| 70 void SetUnmanagedInternal(const base::Time& timestamp); | |
| 71 | |
| 72 // Decodes |policy_data|, populating |mandatory| and |recommended| with | |
| 73 // the results. | |
| 74 virtual bool DecodePolicyData(const em::PolicyData& policy_data, | |
| 75 PolicyMap* mandatory, | |
| 76 PolicyMap* recommended) = 0; | |
| 77 | |
| 78 // Decodes a PolicyFetchResponse into two PolicyMaps and a timestamp. | |
| 79 // Also performs verification, returns NULL if any check fails. | |
| 80 bool DecodePolicyResponse( | |
| 81 const em::PolicyFetchResponse& policy_response, | |
|
Mattias Nissler (ping if slow)
2011/03/29 08:58:39
Nit: I think this fits the previous line.
Jakob Kummerow
2011/03/29 09:33:37
Done.
| |
| 82 PolicyMap* mandatory, | |
| 83 PolicyMap* recommended, | |
| 84 base::Time* timestamp); | |
| 85 | |
| 86 // See comment for |initialization_complete_|. | |
| 87 bool initialization_complete() { | |
| 88 return initialization_complete_; | |
| 89 } | |
| 90 | |
| 91 void set_last_policy_refresh_time(base::Time timestamp) { | |
| 92 last_policy_refresh_time_ = timestamp; | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 class CloudPolicyProvider; | |
| 97 | |
| 98 friend class DevicePolicyCacheTest; | |
| 99 friend class UserPolicyCacheTest; | |
| 100 | |
| 101 // Policy key-value information. | |
| 102 PolicyMap mandatory_policy_; | |
| 103 PolicyMap recommended_policy_; | |
| 104 | |
| 105 // Policy providers. | |
| 106 scoped_ptr<ConfigurationPolicyProvider> managed_policy_provider_; | |
| 107 scoped_ptr<ConfigurationPolicyProvider> recommended_policy_provider_; | |
| 108 | |
| 109 // The time at which the policy was last refreshed. Is updated both upon | |
| 110 // successful and unsuccessful refresh attempts. | |
| 111 base::Time last_policy_refresh_time_; | |
| 112 | |
| 113 // Whether initialization has been completed. This is the case when we have | |
| 114 // valid policy, learned that the device is unmanaged or ran into | |
| 115 // unrecoverable errors. | |
| 116 bool initialization_complete_; | |
| 117 | |
| 118 // Whether the the server has indicated this device is unmanaged. | |
| 119 bool is_unmanaged_; | |
| 120 | |
| 121 // Provider observers that are registered with this cache's providers. | |
| 122 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCacheBase); | |
| 125 }; | |
| 126 | |
| 127 } // namespace policy | |
| 128 | |
| 129 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_ | |
| OLD | NEW |