OLD | NEW |
(Empty) | |
| 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 |
| 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 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
| 14 #include "base/hash_tables.h" |
| 15 #include "chrome/browser/chromeos/cros_settings_provider.h" |
| 16 #include "chrome/browser/chromeos/login/signed_settings_helper.h" |
| 17 #include "chrome/browser/chromeos/signed_settings_migration_helper.h" |
| 18 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 19 #include "content/public/browser/notification_registrar.h" |
| 20 |
| 21 namespace em = enterprise_management; |
| 22 |
| 23 class PrefService; |
| 24 |
| 25 namespace base { |
| 26 class ListValue; |
| 27 } |
| 28 |
| 29 namespace chromeos { |
| 30 |
| 31 class OwnershipService; |
| 32 |
| 33 // CrosSettingsProvider implementation that works with SignedSettings. |
| 34 class DeviceSettingsProvider : public CrosSettingsProvider, |
| 35 public content::NotificationObserver { |
| 36 public: |
| 37 DeviceSettingsProvider(); |
| 38 virtual ~DeviceSettingsProvider(); |
| 39 |
| 40 // CrosSettingsProvider implementation. |
| 41 virtual const base::Value* Get(const std::string& path) const OVERRIDE; |
| 42 virtual bool GetTrusted(const std::string& path, |
| 43 const base::Closure& callback) OVERRIDE; |
| 44 virtual bool HandlesSetting(const std::string& path) const OVERRIDE; |
| 45 virtual void Reload() OVERRIDE; |
| 46 |
| 47 private: |
| 48 // CrosSettingsProvider implementation: |
| 49 virtual void DoSet(const std::string& path, |
| 50 const base::Value& value) OVERRIDE; |
| 51 |
| 52 // content::NotificationObserver implementation: |
| 53 virtual void Observe(int type, |
| 54 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) OVERRIDE; |
| 56 |
| 57 const em::PolicyData policy() const; |
| 58 |
| 59 // Populates in-memory cache from the local_state cache that is used to store |
| 60 // signed settings before the device is owned and to speed up policy |
| 61 // availability before the policy blob is fetched on boot. |
| 62 void RetrieveCachedData(); |
| 63 |
| 64 // Stores a value in the signed settings. If the device is not owned yet the |
| 65 // data ends up only in the local_state cache and is serialized once ownership |
| 66 // is acquired. |
| 67 void SetInPolicy(const std::string& prop, const base::Value& value); |
| 68 |
| 69 // Finalizes stores to the policy file if the cache is dirty. |
| 70 void FinishSetInPolicy(const std::string& prop, |
| 71 const base::Value* value, |
| 72 SignedSettings::ReturnCode code, |
| 73 const em::PolicyFetchResponse& policy); |
| 74 |
| 75 // Parses the policy cache and fills the cache of base::Value objects. |
| 76 void UpdateValuesCache(); |
| 77 |
| 78 // Applies the metrics policy and if not set migrates the legacy file. |
| 79 void ApplyMetricsSetting(bool use_file, bool new_value) const; |
| 80 |
| 81 // Applies the data roaming policy. |
| 82 void ApplyRoamingSetting(bool new_value) const; |
| 83 |
| 84 // Applies any changes of the policies that are not handled by the respective |
| 85 // subsystms. |
| 86 void ApplySideEffects() const; |
| 87 |
| 88 // Called right before boolean property is changed. |
| 89 void OnBooleanPropertyChange(const std::string& path, bool new_value); |
| 90 |
| 91 // Checks if the current cache value can be trusted for being representative |
| 92 // for the disk cache. |
| 93 bool RequestTrustedEntity(); |
| 94 |
| 95 // Called right after signed value was checked. |
| 96 void OnPropertyRetrieve(const std::string& path, |
| 97 const base::Value* value, |
| 98 bool use_default_value); |
| 99 |
| 100 // Callback of StorePolicyOp for ordinary policy stores. |
| 101 void OnStorePolicyCompleted(SignedSettings::ReturnCode code); |
| 102 |
| 103 // Callback of RetrievePolicyOp for ordinary policy [re]loads. |
| 104 void OnRetrievePolicyCompleted(SignedSettings::ReturnCode code, |
| 105 const em::PolicyFetchResponse& policy); |
| 106 |
| 107 // Pending callbacks that need to be invoked after settings verification. |
| 108 std::vector<base::Closure> callbacks_; |
| 109 |
| 110 OwnershipService::Status ownership_status_; |
| 111 mutable scoped_ptr<SignedSettingsMigrationHelper> migration_helper_; |
| 112 |
| 113 content::NotificationRegistrar registrar_; |
| 114 |
| 115 // In order to guard against occasional failure to fetch a property |
| 116 // we allow for some number of retries. |
| 117 int retries_left_; |
| 118 |
| 119 em::PolicyData policy_; |
| 120 bool trusted_; |
| 121 |
| 122 PrefValueMap values_cache_; |
| 123 |
| 124 friend class SignedSettingsHelper; |
| 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider); |
| 127 }; |
| 128 |
| 129 } // namespace chromeos |
| 130 |
| 131 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ |
OLD | NEW |