| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_POLICY_CACHE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ |
| 6 #define CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ | 6 #define CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 9 #include "chrome/browser/chromeos/settings/signed_settings.h" |
| 10 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 10 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
| 11 | 11 |
| 12 namespace chromeos { |
| 13 class SignedSettingsHelper; |
| 14 } // namespace chromeos |
| 15 |
| 16 namespace enterprise_management { |
| 17 class ChromeDeviceSettingsProto; |
| 18 class PolicyData; |
| 19 class PolicyFetchResponse; |
| 20 } // namespace enterprise_management |
| 21 |
| 12 namespace policy { | 22 namespace policy { |
| 13 | 23 |
| 14 class CloudPolicyDataStore; | 24 class CloudPolicyDataStore; |
| 15 class EnterpriseInstallAttributes; | 25 class EnterpriseInstallAttributes; |
| 16 class PolicyMap; | 26 class PolicyMap; |
| 17 | 27 |
| 18 // CloudPolicyCacheBase implementation that persists policy information | 28 // CloudPolicyCacheBase implementation that persists policy information |
| 19 // to ChromeOS' session manager (via DeviceSettingsService). | 29 // to ChromeOS' session manager (via SignedSettingsHelper). |
| 20 class DevicePolicyCache : public CloudPolicyCacheBase, | 30 class DevicePolicyCache : public CloudPolicyCacheBase { |
| 21 public chromeos::DeviceSettingsService::Observer { | |
| 22 public: | 31 public: |
| 23 DevicePolicyCache(CloudPolicyDataStore* data_store, | 32 DevicePolicyCache(CloudPolicyDataStore* data_store, |
| 24 EnterpriseInstallAttributes* install_attributes); | 33 EnterpriseInstallAttributes* install_attributes); |
| 25 virtual ~DevicePolicyCache(); | 34 virtual ~DevicePolicyCache(); |
| 26 | 35 |
| 27 // CloudPolicyCacheBase implementation: | 36 // CloudPolicyCacheBase implementation: |
| 28 virtual void Load() OVERRIDE; | 37 virtual void Load() OVERRIDE; |
| 29 virtual bool SetPolicy( | 38 virtual bool SetPolicy( |
| 30 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; | 39 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; |
| 31 virtual void SetUnmanaged() OVERRIDE; | 40 virtual void SetUnmanaged() OVERRIDE; |
| 32 virtual void SetFetchingDone() OVERRIDE; | 41 virtual void SetFetchingDone() OVERRIDE; |
| 33 | 42 |
| 34 // DeviceSettingsService::Observer implementation: | 43 void OnRetrievePolicyCompleted( |
| 35 virtual void OwnershipStatusChanged() OVERRIDE; | 44 chromeos::SignedSettings::ReturnCode code, |
| 36 virtual void DeviceSettingsUpdated() OVERRIDE; | 45 const enterprise_management::PolicyFetchResponse& policy); |
| 37 | 46 |
| 38 private: | 47 private: |
| 39 friend class DevicePolicyCacheTest; | 48 friend class DevicePolicyCacheTest; |
| 40 friend class DevicePolicyCacheTestHelper; | 49 friend class DevicePolicyCacheTestHelper; |
| 41 | 50 |
| 42 // Alternate c'tor allowing tests to mock out the DeviceSettingsService | 51 // Alternate c'tor allowing tests to mock out the SignedSettingsHelper |
| 43 // singleton. | 52 // singleton. |
| 44 DevicePolicyCache( | 53 DevicePolicyCache( |
| 45 CloudPolicyDataStore* data_store, | 54 CloudPolicyDataStore* data_store, |
| 46 EnterpriseInstallAttributes* install_attributes, | 55 EnterpriseInstallAttributes* install_attributes, |
| 47 chromeos::DeviceSettingsService* device_settings_service); | 56 chromeos::SignedSettingsHelper* signed_settings_helper); |
| 48 | 57 |
| 49 // CloudPolicyCacheBase implementation: | 58 // CloudPolicyCacheBase implementation: |
| 50 virtual bool DecodePolicyData( | 59 virtual bool DecodePolicyData( |
| 51 const enterprise_management::PolicyData& policy_data, | 60 const enterprise_management::PolicyData& policy_data, |
| 52 PolicyMap* policies) OVERRIDE; | 61 PolicyMap* policies) OVERRIDE; |
| 53 | 62 |
| 54 // Handles completion of policy store operations. | 63 void PolicyStoreOpCompleted(chromeos::SignedSettings::ReturnCode code); |
| 55 void PolicyStoreOpCompleted(); | |
| 56 | 64 |
| 57 // Checks with immutable attributes whether this is an enterprise device and | 65 // Checks with immutable attributes whether this is an enterprise device and |
| 58 // read the registration user if this is the case. | 66 // read the registration user if this is the case. |
| 59 void CheckImmutableAttributes(); | 67 void CheckImmutableAttributes(); |
| 60 | 68 |
| 61 // Tries to install the initial device policy retrieved from signed settings. | 69 // Tries to install the initial device policy retrieved from signed settings. |
| 62 // Fills in |device_token| if it could be extracted from the loaded protobuf. | 70 // Fills in |device_token| if it could be extracted from the loaded protobuf. |
| 63 void InstallInitialPolicy( | 71 void InstallInitialPolicy( |
| 64 chromeos::DeviceSettingsService::Status status, | 72 chromeos::SignedSettings::ReturnCode code, |
| 65 const enterprise_management::PolicyData* policy_data, | 73 const enterprise_management::PolicyFetchResponse& policy, |
| 66 std::string* device_token); | 74 std::string* device_token); |
| 67 | 75 |
| 68 // Ensures that CrosSettings has established trust on the reporting prefs and | 76 // Ensures that CrosSettings has established trust on the reporting prefs and |
| 69 // publishes the |device_token| loaded from the cache. It's important that we | 77 // publishes the |device_token| loaded from the cache. It's important that we |
| 70 // have fully-initialized device settings s.t. device status uploads get the | 78 // have fully-initialized device settings s.t. device status uploads get the |
| 71 // correct reporting policy flags. | 79 // correct reporting policy flags. |
| 72 void SetTokenAndFlagReady(const std::string& device_token); | 80 void SetTokenAndFlagReady(const std::string& device_token); |
| 73 | 81 |
| 74 // Checks whether a policy fetch is pending and sends out a notification if | 82 // Checks whether a policy fetch is pending and sends out a notification if |
| 75 // that is the case. | 83 // that is the case. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 97 static void DecodeAutoUpdatePolicies( | 105 static void DecodeAutoUpdatePolicies( |
| 98 const enterprise_management::ChromeDeviceSettingsProto& policy, | 106 const enterprise_management::ChromeDeviceSettingsProto& policy, |
| 99 PolicyMap* policies); | 107 PolicyMap* policies); |
| 100 static void DecodeGenericPolicies( | 108 static void DecodeGenericPolicies( |
| 101 const enterprise_management::ChromeDeviceSettingsProto& policy, | 109 const enterprise_management::ChromeDeviceSettingsProto& policy, |
| 102 PolicyMap* policies); | 110 PolicyMap* policies); |
| 103 | 111 |
| 104 CloudPolicyDataStore* data_store_; | 112 CloudPolicyDataStore* data_store_; |
| 105 EnterpriseInstallAttributes* install_attributes_; | 113 EnterpriseInstallAttributes* install_attributes_; |
| 106 | 114 |
| 107 chromeos::DeviceSettingsService* device_settings_service_; | 115 chromeos::SignedSettingsHelper* signed_settings_helper_; |
| 108 | 116 |
| 109 base::WeakPtrFactory<DevicePolicyCache> weak_ptr_factory_; | 117 base::WeakPtrFactory<DevicePolicyCache> weak_ptr_factory_; |
| 110 | 118 |
| 111 bool policy_fetch_pending_; | 119 bool policy_fetch_pending_; |
| 112 | 120 |
| 113 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCache); | 121 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCache); |
| 114 }; | 122 }; |
| 115 | 123 |
| 116 } // namespace policy | 124 } // namespace policy |
| 117 | 125 |
| 118 #endif // CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ | 126 #endif // CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ |
| OLD | NEW |