OLD | NEW |
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 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler
.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler
.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 const bool is_owner = | 83 const bool is_owner = |
84 user_manager::UserManager::Get()->GetOwnerAccountId().GetUserEmail() == | 84 user_manager::UserManager::Get()->GetOwnerAccountId().GetUserEmail() == |
85 username; | 85 username; |
86 user_dict->SetBoolean("owner", is_owner); | 86 user_dict->SetBoolean("owner", is_owner); |
87 return user_dict; | 87 return user_dict; |
88 } | 88 } |
89 | 89 |
90 // This function decorates the bare list of emails with some more information | 90 // This function decorates the bare list of emails with some more information |
91 // needed by the UI to properly display the Accounts page. | 91 // needed by the UI to properly display the Accounts page. |
92 std::unique_ptr<base::Value> CreateUsersWhitelist( | 92 base::Value* CreateUsersWhitelist(const base::Value *pref_value) { |
93 const base::Value* pref_value) { | |
94 const base::ListValue* list_value = | 93 const base::ListValue* list_value = |
95 static_cast<const base::ListValue*>(pref_value); | 94 static_cast<const base::ListValue*>(pref_value); |
96 auto user_list = base::MakeUnique<base::ListValue>(); | 95 base::ListValue* user_list = new base::ListValue(); |
97 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 96 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
98 | 97 |
99 for (base::ListValue::const_iterator i = list_value->begin(); | 98 for (base::ListValue::const_iterator i = list_value->begin(); |
100 i != list_value->end(); ++i) { | 99 i != list_value->end(); ++i) { |
101 std::string email; | 100 std::string email; |
102 if (i->GetAsString(&email)) { | 101 if (i->GetAsString(&email)) { |
103 // Translate email to the display email. | 102 // Translate email to the display email. |
104 const std::string display_email = | 103 const std::string display_email = |
105 user_manager->GetUserDisplayEmail(AccountId::FromUserEmail(email)); | 104 user_manager->GetUserDisplayEmail(AccountId::FromUserEmail(email)); |
106 // TODO(ivankr): fetch display name for existing users. | 105 // TODO(ivankr): fetch display name for existing users. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 base::ThreadTaskRunnerHandle::Get()->PostTask( | 164 base::ThreadTaskRunnerHandle::Get()->PostTask( |
166 FROM_HERE, base::Bind(&CoreChromeOSOptionsHandler::NotifyOwnershipChanged, | 165 FROM_HERE, base::Bind(&CoreChromeOSOptionsHandler::NotifyOwnershipChanged, |
167 base::Unretained(this))); | 166 base::Unretained(this))); |
168 } | 167 } |
169 | 168 |
170 void CoreChromeOSOptionsHandler::NotifyOwnershipChanged() { | 169 void CoreChromeOSOptionsHandler::NotifyOwnershipChanged() { |
171 for (auto it : pref_subscription_map_) | 170 for (auto it : pref_subscription_map_) |
172 NotifySettingsChanged(it.first); | 171 NotifySettingsChanged(it.first); |
173 } | 172 } |
174 | 173 |
175 std::unique_ptr<base::Value> CoreChromeOSOptionsHandler::FetchPref( | 174 base::Value* CoreChromeOSOptionsHandler::FetchPref( |
176 const std::string& pref_name) { | 175 const std::string& pref_name) { |
177 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) { | 176 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) { |
178 std::unique_ptr<base::Value> value; | 177 base::Value* value = nullptr; |
179 proxy_cros_settings_parser::GetProxyPrefValue( | 178 proxy_cros_settings_parser::GetProxyPrefValue( |
180 network_guid_, pref_name, GetUiProxyConfigService(), &value); | 179 network_guid_, pref_name, GetUiProxyConfigService(), &value); |
181 return value; | 180 return value ? value : new base::Value(); |
182 } | 181 } |
183 | 182 |
184 Profile* profile = Profile::FromWebUI(web_ui()); | 183 Profile* profile = Profile::FromWebUI(web_ui()); |
185 if (!CrosSettings::IsCrosSettings(pref_name)) { | 184 if (!CrosSettings::IsCrosSettings(pref_name)) { |
186 std::string controlling_pref = | 185 std::string controlling_pref = |
187 pref_name == proxy_config::prefs::kUseSharedProxies | 186 pref_name == proxy_config::prefs::kUseSharedProxies |
188 ? proxy_config::prefs::kProxy | 187 ? proxy_config::prefs::kProxy |
189 : std::string(); | 188 : std::string(); |
190 std::unique_ptr<base::Value> value = | 189 base::Value* value = CreateValueForPref(pref_name, controlling_pref); |
191 CreateValueForPref(pref_name, controlling_pref); | |
192 if (!IsSettingShared(pref_name) || !IsSecondaryUser(profile)) | 190 if (!IsSettingShared(pref_name) || !IsSecondaryUser(profile)) |
193 return value; | 191 return value; |
194 base::DictionaryValue* dict; | 192 base::DictionaryValue* dict; |
195 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy")) | 193 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy")) |
196 return value; | 194 return value; |
197 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser( | 195 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser( |
198 user_manager::UserManager::Get()->GetPrimaryUser()); | 196 user_manager::UserManager::Get()->GetPrimaryUser()); |
199 if (!primary_profile) | 197 if (!primary_profile) |
200 return value; | 198 return value; |
201 dict->SetString("controlledBy", "shared"); | 199 dict->SetString("controlledBy", "shared"); |
202 dict->SetBoolean("disabled", true); | 200 dict->SetBoolean("disabled", true); |
203 dict->SetBoolean("value", primary_profile->GetPrefs()->GetBoolean( | 201 dict->SetBoolean("value", primary_profile->GetPrefs()->GetBoolean( |
204 pref_name)); | 202 pref_name)); |
205 return value; | 203 return dict; |
206 } | 204 } |
207 | 205 |
208 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); | 206 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); |
209 if (!pref_value) | 207 if (!pref_value) |
210 return base::MakeUnique<base::Value>(); | 208 return new base::Value(); |
211 | 209 |
212 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. | 210 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. |
213 // TODO(estade): seems that this should replicate CreateValueForPref less. | 211 // TODO(estade): seems that this should replicate CreateValueForPref less. |
214 auto dict = base::MakeUnique<base::DictionaryValue>(); | 212 base::DictionaryValue* dict = new base::DictionaryValue; |
215 if (pref_name == kAccountsPrefUsers) | 213 if (pref_name == kAccountsPrefUsers) |
216 dict->Set("value", CreateUsersWhitelist(pref_value)); | 214 dict->Set("value", CreateUsersWhitelist(pref_value)); |
217 else | 215 else |
218 dict->Set("value", base::MakeUnique<base::Value>(*pref_value)); | 216 dict->Set("value", pref_value->DeepCopy()); |
219 | 217 |
220 std::string controlled_by; | 218 std::string controlled_by; |
221 if (IsSettingPrivileged(pref_name)) { | 219 if (IsSettingPrivileged(pref_name)) { |
222 policy::BrowserPolicyConnectorChromeOS* connector = | 220 policy::BrowserPolicyConnectorChromeOS* connector = |
223 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 221 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
224 if (connector->IsEnterpriseManaged()) | 222 if (connector->IsEnterpriseManaged()) |
225 controlled_by = "policy"; | 223 controlled_by = "policy"; |
226 else if (!ProfileHelper::IsOwnerProfile(profile)) | 224 else if (!ProfileHelper::IsOwnerProfile(profile)) |
227 controlled_by = "owner"; | 225 controlled_by = "owner"; |
228 } | 226 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 void CoreChromeOSOptionsHandler::StopObservingPref(const std::string& path) { | 274 void CoreChromeOSOptionsHandler::StopObservingPref(const std::string& path) { |
277 if (proxy_cros_settings_parser::IsProxyPref(path)) | 275 if (proxy_cros_settings_parser::IsProxyPref(path)) |
278 return; // We unregister those in the destructor. | 276 return; // We unregister those in the destructor. |
279 // Unregister this instance from observing prefs of chrome os settings. | 277 // Unregister this instance from observing prefs of chrome os settings. |
280 if (CrosSettings::IsCrosSettings(path)) | 278 if (CrosSettings::IsCrosSettings(path)) |
281 pref_subscription_map_.erase(path); | 279 pref_subscription_map_.erase(path); |
282 else // Call base class to handle regular preferences. | 280 else // Call base class to handle regular preferences. |
283 ::options::CoreOptionsHandler::StopObservingPref(path); | 281 ::options::CoreOptionsHandler::StopObservingPref(path); |
284 } | 282 } |
285 | 283 |
286 std::unique_ptr<base::Value> CoreChromeOSOptionsHandler::CreateValueForPref( | 284 base::Value* CoreChromeOSOptionsHandler::CreateValueForPref( |
287 const std::string& pref_name, | 285 const std::string& pref_name, |
288 const std::string& controlling_pref_name) { | 286 const std::string& controlling_pref_name) { |
289 // The screen lock setting is shared if multiple users are logged in and at | 287 // The screen lock setting is shared if multiple users are logged in and at |
290 // least one has chosen to require passwords. | 288 // least one has chosen to require passwords. |
291 if (pref_name == prefs::kEnableAutoScreenLock && | 289 if (pref_name == prefs::kEnableAutoScreenLock && |
292 user_manager::UserManager::Get()->GetLoggedInUsers().size() > 1 && | 290 user_manager::UserManager::Get()->GetLoggedInUsers().size() > 1 && |
293 controlling_pref_name.empty()) { | 291 controlling_pref_name.empty()) { |
294 PrefService* user_prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 292 PrefService* user_prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
295 const PrefService::Preference* pref = | 293 const PrefService::Preference* pref = |
296 user_prefs->FindPreference(prefs::kEnableAutoScreenLock); | 294 user_prefs->FindPreference(prefs::kEnableAutoScreenLock); |
297 | 295 |
298 if (pref && pref->IsUserModifiable() && | 296 if (pref && pref->IsUserModifiable() && |
299 SessionControllerClient::ShouldLockScreenAutomatically()) { | 297 SessionControllerClient::ShouldLockScreenAutomatically()) { |
300 bool screen_lock = false; | 298 bool screen_lock = false; |
301 bool success = pref->GetValue()->GetAsBoolean(&screen_lock); | 299 bool success = pref->GetValue()->GetAsBoolean(&screen_lock); |
302 DCHECK(success); | 300 DCHECK(success); |
303 if (!screen_lock) { | 301 if (!screen_lock) { |
304 // Screen lock is enabled for the session, but not in the user's | 302 // Screen lock is enabled for the session, but not in the user's |
305 // preferences. Show the user's value in the checkbox, but indicate | 303 // preferences. Show the user's value in the checkbox, but indicate |
306 // that the password requirement is enabled by some other user. | 304 // that the password requirement is enabled by some other user. |
307 auto dict = base::MakeUnique<base::DictionaryValue>(); | 305 base::DictionaryValue* dict = new base::DictionaryValue; |
308 dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue())); | 306 dict->Set("value", pref->GetValue()->DeepCopy()); |
309 dict->SetString("controlledBy", "shared"); | 307 dict->SetString("controlledBy", "shared"); |
310 return dict; | 308 return dict; |
311 } | 309 } |
312 } | 310 } |
313 } | 311 } |
314 | 312 |
315 return CoreOptionsHandler::CreateValueForPref(pref_name, | 313 return CoreOptionsHandler::CreateValueForPref(pref_name, |
316 controlling_pref_name); | 314 controlling_pref_name); |
317 } | 315 } |
318 | 316 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 DCHECK(CrosSettings::Get()->IsCrosSettings(setting_name)); | 404 DCHECK(CrosSettings::Get()->IsCrosSettings(setting_name)); |
407 std::unique_ptr<base::Value> value(FetchPref(setting_name)); | 405 std::unique_ptr<base::Value> value(FetchPref(setting_name)); |
408 if (!value.get()) | 406 if (!value.get()) |
409 NOTREACHED(); | 407 NOTREACHED(); |
410 DispatchPrefChangeNotification(setting_name, std::move(value)); | 408 DispatchPrefChangeNotification(setting_name, std::move(value)); |
411 } | 409 } |
412 | 410 |
413 void CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged() { | 411 void CoreChromeOSOptionsHandler::NotifyProxyPrefsChanged() { |
414 GetUiProxyConfigService()->UpdateFromPrefs(network_guid_); | 412 GetUiProxyConfigService()->UpdateFromPrefs(network_guid_); |
415 for (size_t i = 0; i < proxy_cros_settings_parser::kProxySettingsCount; ++i) { | 413 for (size_t i = 0; i < proxy_cros_settings_parser::kProxySettingsCount; ++i) { |
416 std::unique_ptr<base::Value> value; | 414 base::Value* value = NULL; |
417 proxy_cros_settings_parser::GetProxyPrefValue( | 415 proxy_cros_settings_parser::GetProxyPrefValue( |
418 network_guid_, proxy_cros_settings_parser::kProxySettings[i], | 416 network_guid_, proxy_cros_settings_parser::kProxySettings[i], |
419 GetUiProxyConfigService(), &value); | 417 GetUiProxyConfigService(), &value); |
420 DCHECK(value); | 418 DCHECK(value); |
| 419 std::unique_ptr<base::Value> ptr(value); |
421 DispatchPrefChangeNotification( | 420 DispatchPrefChangeNotification( |
422 proxy_cros_settings_parser::kProxySettings[i], std::move(value)); | 421 proxy_cros_settings_parser::kProxySettings[i], std::move(ptr)); |
423 } | 422 } |
424 } | 423 } |
425 | 424 |
426 } // namespace options | 425 } // namespace options |
427 } // namespace chromeos | 426 } // namespace chromeos |
OLD | NEW |