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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/browser_process_platform_part.h" | 15 #include "chrome/browser/browser_process_platform_part.h" |
16 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" | 16 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" |
17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
18 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" | 18 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
19 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 19 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
20 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
21 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 21 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
22 #include "components/policy/core/common/policy_map.h" | 22 #include "components/policy/core/common/policy_map.h" |
23 #include "components/policy/core/common/policy_types.h" | 23 #include "components/policy/core/common/policy_types.h" |
24 #include "components/user_manager/user.h" | 24 #include "components/user_manager/user.h" |
| 25 #include "components/user_manager/user_id.h" |
25 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
26 #include "components/user_manager/user_type.h" | 27 #include "components/user_manager/user_type.h" |
27 #include "policy/policy_constants.h" | 28 #include "policy/policy_constants.h" |
28 | 29 |
29 namespace chromeos { | 30 namespace chromeos { |
30 | 31 |
31 ChromeUserSelectionScreen::ChromeUserSelectionScreen( | 32 ChromeUserSelectionScreen::ChromeUserSelectionScreen( |
32 const std::string& display_type) | 33 const std::string& display_type) |
33 : UserSelectionScreen(display_type), | 34 : UserSelectionScreen(display_type), |
34 handler_initialized_(false), | 35 handler_initialized_(false), |
(...skipping 17 matching lines...) Expand all Loading... |
52 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 53 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
53 OnPolicyUpdated((*it)->GetUserID()); | 54 OnPolicyUpdated((*it)->GetUserID()); |
54 } | 55 } |
55 } | 56 } |
56 | 57 |
57 void ChromeUserSelectionScreen::SendUserList() { | 58 void ChromeUserSelectionScreen::SendUserList() { |
58 UserSelectionScreen::SendUserList(); | 59 UserSelectionScreen::SendUserList(); |
59 handler_initialized_ = true; | 60 handler_initialized_ = true; |
60 } | 61 } |
61 | 62 |
62 void ChromeUserSelectionScreen::OnPolicyUpdated(const std::string& user_id) { | 63 void ChromeUserSelectionScreen::OnPolicyUpdated(const user_manager::UserID& user
_id) { |
63 policy::DeviceLocalAccountPolicyBroker* broker = | 64 policy::DeviceLocalAccountPolicyBroker* broker = |
64 device_local_account_policy_service_->GetBrokerForUser(user_id); | 65 device_local_account_policy_service_->GetBrokerForUser(user_id); |
65 if (!broker) | 66 if (!broker) |
66 return; | 67 return; |
67 | 68 |
68 CheckForPublicSessionDisplayNameChange(broker); | 69 CheckForPublicSessionDisplayNameChange(broker); |
69 CheckForPublicSessionLocalePolicyChange(broker); | 70 CheckForPublicSessionLocalePolicyChange(broker); |
70 } | 71 } |
71 | 72 |
72 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { | 73 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { |
73 // 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 |
74 // entire UI is reloaded. | 75 // entire UI is reloaded. |
75 } | 76 } |
76 | 77 |
77 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( | 78 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
78 policy::DeviceLocalAccountPolicyBroker* broker) { | 79 policy::DeviceLocalAccountPolicyBroker* broker) { |
79 const std::string& user_id = broker->user_id(); | 80 const user_manager::UserID& user_id = broker->user_id(); |
80 const std::string& display_name = broker->GetDisplayName(); | 81 const std::string& display_name = broker->GetDisplayName(); |
81 if (display_name == public_session_display_names_[user_id]) | 82 if (display_name == public_session_display_names_[user_id]) |
82 return; | 83 return; |
83 | 84 |
84 public_session_display_names_[user_id] = display_name; | 85 public_session_display_names_[user_id] = display_name; |
85 | 86 |
86 if (!handler_initialized_) | 87 if (!handler_initialized_) |
87 return; | 88 return; |
88 | 89 |
89 if (!display_name.empty()) { | 90 if (!display_name.empty()) { |
90 // 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. |
91 view_->SetPublicSessionDisplayName(user_id, display_name); | 92 view_->SetPublicSessionDisplayName(user_id, display_name); |
92 return; | 93 return; |
93 } | 94 } |
94 | 95 |
95 // 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|, |
96 // 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| |
97 // 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 |
98 // 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 |
99 // been informed of the change. | 100 // been informed of the change. |
100 base::MessageLoop::current()->PostTask( | 101 base::MessageLoop::current()->PostTask( |
101 FROM_HERE, | 102 FROM_HERE, |
102 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, | 103 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, |
103 weak_factory_.GetWeakPtr(), | 104 weak_factory_.GetWeakPtr(), |
104 user_id)); | 105 user_id)); |
105 } | 106 } |
106 | 107 |
107 void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( | 108 void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( |
108 policy::DeviceLocalAccountPolicyBroker* broker) { | 109 policy::DeviceLocalAccountPolicyBroker* broker) { |
109 const std::string& user_id = broker->user_id(); | 110 const user_manager::UserID& user_id = broker->user_id(); |
110 const policy::PolicyMap::Entry* entry = | 111 const policy::PolicyMap::Entry* entry = |
111 broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); | 112 broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); |
112 | 113 |
113 // Parse the list of recommended locales set by policy. | 114 // Parse the list of recommended locales set by policy. |
114 std::vector<std::string> new_recommended_locales; | 115 std::vector<std::string> new_recommended_locales; |
115 base::ListValue const* list = NULL; | 116 base::ListValue const* list = NULL; |
116 if (entry && | 117 if (entry && |
117 entry->level == policy::POLICY_LEVEL_RECOMMENDED && | 118 entry->level == policy::POLICY_LEVEL_RECOMMENDED && |
118 entry->value && | 119 entry->value && |
119 entry->value->GetAsList(&list)) { | 120 entry->value->GetAsList(&list)) { |
(...skipping 15 matching lines...) Expand all Loading... |
135 if (new_recommended_locales != recommended_locales) | 136 if (new_recommended_locales != recommended_locales) |
136 SetPublicSessionLocales(user_id, new_recommended_locales); | 137 SetPublicSessionLocales(user_id, new_recommended_locales); |
137 | 138 |
138 if (new_recommended_locales.empty()) | 139 if (new_recommended_locales.empty()) |
139 public_session_recommended_locales_.erase(user_id); | 140 public_session_recommended_locales_.erase(user_id); |
140 else | 141 else |
141 recommended_locales = new_recommended_locales; | 142 recommended_locales = new_recommended_locales; |
142 } | 143 } |
143 | 144 |
144 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( | 145 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( |
145 const std::string& user_id) { | 146 const user_manager::UserID& user_id) { |
146 const user_manager::User* user = | 147 const user_manager::User* user = |
147 user_manager::UserManager::Get()->FindUser(user_id); | 148 user_manager::UserManager::Get()->FindUser(user_id); |
148 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 149 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
149 return; | 150 return; |
150 | 151 |
151 view_->SetPublicSessionDisplayName(user_id, | 152 view_->SetPublicSessionDisplayName(user_id, |
152 base::UTF16ToUTF8(user->GetDisplayName())); | 153 base::UTF16ToUTF8(user->GetDisplayName())); |
153 } | 154 } |
154 | 155 |
155 void ChromeUserSelectionScreen::SetPublicSessionLocales( | 156 void ChromeUserSelectionScreen::SetPublicSessionLocales( |
156 const std::string& user_id, | 157 const user_manager::UserID& user_id, |
157 const std::vector<std::string>& recommended_locales) { | 158 const std::vector<std::string>& recommended_locales) { |
158 if (!handler_initialized_) | 159 if (!handler_initialized_) |
159 return; | 160 return; |
160 | 161 |
161 // Construct the list of available locales. This list consists of the | 162 // Construct the list of available locales. This list consists of the |
162 // recommended locales, followed by all others. | 163 // recommended locales, followed by all others. |
163 scoped_ptr<base::ListValue> available_locales = | 164 scoped_ptr<base::ListValue> available_locales = |
164 GetUILanguageList(&recommended_locales, std::string()); | 165 GetUILanguageList(&recommended_locales, std::string()); |
165 | 166 |
166 // 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 |
167 // 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. |
168 const std::string default_locale = FindMostRelevantLocale( | 169 const std::string default_locale = FindMostRelevantLocale( |
169 recommended_locales, | 170 recommended_locales, |
170 *available_locales.get(), | 171 *available_locales.get(), |
171 g_browser_process->GetApplicationLocale()); | 172 g_browser_process->GetApplicationLocale()); |
172 | 173 |
173 // 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 |
174 // 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 |
175 // 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 |
176 // advanced form (two or more recommended locales). | 177 // advanced form (two or more recommended locales). |
177 const bool two_or_more_recommended_locales = recommended_locales.size() >= 2; | 178 const bool two_or_more_recommended_locales = recommended_locales.size() >= 2; |
178 | 179 |
179 // Notify the UI. | 180 // Notify the UI. |
180 view_->SetPublicSessionLocales(user_id, available_locales.Pass(), | 181 view_->SetPublicSessionLocales(user_id, available_locales.Pass(), |
181 default_locale, | 182 default_locale, |
182 two_or_more_recommended_locales); | 183 two_or_more_recommended_locales); |
183 } | 184 } |
184 | 185 |
185 } // namespace chromeos | 186 } // namespace chromeos |
OLD | NEW |