Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: chrome/browser/chromeos/login/screens/chrome_user_selection_screen.cc

Issue 427053002: Do not reload account picker when device-local account policy changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Moved policy code to Chrome-specific subclass. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/browser_process_platform_part.h"
13 #include "chrome/browser/chromeos/login/users/user_manager.h"
14 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
15 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
16 #include "components/user_manager/user.h"
17 #include "components/user_manager/user_type.h"
18
19 namespace chromeos {
20
21 ChromeUserSelectionScreen::ChromeUserSelectionScreen()
22 : handler_initialized_(false),
23 weak_factory_(this) {
24 device_local_account_policy_service_ = g_browser_process->platform_part()->
25 browser_policy_connector_chromeos()->GetDeviceLocalAccountPolicyService();
26 device_local_account_policy_service_->AddObserver(this);
27 }
28
29 ChromeUserSelectionScreen::~ChromeUserSelectionScreen() {
30 device_local_account_policy_service_->RemoveObserver(this);
31 }
32
33 void ChromeUserSelectionScreen::Init(const user_manager::UserList& users,
34 bool show_guest) {
35 UserSelectionScreen::Init(users, show_guest);
36
37 // Retrieve the current policy for |users_|.
38 for (user_manager::UserList::const_iterator it = users_.begin();
Nikita (slow) 2014/08/05 12:09:24 nit: You may as well add GetUsers() getter.
bartfab (slow) 2014/08/05 18:52:02 Sorry, I do not understand. Where would you like m
Nikita (slow) 2014/08/06 08:14:40 I mean instead of having users_ as a protected fie
bartfab (slow) 2014/08/07 14:14:50 Thanks, somehow I did not realize that: a) using a
39 it != users_.end(); ++it) {
40 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT)
41 OnPolicyUpdated((*it)->GetUserID());
42 }
43 }
44
45 void ChromeUserSelectionScreen::SendUserList() {
46 UserSelectionScreen::SendUserList();
47 handler_initialized_ = true;
48 }
49
50 void ChromeUserSelectionScreen::OnPolicyUpdated(const std::string& user_id) {
51 policy::DeviceLocalAccountPolicyBroker* broker =
52 device_local_account_policy_service_->GetBrokerForUser(user_id);
53 if (!broker)
54 return;
55
56 CheckForPublicSessionDisplayNameChange(broker);
57 }
58
59 void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() {
60 // Nothing to do here. When the list of device-local accounts changes, the
61 // entire UI is reloaded.
62 }
63
64 void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange(
65 policy::DeviceLocalAccountPolicyBroker* broker) {
66 const std::string& user_id = broker->user_id();
67 const std::string& display_name = broker->GetDisplayName();
68 if (display_name == public_session_display_names_[user_id])
69 return;
70
71 public_session_display_names_[user_id] = display_name;
72
73 if (!handler_initialized_)
74 return;
75
76 if (!display_name.empty()) {
77 // If a new display name was set by policy, notify the UI about it.
78 handler_->SetPublicSessionDisplayName(user_id, display_name);
79 return;
80 }
81
82 // When no display name is set by policy, the |User|, owned by |UserManager|,
83 // decides what display name to use. However, the order in which |UserManager|
84 // 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
86 // been informed of the change.
87 base::MessageLoop::current()->PostTask(
88 FROM_HERE,
89 base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName,
90 weak_factory_.GetWeakPtr(),
91 user_id));
92 }
93
94 void ChromeUserSelectionScreen::SetPublicSessionDisplayName(
95 const std::string& user_id) {
96 const user_manager::User* user = UserManager::Get()->FindUser(user_id);
97 if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT)
98 return;
99
100 handler_->SetPublicSessionDisplayName(
101 user_id,
102 base::UTF16ToUTF8(user->GetDisplayName()));
103 }
104
105 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698