Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_provider.h

Issue 640063008: Revert of Implemented OwnerSettingsService::Set() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_ 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
7 7
8 #include <deque>
8 #include <string> 9 #include <string>
10 #include <utility>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/basictypes.h" 13 #include "base/basictypes.h"
12 #include "base/callback.h" 14 #include "base/callback.h"
13 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
14 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
15 #include "base/prefs/pref_value_map.h" 17 #include "base/prefs/pref_value_map.h"
16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h" 19 #include "chrome/browser/chromeos/settings/device_settings_service.h"
18 #include "chromeos/settings/cros_settings_provider.h" 20 #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" 21 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
21 22
22 namespace base { 23 namespace base {
23 class Value; 24 class Value;
24 } 25 }
25 26
26 namespace enterprise_management { 27 namespace enterprise_management {
27 class ChromeDeviceSettingsProto; 28 class ChromeDeviceSettingsProto;
28 } // namespace enterprise_management 29 } // namespace enterprise_management
29 30
30 namespace chromeos { 31 namespace chromeos {
31 32
32 // CrosSettingsProvider implementation that works with device settings. 33 // CrosSettingsProvider implementation that works with device settings.
33 // 34 class DeviceSettingsProvider : public CrosSettingsProvider,
34 // Note that the write path is in the process of being migrated to 35 public DeviceSettingsService::Observer {
35 // OwnerSettingsServiceChromeOS (crbug.com/230018).
36 class DeviceSettingsProvider
37 : public CrosSettingsProvider,
38 public DeviceSettingsService::Observer,
39 public ownership::OwnerSettingsService::Observer {
40 public: 36 public:
41 // The callback type that is called to get the device mode. 37 // The callback type that is called to get the device mode.
42 typedef base::Callback<policy::DeviceMode(void)> GetDeviceModeCallback; 38 typedef base::Callback<policy::DeviceMode(void)> GetDeviceModeCallback;
43 39
44 DeviceSettingsProvider(const NotifyObserversCallback& notify_cb, 40 DeviceSettingsProvider(const NotifyObserversCallback& notify_cb,
45 DeviceSettingsService* device_settings_service); 41 DeviceSettingsService* device_settings_service);
46 virtual ~DeviceSettingsProvider(); 42 virtual ~DeviceSettingsProvider();
47 43
48 // Returns true if |path| is handled by this provider. 44 // Returns true if |path| is handled by this provider.
49 static bool IsDeviceSetting(const std::string& name); 45 static bool IsDeviceSetting(const std::string& name);
50 46
51 // CrosSettingsProvider implementation. 47 // CrosSettingsProvider implementation.
52 virtual const base::Value* Get(const std::string& path) const override; 48 virtual const base::Value* Get(const std::string& path) const override;
53 virtual TrustedStatus PrepareTrustedValues( 49 virtual TrustedStatus PrepareTrustedValues(
54 const base::Closure& callback) override; 50 const base::Closure& callback) override;
55 virtual bool HandlesSetting(const std::string& path) const override; 51 virtual bool HandlesSetting(const std::string& path) const override;
56 52
57 private: 53 private:
58 // CrosSettingsProvider implementation: 54 // CrosSettingsProvider implementation:
59 virtual void DoSet(const std::string& path, 55 virtual void DoSet(const std::string& path,
60 const base::Value& value) override; 56 const base::Value& value) override;
61 57
62 // DeviceSettingsService::Observer implementation: 58 // DeviceSettingsService::Observer implementation:
63 virtual void OwnershipStatusChanged() override; 59 virtual void OwnershipStatusChanged() override;
64 virtual void DeviceSettingsUpdated() override; 60 virtual void DeviceSettingsUpdated() override;
65 61
66 // ownership::OwnerSettingsService::Observer implementation:
67 virtual void OnTentativeChangesInPolicy(
68 const enterprise_management::PolicyData& policy_data) override;
69
70 // Populates in-memory cache from the local_state cache that is used to store 62 // Populates in-memory cache from the local_state cache that is used to store
71 // device settings before the device is owned and to speed up policy 63 // device settings before the device is owned and to speed up policy
72 // availability before the policy blob is fetched on boot. 64 // availability before the policy blob is fetched on boot.
73 void RetrieveCachedData(); 65 void RetrieveCachedData();
74 66
67 // Stores a value from the |pending_changes_| queue in the device settings.
68 // If the device is not owned yet the data ends up only in the local_state
69 // cache and is serialized once ownership is acquired.
70 void SetInPolicy();
71
75 // Parses the policy data and fills in |values_cache_|. 72 // Parses the policy data and fills in |values_cache_|.
76 void UpdateValuesCache( 73 void UpdateValuesCache(
77 const enterprise_management::PolicyData& policy_data, 74 const enterprise_management::PolicyData& policy_data,
78 const enterprise_management::ChromeDeviceSettingsProto& settings, 75 const enterprise_management::ChromeDeviceSettingsProto& settings,
79 TrustedStatus trusted_status); 76 TrustedStatus trusted_status);
80 77
81 // Applies the metrics policy and if not set migrates the legacy file. 78 // Applies the metrics policy and if not set migrates the legacy file.
82 void ApplyMetricsSetting(bool use_file, bool new_value); 79 void ApplyMetricsSetting(bool use_file, bool new_value);
83 80
84 // Applies the data roaming policy. 81 // Applies the data roaming policy.
(...skipping 18 matching lines...) Expand all
103 100
104 // Invokes UpdateFromService() to synchronize with |device_settings_service_|, 101 // Invokes UpdateFromService() to synchronize with |device_settings_service_|,
105 // then triggers the next store operation if applicable. 102 // then triggers the next store operation if applicable.
106 void UpdateAndProceedStoring(); 103 void UpdateAndProceedStoring();
107 104
108 // Re-reads state from |device_settings_service_|, adjusts 105 // Re-reads state from |device_settings_service_|, adjusts
109 // |trusted_status_| and calls UpdateValuesCache() if applicable. Returns true 106 // |trusted_status_| and calls UpdateValuesCache() if applicable. Returns true
110 // if new settings have been loaded. 107 // if new settings have been loaded.
111 bool UpdateFromService(); 108 bool UpdateFromService();
112 109
110 // Sends |device_settings_| to |device_settings_service_| for signing and
111 // storage in session_manager.
112 void StoreDeviceSettings();
113
113 // Checks the current ownership status to see whether the device owner is 114 // Checks the current ownership status to see whether the device owner is
114 // logged in and writes the data accumulated in |migration_values_| to proper 115 // logged in and writes the data accumulated in |migration_values_| to proper
115 // device settings. 116 // device settings.
116 void AttemptMigration(); 117 void AttemptMigration();
117 118
118 // Pending callbacks that need to be invoked after settings verification. 119 // Pending callbacks that need to be invoked after settings verification.
119 std::vector<base::Closure> callbacks_; 120 std::vector<base::Closure> callbacks_;
120 121
121 DeviceSettingsService* device_settings_service_; 122 DeviceSettingsService* device_settings_service_;
122 mutable PrefValueMap migration_values_; 123 mutable PrefValueMap migration_values_;
123 124
124 TrustedStatus trusted_status_; 125 TrustedStatus trusted_status_;
125 DeviceSettingsService::OwnershipStatus ownership_status_; 126 DeviceSettingsService::OwnershipStatus ownership_status_;
126 127
127 // The device settings as currently reported through the 128 // The device settings as currently reported through the CrosSettingsProvider
128 // CrosSettingsProvider interface. This may be different from the 129 // interface. This may be different from the actual current device settings
129 // actual current device settings (which can be obtained from 130 // (which can be obtained from |device_settings_service_|) in case the device
130 // |device_settings_service_|) in case the device does not have an 131 // does not have an owner yet or there are pending changes that have not yet
131 // owner yet. As soon as ownership of the device will be taken, 132 // been written to session_manager.
132 // |device_settings_| will stored on disk and won't be used.
133 enterprise_management::ChromeDeviceSettingsProto device_settings_; 133 enterprise_management::ChromeDeviceSettingsProto device_settings_;
134 134
135 // A cache of values, indexed by the settings keys served through the 135 // A cache of values, indexed by the settings keys served through the
136 // CrosSettingsProvider interface. This is always kept in sync with the 136 // CrosSettingsProvider interface. This is always kept in sync with the raw
137 // current device settings. 137 // data found in |device_settings_|.
138 PrefValueMap values_cache_; 138 PrefValueMap values_cache_;
139 139
140 // This is a queue for set requests, because those need to be sequential.
141 typedef std::pair<std::string, base::Value*> PendingQueueElement;
142 std::deque<PendingQueueElement> pending_changes_;
143
140 // Weak pointer factory for creating store operation callbacks. 144 // Weak pointer factory for creating store operation callbacks.
141 base::WeakPtrFactory<DeviceSettingsProvider> store_callback_factory_; 145 base::WeakPtrFactory<DeviceSettingsProvider> store_callback_factory_;
142 146
143 friend class DeviceSettingsProviderTest; 147 friend class DeviceSettingsProviderTest;
144 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, 148 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest,
145 InitializationTestUnowned); 149 InitializationTestUnowned);
146 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, 150 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest,
147 PolicyFailedPermanentlyNotification); 151 PolicyFailedPermanentlyNotification);
148 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, PolicyLoadNotification); 152 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, PolicyLoadNotification);
149 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider); 153 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider);
150 }; 154 };
151 155
152 } // namespace chromeos 156 } // namespace chromeos
153 157
154 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_ 158 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698