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_CONFIGURATION_POLICY_READER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_READER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_READER_H_ | 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_READER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/observer_list.h" | |
| 9 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/policy/configuration_policy_provider.h" | 12 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 12 #include "chrome/browser/policy/policy_status_info.h" | 13 #include "chrome/browser/policy/policy_status_info.h" |
| 13 | 14 |
| 14 namespace policy { | 15 namespace policy { |
| 15 | 16 |
| 16 class ConfigurationPolicyStatusKeeper; | 17 class ConfigurationPolicyStatusKeeper; |
| 17 | 18 |
| 18 // This class reads policy information from a ConfigurationPolicyProvider in | 19 // This class reads policy information from a ConfigurationPolicyProvider in |
| 19 // order to determine the status of a policy (this includes its value and | 20 // order to determine the status of a policy (this includes its value and |
| 20 // whether it could be enforced on the client or not), as required by the | 21 // whether it could be enforced on the client or not), as required by the |
| 21 // about:policy UI. | 22 // about:policy UI. |
| 22 class ConfigurationPolicyReader : public ConfigurationPolicyProvider::Observer { | 23 class ConfigurationPolicyReader : public ConfigurationPolicyProvider::Observer { |
| 23 public: | 24 public: |
| 25 class Observer { | |
| 26 public: | |
| 27 virtual ~Observer() {} | |
| 28 virtual void OnPolicyValuesChanged() = 0; | |
| 29 }; | |
| 30 | |
| 24 ConfigurationPolicyReader(ConfigurationPolicyProvider* provider, | 31 ConfigurationPolicyReader(ConfigurationPolicyProvider* provider, |
| 25 PolicyStatusInfo::PolicyLevel policy_level); | 32 PolicyStatusInfo::PolicyLevel policy_level); |
| 26 virtual ~ConfigurationPolicyReader(); | 33 virtual ~ConfigurationPolicyReader(); |
| 27 | 34 |
| 28 // ConfigurationPolicyProvider::Observer methods: | 35 // ConfigurationPolicyProvider::Observer methods: |
| 29 virtual void OnUpdatePolicy(); | 36 virtual void OnUpdatePolicy(); |
| 30 virtual void OnProviderGoingAway(); | 37 virtual void OnProviderGoingAway(); |
| 31 | 38 |
| 39 // Methods to handle Observers. | |
| 40 void AddObserver(Observer* observer); | |
| 41 void RemoveObserver(Observer* observer); | |
| 42 | |
| 32 // Creates a ConfigurationPolicyReader that reads managed platform policy. | 43 // Creates a ConfigurationPolicyReader that reads managed platform policy. |
| 33 static ConfigurationPolicyReader* | 44 static ConfigurationPolicyReader* CreateManagedPlatformPolicyReader(); |
| 34 CreateManagedPlatformPolicyReader(); | |
| 35 | 45 |
| 36 // Creates a ConfigurationPolicyReader that reads managed cloud policy. | 46 // Creates a ConfigurationPolicyReader that reads managed cloud policy. |
| 37 static ConfigurationPolicyReader* | 47 static ConfigurationPolicyReader* CreateManagedCloudPolicyReader(); |
| 38 CreateManagedCloudPolicyReader(); | |
| 39 | 48 |
| 40 // Creates a ConfigurationPolicyReader that reads recommended platform policy. | 49 // Creates a ConfigurationPolicyReader that reads recommended platform policy. |
| 41 static ConfigurationPolicyReader* | 50 static ConfigurationPolicyReader* CreateRecommendedPlatformPolicyReader(); |
| 42 CreateRecommendedPlatformPolicyReader(); | |
| 43 | 51 |
| 44 // Creates a ConfigurationPolicyReader that reads recommended cloud policy. | 52 // Creates a ConfigurationPolicyReader that reads recommended cloud policy. |
| 45 static ConfigurationPolicyReader* | 53 static ConfigurationPolicyReader* CreateRecommendedCloudPolicyReader(); |
| 46 CreateRecommendedCloudPolicyReader(); | |
| 47 | 54 |
| 48 // Returns a pointer to a DictionaryValue object containing policy status | 55 // Returns a pointer to a DictionaryValue object containing policy status |
| 49 // information for the UI. Ownership of the return value is acquired by the | 56 // information for the UI. Ownership of the return value is acquired by the |
| 50 // caller. Returns NULL if the reader is not aware of the given policy. | 57 // caller. Returns NULL if the reader is not aware of the given policy. |
| 51 virtual DictionaryValue* | 58 virtual DictionaryValue* |
| 52 GetPolicyStatus(ConfigurationPolicyType policy) const; | 59 GetPolicyStatus(ConfigurationPolicyType policy) const; |
| 53 | 60 |
| 54 private: | 61 private: |
| 55 friend class MockConfigurationPolicyReader; | 62 friend class MockConfigurationPolicyReader; |
| 56 | 63 |
| 57 // Only used in tests. | 64 // Only used in tests. |
| 58 ConfigurationPolicyReader(); | 65 ConfigurationPolicyReader(); |
| 59 | 66 |
| 60 // Updates the policy information held in this reader. This is called when | 67 // Updates the policy information held in this reader. This is called when |
| 61 // the ConfigurationPolicyProvider is updated. | 68 // the ConfigurationPolicyProvider is updated. |
| 62 void Refresh(); | 69 void Refresh(); |
| 63 | 70 |
| 64 // The policy provider from which policy settings are read. | 71 // The policy provider from which policy settings are read. |
| 65 ConfigurationPolicyProvider* provider_; | 72 ConfigurationPolicyProvider* provider_; |
| 66 | 73 |
| 67 // Whether this ConfigurationPolicyReader contains managed policies. | 74 // Whether this ConfigurationPolicyReader contains managed policies. |
| 68 PolicyStatusInfo::PolicyLevel policy_level_; | 75 PolicyStatusInfo::PolicyLevel policy_level_; |
| 69 | 76 |
| 70 // Current policy status. | 77 // Current policy status. |
| 71 scoped_ptr<ConfigurationPolicyStatusKeeper> policy_keeper_; | 78 scoped_ptr<ConfigurationPolicyStatusKeeper> policy_keeper_; |
| 72 | 79 |
| 80 ObserverList<Observer, true> observers_; | |
| 81 | |
| 73 ConfigurationPolicyObserverRegistrar registrar_; | 82 ConfigurationPolicyObserverRegistrar registrar_; |
| 74 | 83 |
| 75 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyReader); | 84 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyReader); |
| 76 }; | 85 }; |
| 77 | 86 |
| 78 // This class combines the policy information from different | 87 // This class combines the policy information from different |
| 79 // ConfigurationPolicyReaders into a single list of policy information that the | 88 // ConfigurationPolicyReaders into a single list of policy information that the |
| 80 // about:policy UI can display. | 89 // about:policy UI can display. |
| 81 class PolicyStatus { | 90 class PolicyStatus { |
| 82 public: | 91 public: |
| 92 typedef ConfigurationPolicyReader::Observer Observer; | |
| 83 PolicyStatus(ConfigurationPolicyReader* managed_platform, | 93 PolicyStatus(ConfigurationPolicyReader* managed_platform, |
| 84 ConfigurationPolicyReader* managed_cloud, | 94 ConfigurationPolicyReader* managed_cloud, |
| 85 ConfigurationPolicyReader* recommended_platform, | 95 ConfigurationPolicyReader* recommended_platform, |
| 86 ConfigurationPolicyReader* recommended_cloud); | 96 ConfigurationPolicyReader* recommended_cloud); |
| 87 ~PolicyStatus(); | 97 ~PolicyStatus(); |
| 88 | 98 |
| 99 // Adds an observer to each one of the ConfigurationPolicyReaders. | |
| 100 void AddObserver(Observer* observer) const; | |
| 101 | |
| 102 // Removes an observer to each one of the ConfigurationPolicyReaders. | |
|
Mattias Nissler (ping if slow)
2011/09/02 11:16:09
s/to/from/
simo
2011/09/02 15:32:02
Done.
| |
| 103 void RemoveObserver(Observer* observer) const; | |
| 104 | |
| 89 // Returns a ListValue pointer containing the status information of all | 105 // Returns a ListValue pointer containing the status information of all |
| 90 // policies supported by the client. |any_policies_sent| is set to true if | 106 // policies supported by the client. |any_policies_sent| is set to true if |
| 91 // there are policies in the list that were sent by a provider, otherwise | 107 // there are policies in the list that were sent by a provider, otherwise |
| 92 // it is set to false. This is for the about:policy UI to display. | 108 // it is set tof alse. This is for the about:policy UI to display. |
|
Mattias Nissler (ping if slow)
2011/09/02 11:16:09
tof alse? sounds like a nordic actor.
simo
2011/09/02 15:32:02
Done.
| |
| 93 ListValue* GetPolicyStatusList(bool* any_policies_sent) const; | 109 ListValue* GetPolicyStatusList(bool* any_policies_sent) const; |
| 94 | 110 |
| 95 // Returns a string16 containing the actual name of the policy corresponding | 111 // Returns a string16 containing the actual name of the policy corresponding |
| 96 // to |policy_type|. Returns an empty string if there is no such policy_type | 112 // to |policy_type|. Returns an empty string if there is no such policy_type |
| 97 // among the policies supported by the client. | 113 // among the policies supported by the client. |
| 98 static string16 GetPolicyName(ConfigurationPolicyType policy_type); | 114 static string16 GetPolicyName(ConfigurationPolicyType policy_type); |
| 99 | 115 |
| 100 private: | 116 private: |
| 101 typedef ConfigurationPolicyProvider::PolicyDefinitionList | 117 typedef ConfigurationPolicyProvider::PolicyDefinitionList |
| 102 PolicyDefinitionList; | 118 PolicyDefinitionList; |
| 103 | 119 |
| 104 // Add the policy information for |policy| to the ListValue pointed to be | 120 // Add the policy information for |policy| to the ListValue pointed to be |
| 105 // |list| as it is returned by the different ConfigurationPolicyReader | 121 // |list| as it is returned by the different ConfigurationPolicyReader |
| 106 // objects. Returns true if a policy was added and false otherwise. | 122 // objects. Returns true if a policy was added and false otherwise. |
| 107 bool AddPolicyFromReaders(ConfigurationPolicyType policy, | 123 bool AddPolicyFromReaders(ConfigurationPolicyType policy, |
| 108 ListValue* list) const; | 124 ListValue* list) const; |
| 109 | 125 |
| 110 scoped_ptr<ConfigurationPolicyReader> managed_platform_; | 126 scoped_ptr<ConfigurationPolicyReader> managed_platform_; |
| 111 scoped_ptr<ConfigurationPolicyReader> managed_cloud_; | 127 scoped_ptr<ConfigurationPolicyReader> managed_cloud_; |
| 112 scoped_ptr<ConfigurationPolicyReader> recommended_platform_; | 128 scoped_ptr<ConfigurationPolicyReader> recommended_platform_; |
| 113 scoped_ptr<ConfigurationPolicyReader> recommended_cloud_; | 129 scoped_ptr<ConfigurationPolicyReader> recommended_cloud_; |
| 114 | 130 |
| 115 DISALLOW_COPY_AND_ASSIGN(PolicyStatus); | 131 DISALLOW_COPY_AND_ASSIGN(PolicyStatus); |
| 116 }; | 132 }; |
| 117 | 133 |
| 118 } // namespace policy | 134 } // namespace policy |
| 119 | 135 |
| 120 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_READER_H_ | 136 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_READER_H_ |
| OLD | NEW |