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