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" |
| 10 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" |
11 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/browser_process_platform_part.h" | 15 #include "chrome/browser/browser_process_platform_part.h" |
13 #include "chrome/browser/chromeos/login/users/user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/user_manager.h" |
14 #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" |
15 #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" |
| 21 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
| 22 #include "components/policy/core/common/policy_map.h" |
| 23 #include "components/policy/core/common/policy_types.h" |
16 #include "components/user_manager/user.h" | 24 #include "components/user_manager/user.h" |
17 #include "components/user_manager/user_type.h" | 25 #include "components/user_manager/user_type.h" |
| 26 #include "policy/policy_constants.h" |
18 | 27 |
19 namespace chromeos { | 28 namespace chromeos { |
20 | 29 |
21 ChromeUserSelectionScreen::ChromeUserSelectionScreen() | 30 ChromeUserSelectionScreen::ChromeUserSelectionScreen() |
22 : handler_initialized_(false), | 31 : handler_initialized_(false), |
23 weak_factory_(this) { | 32 weak_factory_(this) { |
24 device_local_account_policy_service_ = g_browser_process->platform_part()-> | 33 device_local_account_policy_service_ = g_browser_process->platform_part()-> |
25 browser_policy_connector_chromeos()->GetDeviceLocalAccountPolicyService(); | 34 browser_policy_connector_chromeos()->GetDeviceLocalAccountPolicyService(); |
26 device_local_account_policy_service_->AddObserver(this); | 35 device_local_account_policy_service_->AddObserver(this); |
27 } | 36 } |
(...skipping 19 matching lines...) Expand all Loading... |
47 handler_initialized_ = true; | 56 handler_initialized_ = true; |
48 } | 57 } |
49 | 58 |
50 void ChromeUserSelectionScreen::OnPolicyUpdated(const std::string& user_id) { | 59 void ChromeUserSelectionScreen::OnPolicyUpdated(const std::string& user_id) { |
51 policy::DeviceLocalAccountPolicyBroker* broker = | 60 policy::DeviceLocalAccountPolicyBroker* broker = |
52 device_local_account_policy_service_->GetBrokerForUser(user_id); | 61 device_local_account_policy_service_->GetBrokerForUser(user_id); |
53 if (!broker) | 62 if (!broker) |
54 return; | 63 return; |
55 | 64 |
56 CheckForPublicSessionDisplayNameChange(broker); | 65 CheckForPublicSessionDisplayNameChange(broker); |
| 66 CheckForPublicSessionLocalePolicyChange(broker); |
57 } | 67 } |
58 | 68 |
59 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { | 69 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() { |
60 // Nothing to do here. When the list of device-local accounts changes, the | 70 // Nothing to do here. When the list of device-local accounts changes, the |
61 // entire UI is reloaded. | 71 // entire UI is reloaded. |
62 } | 72 } |
63 | 73 |
64 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( | 74 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange( |
65 policy::DeviceLocalAccountPolicyBroker* broker) { | 75 policy::DeviceLocalAccountPolicyBroker* broker) { |
66 const std::string& user_id = broker->user_id(); | 76 const std::string& user_id = broker->user_id(); |
(...skipping 17 matching lines...) Expand all Loading... |
84 // and |this| are informed of the display name change is undefined. Post a | 94 // and |this| are informed of the display name change is undefined. Post a |
85 // task that will update the UI after the UserManager is guaranteed to have | 95 // task that will update the UI after the UserManager is guaranteed to have |
86 // been informed of the change. | 96 // been informed of the change. |
87 base::MessageLoop::current()->PostTask( | 97 base::MessageLoop::current()->PostTask( |
88 FROM_HERE, | 98 FROM_HERE, |
89 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, | 99 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName, |
90 weak_factory_.GetWeakPtr(), | 100 weak_factory_.GetWeakPtr(), |
91 user_id)); | 101 user_id)); |
92 } | 102 } |
93 | 103 |
| 104 void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange( |
| 105 policy::DeviceLocalAccountPolicyBroker* broker) { |
| 106 const std::string& user_id = broker->user_id(); |
| 107 const policy::PolicyMap::Entry* entry = |
| 108 broker->core()->store()->policy_map().Get(policy::key::kSessionLocales); |
| 109 |
| 110 // Parse the list of recommended locales set by policy. |
| 111 std::vector<std::string> new_recommended_locales; |
| 112 base::ListValue const* list = NULL; |
| 113 if (entry && |
| 114 entry->level == policy::POLICY_LEVEL_RECOMMENDED && |
| 115 entry->value && |
| 116 entry->value->GetAsList(&list)) { |
| 117 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); |
| 118 ++it) { |
| 119 std::string locale; |
| 120 if (!(*it)->GetAsString(&locale)) { |
| 121 NOTREACHED(); |
| 122 new_recommended_locales.clear(); |
| 123 break; |
| 124 } |
| 125 new_recommended_locales.push_back(locale); |
| 126 } |
| 127 } |
| 128 |
| 129 if (new_recommended_locales.empty()) { |
| 130 // There are no recommended locales. |
| 131 PublicSessionRecommendedLocaleMap::iterator it = |
| 132 public_session_recommended_locales_.find(user_id); |
| 133 if (it != public_session_recommended_locales_.end()) { |
| 134 // If there previously were recommended locales, remove them from |
| 135 // |public_session_recommended_locales_| and notify the UI. |
| 136 public_session_recommended_locales_.erase(it); |
| 137 SetPublicSessionLocales(user_id, &new_recommended_locales); |
| 138 } |
| 139 return; |
| 140 } |
| 141 |
| 142 // There are recommended locales. |
| 143 std::vector<std::string>& recommended_locales = |
| 144 public_session_recommended_locales_[user_id]; |
| 145 if (new_recommended_locales != recommended_locales) { |
| 146 // If the list of recommended locales has changed, update |
| 147 // |public_session_recommended_locales_| and notify the UI. |
| 148 recommended_locales = new_recommended_locales; |
| 149 SetPublicSessionLocales(user_id, &new_recommended_locales); |
| 150 } |
| 151 } |
| 152 |
94 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( | 153 void ChromeUserSelectionScreen::SetPublicSessionDisplayName( |
95 const std::string& user_id) { | 154 const std::string& user_id) { |
96 const user_manager::User* user = UserManager::Get()->FindUser(user_id); | 155 const user_manager::User* user = UserManager::Get()->FindUser(user_id); |
97 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 156 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT) |
98 return; | 157 return; |
99 | 158 |
100 handler_->SetPublicSessionDisplayName( | 159 handler_->SetPublicSessionDisplayName( |
101 user_id, | 160 user_id, |
102 base::UTF16ToUTF8(user->GetDisplayName())); | 161 base::UTF16ToUTF8(user->GetDisplayName())); |
103 } | 162 } |
104 | 163 |
| 164 void ChromeUserSelectionScreen::SetPublicSessionLocales( |
| 165 const std::string& user_id, |
| 166 const std::vector<std::string>* recommended_locales) { |
| 167 if (!handler_initialized_) |
| 168 return; |
| 169 |
| 170 // Construct the list of available locales. This list consists of the |
| 171 // recommended locales, followed by all others. |
| 172 scoped_ptr<base::ListValue> locales = |
| 173 GetUILanguageList(recommended_locales, std::string()); |
| 174 |
| 175 // Set the initially selected locale. If the list of recommended locales is |
| 176 // not empty, select its first entry. Otherwise, select the current UI locale. |
| 177 const std::string& default_locale = recommended_locales->empty() ? |
| 178 g_browser_process->GetApplicationLocale() : recommended_locales->front(); |
| 179 |
| 180 // Set a flag to indicate whether the list of recommended locales contains at |
| 181 // least two entries. This is used to decide whether the public session pod |
| 182 // expands to its basic form (for zero or one recommended locales) or the |
| 183 // advanced form (two or more recommended locales). |
| 184 const bool two_or_more_recommended_locales = recommended_locales->size() >= 2; |
| 185 |
| 186 // Notify the UI. |
| 187 handler_->SetPublicSessionLocales(user_id, |
| 188 locales.Pass(), |
| 189 default_locale, |
| 190 two_or_more_recommended_locales); |
| 191 } |
| 192 |
105 } // namespace chromeos | 193 } // namespace chromeos |
OLD | NEW |