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