OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/device_settings_provider.h" | 5 #include "chrome/browser/chromeos/device_settings_provider.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 85 // TODO(pastarmovj): Remove this once migration is not needed anymore. |
86 // If the value is not set we should try to migrate legacy consent file. | 86 // If the value is not set we should try to migrate legacy consent file. |
87 // Loading consent file state causes us to do blocking IO on UI thread. | 87 // Loading consent file state causes us to do blocking IO on UI thread. |
88 // Temporarily allow it until we fix http://crbug.com/62626 | 88 // Temporarily allow it until we fix http://crbug.com/62626 |
89 base::ThreadRestrictions::ScopedAllowIO allow_io; | 89 base::ThreadRestrictions::ScopedAllowIO allow_io; |
90 return GoogleUpdateSettings::GetCollectStatsConsent(); | 90 return GoogleUpdateSettings::GetCollectStatsConsent(); |
91 } | 91 } |
92 | 92 |
93 } // namespace | 93 } // namespace |
94 | 94 |
95 DeviceSettingsProvider::DeviceSettingsProvider() | 95 DeviceSettingsProvider::DeviceSettingsProvider( |
96 : ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)), | 96 const NotifyObserversCallback& notify_cb) |
| 97 : CrosSettingsProvider(notify_cb), |
| 98 ownership_status_(OwnershipService::GetSharedInstance()->GetStatus(true)), |
97 migration_helper_(new SignedSettingsMigrationHelper()), | 99 migration_helper_(new SignedSettingsMigrationHelper()), |
98 retries_left_(kNumRetriesLimit), | 100 retries_left_(kNumRetriesLimit), |
99 trusted_(false) { | 101 trusted_(false) { |
100 // Register for notification when ownership is taken so that we can update | 102 // Register for notification when ownership is taken so that we can update |
101 // the |ownership_status_| and reload if needed. | 103 // the |ownership_status_| and reload if needed. |
102 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, | 104 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
103 content::NotificationService::AllSources()); | 105 content::NotificationService::AllSources()); |
104 // Make sure we have at least the cache data immediately. | 106 // Make sure we have at least the cache data immediately. |
105 RetrieveCachedData(); | 107 RetrieveCachedData(); |
106 // Start prefetching preferences. | 108 // Start prefetching preferences. |
(...skipping 16 matching lines...) Expand all Loading... |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
126 void DeviceSettingsProvider::DoSet(const std::string& path, | 128 void DeviceSettingsProvider::DoSet(const std::string& path, |
127 const base::Value& in_value) { | 129 const base::Value& in_value) { |
128 if (!UserManager::Get()->current_user_is_owner() && | 130 if (!UserManager::Get()->current_user_is_owner() && |
129 ownership_status_ != OwnershipService::OWNERSHIP_NONE) { | 131 ownership_status_ != OwnershipService::OWNERSHIP_NONE) { |
130 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; | 132 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; |
131 | 133 |
132 // Revert UI change. | 134 // Revert UI change. |
133 CrosSettings::Get()->FireObservers(path.c_str()); | 135 NotifyObservers(path); |
134 return; | 136 return; |
135 } | 137 } |
136 | 138 |
137 if (IsControlledSetting(path)) | 139 if (IsControlledSetting(path)) |
138 SetInPolicy(path, in_value); | 140 SetInPolicy(path, in_value); |
139 else | 141 else |
140 NOTREACHED() << "Try to set unhandled cros setting " << path; | 142 NOTREACHED() << "Try to set unhandled cros setting " << path; |
141 } | 143 } |
142 | 144 |
143 void DeviceSettingsProvider::Observe( | 145 void DeviceSettingsProvider::Observe( |
(...skipping 29 matching lines...) Expand all Loading... |
173 } | 175 } |
174 | 176 |
175 void DeviceSettingsProvider::SetInPolicy(const std::string& prop, | 177 void DeviceSettingsProvider::SetInPolicy(const std::string& prop, |
176 const base::Value& value) { | 178 const base::Value& value) { |
177 if (prop == kDeviceOwner) { | 179 if (prop == kDeviceOwner) { |
178 // Just store it in the memory cache without trusted checks or persisting. | 180 // Just store it in the memory cache without trusted checks or persisting. |
179 std::string owner; | 181 std::string owner; |
180 if (value.GetAsString(&owner)) { | 182 if (value.GetAsString(&owner)) { |
181 policy_.set_username(owner); | 183 policy_.set_username(owner); |
182 values_cache_.SetValue(prop, value.DeepCopy()); | 184 values_cache_.SetValue(prop, value.DeepCopy()); |
183 CrosSettings::Get()->FireObservers(prop.c_str()); | 185 NotifyObservers(prop); |
184 // We can't trust this value anymore until we reload the real username. | 186 // We can't trust this value anymore until we reload the real username. |
185 trusted_ = false; | 187 trusted_ = false; |
186 } else { | 188 } else { |
187 NOTREACHED(); | 189 NOTREACHED(); |
188 } | 190 } |
189 return; | 191 return; |
190 } | 192 } |
191 | 193 |
192 if (!RequestTrustedEntity()) { | 194 if (!RequestTrustedEntity()) { |
193 // Otherwise we should first reload and apply on top of that. | 195 // Otherwise we should first reload and apply on top of that. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if ((*i)->GetAsString(&email)) | 268 if ((*i)->GetAsString(&email)) |
267 whitelist_proto->add_user_whitelist(email.c_str()); | 269 whitelist_proto->add_user_whitelist(email.c_str()); |
268 } | 270 } |
269 } else { | 271 } else { |
270 NOTREACHED(); | 272 NOTREACHED(); |
271 } | 273 } |
272 data.set_policy_value(pol.SerializeAsString()); | 274 data.set_policy_value(pol.SerializeAsString()); |
273 // Set the cache to the updated value. | 275 // Set the cache to the updated value. |
274 policy_ = data; | 276 policy_ = data; |
275 UpdateValuesCache(); | 277 UpdateValuesCache(); |
276 CrosSettings::Get()->FireObservers(prop.c_str()); | 278 NotifyObservers(prop); |
277 | 279 |
278 if (!signed_settings_cache::Store(data, g_browser_process->local_state())) | 280 if (!signed_settings_cache::Store(data, g_browser_process->local_state())) |
279 LOG(ERROR) << "Couldn't store to the temp storage."; | 281 LOG(ERROR) << "Couldn't store to the temp storage."; |
280 | 282 |
281 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) { | 283 if (ownership_status_ == OwnershipService::OWNERSHIP_TAKEN) { |
282 em::PolicyFetchResponse policy_envelope; | 284 em::PolicyFetchResponse policy_envelope; |
283 policy_envelope.set_policy_data(policy_.SerializeAsString()); | 285 policy_envelope.set_policy_data(policy_.SerializeAsString()); |
284 SignedSettingsHelper::Get()->StartStorePolicyOp( | 286 SignedSettingsHelper::Get()->StartStorePolicyOp( |
285 policy_envelope, | 287 policy_envelope, |
286 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted, | 288 base::Bind(&DeviceSettingsProvider::OnStorePolicyCompleted, |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 Reload(); | 518 Reload(); |
517 return; | 519 return; |
518 } | 520 } |
519 LOG(ERROR) << "No retries left"; | 521 LOG(ERROR) << "No retries left"; |
520 break; | 522 break; |
521 } | 523 } |
522 } | 524 } |
523 } | 525 } |
524 | 526 |
525 } // namespace chromeos | 527 } // namespace chromeos |
OLD | NEW |