Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / settings / device_settings_provider.h
blob4705e6176feefe80faa47e6bff9697e0eeb56199
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/prefs/pref_value_map.h"
16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h"
18 #include "chromeos/settings/cros_settings_provider.h"
19 #include "components/ownership/owner_settings_service.h"
20 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
22 namespace base {
23 class Value;
26 namespace enterprise_management {
27 class ChromeDeviceSettingsProto;
28 } // namespace enterprise_management
30 namespace chromeos {
32 // CrosSettingsProvider implementation that works with device settings.
34 // Note that the write path is in the process of being migrated to
35 // OwnerSettingsServiceChromeOS (crbug.com/230018).
36 class DeviceSettingsProvider
37 : public CrosSettingsProvider,
38 public DeviceSettingsService::Observer,
39 public ownership::OwnerSettingsService::Observer {
40 public:
41 // The callback type that is called to get the device mode.
42 typedef base::Callback<policy::DeviceMode(void)> GetDeviceModeCallback;
44 DeviceSettingsProvider(const NotifyObserversCallback& notify_cb,
45 DeviceSettingsService* device_settings_service);
46 ~DeviceSettingsProvider() override;
48 // Returns true if |path| is handled by this provider.
49 static bool IsDeviceSetting(const std::string& name);
51 // CrosSettingsProvider implementation.
52 const base::Value* Get(const std::string& path) const override;
53 TrustedStatus PrepareTrustedValues(const base::Closure& callback) override;
54 bool HandlesSetting(const std::string& path) const override;
56 private:
57 // CrosSettingsProvider implementation:
58 void DoSet(const std::string& path, const base::Value& value) override;
60 // DeviceSettingsService::Observer implementation:
61 void OwnershipStatusChanged() override;
62 void DeviceSettingsUpdated() override;
63 void OnDeviceSettingsServiceShutdown() override;
65 // ownership::OwnerSettingsService::Observer implementation:
66 void OnTentativeChangesInPolicy(
67 const enterprise_management::PolicyData& policy_data) override;
69 // Populates in-memory cache from the local_state cache that is used to store
70 // device settings before the device is owned and to speed up policy
71 // availability before the policy blob is fetched on boot.
72 void RetrieveCachedData();
74 // Parses the policy data and fills in |values_cache_|.
75 void UpdateValuesCache(
76 const enterprise_management::PolicyData& policy_data,
77 const enterprise_management::ChromeDeviceSettingsProto& settings,
78 TrustedStatus trusted_status);
80 // Applies the metrics policy and if not set migrates the legacy file.
81 void ApplyMetricsSetting(bool use_file, bool new_value);
83 // Applies the data roaming policy.
84 void ApplyRoamingSetting(bool new_value);
85 void ApplyRoamingSettingFromProto(
86 const enterprise_management::ChromeDeviceSettingsProto& settings);
88 // Applies any changes of the policies that are not handled by the respective
89 // subsystems.
90 void ApplySideEffects(
91 const enterprise_management::ChromeDeviceSettingsProto& settings);
93 // In case of missing policy blob we should verify if this is upgrade of
94 // machine owned from pre version 12 OS and the user never touched the device
95 // settings. In this case revert to defaults and let people in until the owner
96 // comes and changes that.
97 bool MitigateMissingPolicy();
99 // Checks if the current cache value can be trusted for being representative
100 // for the disk cache.
101 TrustedStatus RequestTrustedEntity();
103 // Invokes UpdateFromService() to synchronize with |device_settings_service_|,
104 // then triggers the next store operation if applicable.
105 void UpdateAndProceedStoring();
107 // Re-reads state from |device_settings_service_|, adjusts
108 // |trusted_status_| and calls UpdateValuesCache() if applicable. Returns true
109 // if new settings have been loaded.
110 bool UpdateFromService();
112 // Checks the current ownership status to see whether the device owner is
113 // logged in and writes the data accumulated in |migration_values_| to proper
114 // device settings.
115 void AttemptMigration();
117 // Pending callbacks that need to be invoked after settings verification.
118 std::vector<base::Closure> callbacks_;
120 DeviceSettingsService* device_settings_service_;
121 mutable PrefValueMap migration_values_;
123 TrustedStatus trusted_status_;
124 DeviceSettingsService::OwnershipStatus ownership_status_;
126 // The device settings as currently reported through the
127 // CrosSettingsProvider interface. This may be different from the
128 // actual current device settings (which can be obtained from
129 // |device_settings_service_|) in case the device does not have an
130 // owner yet. As soon as ownership of the device will be taken,
131 // |device_settings_| will stored on disk and won't be used.
132 enterprise_management::ChromeDeviceSettingsProto device_settings_;
134 // A cache of values, indexed by the settings keys served through the
135 // CrosSettingsProvider interface. This is always kept in sync with the
136 // current device settings.
137 PrefValueMap values_cache_;
139 // Weak pointer factory for creating store operation callbacks.
140 base::WeakPtrFactory<DeviceSettingsProvider> store_callback_factory_;
142 friend class DeviceSettingsProviderTest;
143 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest,
144 InitializationTestUnowned);
145 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest,
146 PolicyFailedPermanentlyNotification);
147 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, PolicyLoadNotification);
148 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider);
151 } // namespace chromeos
153 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_