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