Chromium Code Reviews| Index: chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc |
| index 0d18b94f7e74acbf44728beb77fe0e629ef187f1..91dc717eadbfd7b1b00df8a41c65fe7b33b5efae 100644 |
| --- a/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc |
| +++ b/chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc |
| @@ -46,12 +46,23 @@ const char* kNonPrivilegedSettings[] = { |
| kSystemTimezone |
| }; |
| +// List of settings that should only be changeable by the primary user. |
| +const char* kPrimaryUserSettings[] = { |
| + prefs::kWakeOnWifiSsid, |
| +}; |
| + |
| // Returns true if |pref| can be controlled (e.g. by policy or owner). |
| bool IsSettingPrivileged(const std::string& pref) { |
| const char** end = kNonPrivilegedSettings + arraysize(kNonPrivilegedSettings); |
| return std::find(kNonPrivilegedSettings, end, pref) == end; |
| } |
| +// Returns true if |pref| is shared (controlled by the primary user). |
| +bool IsSettingShared(const std::string& pref) { |
| + const char** end = kPrimaryUserSettings + arraysize(kPrimaryUserSettings); |
| + return std::find(kPrimaryUserSettings, end, pref) != end; |
|
stevenjb
2014/12/17 22:22:55
Ugh, I was going to bitch about this pattern (I th
|
| +} |
| + |
| // Creates a user info dictionary to be stored in the |ListValue| that is |
| // passed to Javascript for the |kAccountsPrefUsers| preference. |
| base::DictionaryValue* CreateUserInfo(const std::string& username, |
| @@ -88,6 +99,13 @@ base::Value* CreateUsersWhitelist(const base::Value *pref_value) { |
| return user_list; |
| } |
| +// Checks whether this is a secondary user in a multi-profile session. |
| +bool IsSecondaryUser(Profile* profile) { |
| + user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| + user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); |
| + return user && user->email() != user_manager->GetPrimaryUser()->email(); |
|
stevenjb
2014/12/17 22:22:55
Any reason to compare email() instead of User*s, i
michaelpg
2014/12/22 22:23:18
I asked skuhne why we do this but he wasn't sure.
|
| +} |
| + |
| const char kSelectNetworkMessage[] = "selectNetwork"; |
| } // namespace |
| @@ -163,10 +181,25 @@ base::Value* CoreChromeOSOptionsHandler::FetchPref( |
| return value; |
| } |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| if (!CrosSettings::IsCrosSettings(pref_name)) { |
| std::string controlling_pref = |
| pref_name == prefs::kUseSharedProxies ? prefs::kProxy : std::string(); |
| - return CreateValueForPref(pref_name, controlling_pref); |
| + base::Value* value = CreateValueForPref(pref_name, controlling_pref); |
| + base::DictionaryValue* dict; |
| + if (IsSettingShared(pref_name) && IsSecondaryUser(profile) && |
| + value->GetAsDictionary(&dict) && !dict->HasKey("controlledBy")) { |
|
stevenjb
2014/12/17 22:22:55
if (!IsSettingShared(pref_name) || !IsSecondaryUse
michaelpg
2014/12/22 22:23:18
Done.
|
| + Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser( |
| + user_manager::UserManager::Get()->GetPrimaryUser()); |
| + if (primary_profile) { |
|
stevenjb
2014/12/17 22:22:55
early exit here too
michaelpg
2014/12/22 22:23:18
Done.
|
| + dict->SetString("controlledBy", "shared"); |
| + dict->SetBoolean("disabled", true); |
| + dict->SetBoolean("value", primary_profile->GetPrefs()->GetBoolean( |
| + pref_name)); |
| + return dict; |
| + } |
| + } |
| + return value; |
| } |
| const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); |
| @@ -187,7 +220,7 @@ base::Value* CoreChromeOSOptionsHandler::FetchPref( |
| g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| if (connector->IsEnterpriseManaged()) |
| controlled_by = "policy"; |
| - else if (!ProfileHelper::IsOwnerProfile(Profile::FromWebUI(web_ui()))) |
| + else if (!ProfileHelper::IsOwnerProfile(profile)) |
| controlled_by = "owner"; |
| } |
| dict->SetBoolean("disabled", !controlled_by.empty()); |
| @@ -302,10 +335,7 @@ void CoreChromeOSOptionsHandler::GetLocalizedValues( |
| user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| - // Check at load time whether this is a secondary user in a multi-profile |
| - // session. |
| - user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); |
| - if (user && user->email() != user_manager->GetPrimaryUser()->email()) { |
|
stevenjb
2014/12/17 22:22:55
Ah, I see this was just moved, so go ahead and lea
|
| + if (IsSecondaryUser(profile)) { |
| const std::string& primary_email = user_manager->GetPrimaryUser()->email(); |
| // Set secondaryUser to show the shared icon by the network section header. |