| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback_forward.h" | |
| 14 #include "chrome/browser/chromeos/cros_settings_provider.h" | |
| 15 #include "chrome/browser/chromeos/login/ownership_service.h" | |
| 16 #include "chrome/browser/chromeos/signed_settings_migration_helper.h" | |
| 17 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | |
| 18 #include "chrome/browser/prefs/pref_value_map.h" | |
| 19 #include "content/public/browser/notification_registrar.h" | |
| 20 | |
| 21 namespace base { | |
| 22 class Value; | |
| 23 } | |
| 24 | |
| 25 namespace enterprise_management { | |
| 26 class ChromeDeviceSettingsProto; | |
| 27 } // namespace enterprise_management | |
| 28 | |
| 29 namespace chromeos { | |
| 30 | |
| 31 // CrosSettingsProvider implementation that works with SignedSettings. | |
| 32 class DeviceSettingsProvider : public CrosSettingsProvider, | |
| 33 public content::NotificationObserver { | |
| 34 public: | |
| 35 DeviceSettingsProvider(const NotifyObserversCallback& notify_cb, | |
| 36 SignedSettingsHelper* signed_settings_helper); | |
| 37 virtual ~DeviceSettingsProvider(); | |
| 38 | |
| 39 // CrosSettingsProvider implementation. | |
| 40 virtual const base::Value* Get(const std::string& path) const OVERRIDE; | |
| 41 virtual TrustedStatus PrepareTrustedValues( | |
| 42 const base::Closure& callback) OVERRIDE; | |
| 43 virtual bool HandlesSetting(const std::string& path) const OVERRIDE; | |
| 44 virtual void Reload() OVERRIDE; | |
| 45 | |
| 46 private: | |
| 47 // CrosSettingsProvider implementation: | |
| 48 virtual void DoSet(const std::string& path, | |
| 49 const base::Value& value) OVERRIDE; | |
| 50 | |
| 51 // content::NotificationObserver implementation: | |
| 52 virtual void Observe(int type, | |
| 53 const content::NotificationSource& source, | |
| 54 const content::NotificationDetails& details) OVERRIDE; | |
| 55 | |
| 56 const enterprise_management::PolicyData policy() const; | |
| 57 | |
| 58 // Populates in-memory cache from the local_state cache that is used to store | |
| 59 // signed settings before the device is owned and to speed up policy | |
| 60 // availability before the policy blob is fetched on boot. | |
| 61 void RetrieveCachedData(); | |
| 62 | |
| 63 // Stores a value from the |pending_changes_| queue in the signed settings. | |
| 64 // If the device is not owned yet the data ends up only in the local_state | |
| 65 // cache and is serialized once ownership is acquired. | |
| 66 void SetInPolicy(); | |
| 67 | |
| 68 // Finalizes stores to the policy file if the cache is dirty. | |
| 69 void FinishSetInPolicy( | |
| 70 SignedSettings::ReturnCode code, | |
| 71 const enterprise_management::PolicyFetchResponse& policy); | |
| 72 | |
| 73 // Decode the various groups of policies. | |
| 74 void DecodeLoginPolicies( | |
| 75 const enterprise_management::ChromeDeviceSettingsProto& policy, | |
| 76 PrefValueMap* new_values_cache) const; | |
| 77 void DecodeKioskPolicies( | |
| 78 const enterprise_management::ChromeDeviceSettingsProto& policy, | |
| 79 PrefValueMap* new_values_cache) const; | |
| 80 void DecodeNetworkPolicies( | |
| 81 const enterprise_management::ChromeDeviceSettingsProto& policy, | |
| 82 PrefValueMap* new_values_cache) const; | |
| 83 void DecodeReportingPolicies( | |
| 84 const enterprise_management::ChromeDeviceSettingsProto& policy, | |
| 85 PrefValueMap* new_values_cache) const; | |
| 86 void DecodeGenericPolicies( | |
| 87 const enterprise_management::ChromeDeviceSettingsProto& policy, | |
| 88 PrefValueMap* new_values_cache) const; | |
| 89 | |
| 90 // Parses the policy cache and fills the cache of base::Value objects. | |
| 91 void UpdateValuesCache(); | |
| 92 | |
| 93 // Applies the metrics policy and if not set migrates the legacy file. | |
| 94 void ApplyMetricsSetting(bool use_file, bool new_value) const; | |
| 95 | |
| 96 // Applies the data roaming policy. | |
| 97 void ApplyRoamingSetting(bool new_value) const; | |
| 98 | |
| 99 // Applies any changes of the policies that are not handled by the respective | |
| 100 // subsystems. | |
| 101 void ApplySideEffects() const; | |
| 102 | |
| 103 // In case of missing policy blob we should verify if this is upgrade of | |
| 104 // machine owned from pre version 12 OS and the user never touched the device | |
| 105 // settings. In this case revert to defaults and let people in until the owner | |
| 106 // comes and changes that. | |
| 107 bool MitigateMissingPolicy(); | |
| 108 | |
| 109 // Called right before boolean property is changed. | |
| 110 void OnBooleanPropertyChange(const std::string& path, bool new_value); | |
| 111 | |
| 112 // Checks if the current cache value can be trusted for being representative | |
| 113 // for the disk cache. | |
| 114 TrustedStatus RequestTrustedEntity(); | |
| 115 | |
| 116 // Called right after signed value was checked. | |
| 117 void OnPropertyRetrieve(const std::string& path, | |
| 118 const base::Value* value, | |
| 119 bool use_default_value); | |
| 120 | |
| 121 // Callback of StorePolicyOp for ordinary policy stores. | |
| 122 void OnStorePolicyCompleted(SignedSettings::ReturnCode code); | |
| 123 | |
| 124 // Callback of RetrievePolicyOp for ordinary policy [re]loads. | |
| 125 void OnRetrievePolicyCompleted( | |
| 126 SignedSettings::ReturnCode code, | |
| 127 const enterprise_management::PolicyFetchResponse& policy); | |
| 128 | |
| 129 // These setters are for test use only. | |
| 130 void set_ownership_status(OwnershipService::Status status) { | |
| 131 ownership_status_ = status; | |
| 132 } | |
| 133 void set_trusted_status(TrustedStatus status) { | |
| 134 trusted_status_ = status; | |
| 135 } | |
| 136 void set_retries_left(int retries) { | |
| 137 retries_left_ = retries; | |
| 138 } | |
| 139 | |
| 140 // Pending callbacks that need to be invoked after settings verification. | |
| 141 std::vector<base::Closure> callbacks_; | |
| 142 | |
| 143 SignedSettingsHelper* signed_settings_helper_; | |
| 144 OwnershipService::Status ownership_status_; | |
| 145 mutable scoped_ptr<SignedSettingsMigrationHelper> migration_helper_; | |
| 146 | |
| 147 content::NotificationRegistrar registrar_; | |
| 148 | |
| 149 // In order to guard against occasional failure to fetch a property | |
| 150 // we allow for some number of retries. | |
| 151 int retries_left_; | |
| 152 | |
| 153 enterprise_management::PolicyData policy_; | |
| 154 TrustedStatus trusted_status_; | |
| 155 | |
| 156 PrefValueMap values_cache_; | |
| 157 | |
| 158 // This is a queue for set requests, because those need to be sequential. | |
| 159 typedef std::pair<std::string, base::Value*> PendingQueueElement; | |
| 160 std::vector<PendingQueueElement> pending_changes_; | |
| 161 | |
| 162 friend class DeviceSettingsProviderTest; | |
| 163 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, | |
| 164 InitializationTestUnowned); | |
| 165 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, | |
| 166 PolicyFailedPermanentlyNotification); | |
| 167 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, PolicyLoadNotification); | |
| 168 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider); | |
| 169 }; | |
| 170 | |
| 171 } // namespace chromeos | |
| 172 | |
| 173 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ | |
| OLD | NEW |