| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/login/screens/chrome_user_selection_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 CheckForPublicSessionLocalePolicyChange(broker); | 70 CheckForPublicSessionLocalePolicyChange(broker); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { | 73 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { |
| 74 // Nothing to do here. When the list of device-local accounts changes, the | 74 // Nothing to do here. When the list of device-local accounts changes, the |
| 75 // entire UI is reloaded. | 75 // entire UI is reloaded. |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( | 78 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
| 79 policy::DeviceLocalAccountPolicyBroker* broker) { | 79 policy::DeviceLocalAccountPolicyBroker* broker) { |
| 80 const std::string& user_id = broker->user_id(); | 80 const AccountId& account_id = GetAccountIdOfKnownUser(broker->user_id()); |
| 81 DCHECK(account_id.is_valid()); |
| 81 const std::string& display_name = broker->GetDisplayName(); | 82 const std::string& display_name = broker->GetDisplayName(); |
| 82 if (display_name == public_session_display_names_[user_id]) | 83 if (display_name == public_session_display_names_[account_id]) |
| 83 return; | 84 return; |
| 84 | 85 |
| 85 public_session_display_names_[user_id] = display_name; | 86 public_session_display_names_[account_id] = display_name; |
| 86 | 87 |
| 87 if (!handler_initialized_) | 88 if (!handler_initialized_) |
| 88 return; | 89 return; |
| 89 | 90 |
| 90 if (!display_name.empty()) { | 91 if (!display_name.empty()) { |
| 91 // If a new display name was set by policy, notify the UI about it. | 92 // If a new display name was set by policy, notify the UI about it. |
| 92 view_->SetPublicSessionDisplayName(user_id, display_name); | 93 view_->SetPublicSessionDisplayName(account_id, display_name); |
| 93 return; | 94 return; |
| 94 } | 95 } |
| 95 | 96 |
| 96 // When no display name is set by policy, the |User|, owned by |UserManager|, | 97 // When no display name is set by policy, the |User|, owned by |UserManager|, |
| 97 // decides what display name to use. However, the order in which |UserManager| | 98 // decides what display name to use. However, the order in which |UserManager| |
| 98 // and |this| are informed of the display name change is undefined. Post a | 99 // and |this| are informed of the display name change is undefined. Post a |
| 99 // task that will update the UI after the UserManager is guaranteed to have | 100 // task that will update the UI after the UserManager is guaranteed to have |
| 100 // been informed of the change. | 101 // been informed of the change. |
| 101 base::MessageLoop::current()->PostTask( | 102 base::MessageLoop::current()->PostTask( |
| 102 FROM_HERE, | 103 FROM_HERE, |
| 103 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, | 104 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, |
| 104 weak_factory_.GetWeakPtr(), | 105 weak_factory_.GetWeakPtr(), account_id)); |
| 105 user_id)); | |
| 106 } | 106 } |
| 107 | 107 |
| 108 void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( | 108 void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( |
| 109 policy::DeviceLocalAccountPolicyBroker* broker) { | 109 policy::DeviceLocalAccountPolicyBroker* broker) { |
| 110 const std::string& user_id = broker->user_id(); | 110 const AccountId& account_id = GetAccountIdOfKnownUser(broker->user_id()); |
| 111 DCHECK(account_id.is_valid()); |
| 111 const policy::PolicyMap::Entry* entry = | 112 const policy::PolicyMap::Entry* entry = |
| 112 broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); | 113 broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); |
| 113 | 114 |
| 114 // Parse the list of recommended locales set by policy. | 115 // Parse the list of recommended locales set by policy. |
| 115 std::vector<std::string> new_recommended_locales; | 116 std::vector<std::string> new_recommended_locales; |
| 116 base::ListValue const* list = NULL; | 117 base::ListValue const* list = NULL; |
| 117 if (entry && | 118 if (entry && |
| 118 entry->level == policy::POLICY_LEVEL_RECOMMENDED && | 119 entry->level == policy::POLICY_LEVEL_RECOMMENDED && |
| 119 entry->value && | 120 entry->value && |
| 120 entry->value->GetAsList(&list)) { | 121 entry->value->GetAsList(&list)) { |
| 121 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); | 122 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); |
| 122 ++it) { | 123 ++it) { |
| 123 std::string locale; | 124 std::string locale; |
| 124 if (!(*it)->GetAsString(&locale)) { | 125 if (!(*it)->GetAsString(&locale)) { |
| 125 NOTREACHED(); | 126 NOTREACHED(); |
| 126 new_recommended_locales.clear(); | 127 new_recommended_locales.clear(); |
| 127 break; | 128 break; |
| 128 } | 129 } |
| 129 new_recommended_locales.push_back(locale); | 130 new_recommended_locales.push_back(locale); |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 | 133 |
| 133 std::vector<std::string>& recommended_locales = | 134 std::vector<std::string>& recommended_locales = |
| 134 public_session_recommended_locales_[user_id]; | 135 public_session_recommended_locales_[account_id]; |
| 135 | 136 |
| 136 if (new_recommended_locales != recommended_locales) | 137 if (new_recommended_locales != recommended_locales) |
| 137 SetPublicSessionLocales(user_id, new_recommended_locales); | 138 SetPublicSessionLocales(account_id, new_recommended_locales); |
| 138 | 139 |
| 139 if (new_recommended_locales.empty()) | 140 if (new_recommended_locales.empty()) |
| 140 public_session_recommended_locales_.erase(user_id); | 141 public_session_recommended_locales_.erase(account_id); |
| 141 else | 142 else |
| 142 recommended_locales = new_recommended_locales; | 143 recommended_locales = new_recommended_locales; |
| 143 } | 144 } |
| 144 | 145 |
| 145 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( | 146 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( |
| 146 const std::string& user_id) { | 147 const AccountId& account_id) { |
| 147 const user_manager::User* user = user_manager::UserManager::Get()->FindUser( | 148 const user_manager::User* user = |
| 148 AccountId::FromUserEmail(user_id)); | 149 user_manager::UserManager::Get()->FindUser(account_id); |
| 149 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 150 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
| 150 return; | 151 return; |
| 151 | 152 |
| 152 view_->SetPublicSessionDisplayName(user_id, | 153 view_->SetPublicSessionDisplayName(account_id, |
| 153 base::UTF16ToUTF8(user->GetDisplayName())); | 154 base::UTF16ToUTF8(user->GetDisplayName())); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void ChromeUserSelectionScreen::SetPublicSessionLocales( | 157 void ChromeUserSelectionScreen::SetPublicSessionLocales( |
| 157 const std::string& user_id, | 158 const AccountId& account_id, |
| 158 const std::vector<std::string>& recommended_locales) { | 159 const std::vector<std::string>& recommended_locales) { |
| 159 if (!handler_initialized_) | 160 if (!handler_initialized_) |
| 160 return; | 161 return; |
| 161 | 162 |
| 162 // Construct the list of available locales. This list consists of the | 163 // Construct the list of available locales. This list consists of the |
| 163 // recommended locales, followed by all others. | 164 // recommended locales, followed by all others. |
| 164 scoped_ptr<base::ListValue> available_locales = | 165 scoped_ptr<base::ListValue> available_locales = |
| 165 GetUILanguageList(&recommended_locales, std::string()); | 166 GetUILanguageList(&recommended_locales, std::string()); |
| 166 | 167 |
| 167 // Set the initially selected locale to the first recommended locale that is | 168 // Set the initially selected locale to the first recommended locale that is |
| 168 // actually available or the current UI locale if none of them are available. | 169 // actually available or the current UI locale if none of them are available. |
| 169 const std::string default_locale = FindMostRelevantLocale( | 170 const std::string default_locale = FindMostRelevantLocale( |
| 170 recommended_locales, | 171 recommended_locales, |
| 171 *available_locales.get(), | 172 *available_locales.get(), |
| 172 g_browser_process->GetApplicationLocale()); | 173 g_browser_process->GetApplicationLocale()); |
| 173 | 174 |
| 174 // Set a flag to indicate whether the list of recommended locales contains at | 175 // Set a flag to indicate whether the list of recommended locales contains at |
| 175 // least two entries. This is used to decide whether the public session pod | 176 // least two entries. This is used to decide whether the public session pod |
| 176 // expands to its basic form (for zero or one recommended locales) or the | 177 // expands to its basic form (for zero or one recommended locales) or the |
| 177 // advanced form (two or more recommended locales). | 178 // advanced form (two or more recommended locales). |
| 178 const bool two_or_more_recommended_locales = recommended_locales.size() >= 2; | 179 const bool two_or_more_recommended_locales = recommended_locales.size() >= 2; |
| 179 | 180 |
| 180 // Notify the UI. | 181 // Notify the UI. |
| 181 view_->SetPublicSessionLocales(user_id, available_locales.Pass(), | 182 view_->SetPublicSessionLocales(account_id, available_locales.Pass(), |
| 182 default_locale, | 183 default_locale, |
| 183 two_or_more_recommended_locales); | 184 two_or_more_recommended_locales); |
| 184 } | 185 } |
| 185 | 186 |
| 186 } // namespace chromeos | 187 } // namespace chromeos |
| OLD | NEW |