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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc

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

Powered by Google App Engine
This is Rietveld 408576698