OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/ash/multi_user/multi_user_context_menu.h" | 5 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
6 | 6 |
7 #include "ash/multi_profile_uma.h" | 7 #include "ash/multi_profile_uma.h" |
8 #include "ash/session/session_state_delegate.h" | 8 #include "ash/session/session_state_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 ash::SessionStateDelegate* delegate = | 69 ash::SessionStateDelegate* delegate = |
70 ash::Shell::GetInstance()->session_state_delegate(); | 70 ash::Shell::GetInstance()->session_state_delegate(); |
71 if (!delegate) | 71 if (!delegate) |
72 return model.Pass(); | 72 return model.Pass(); |
73 | 73 |
74 int logged_in_users = delegate->NumberOfLoggedInUsers(); | 74 int logged_in_users = delegate->NumberOfLoggedInUsers(); |
75 if (logged_in_users > 1) { | 75 if (logged_in_users > 1) { |
76 // If this window is not owned, we don't show the menu addition. | 76 // If this window is not owned, we don't show the menu addition. |
77 chrome::MultiUserWindowManager* manager = | 77 chrome::MultiUserWindowManager* manager = |
78 chrome::MultiUserWindowManager::GetInstance(); | 78 chrome::MultiUserWindowManager::GetInstance(); |
79 const std::string user_id = manager->GetWindowOwner(window); | 79 const AccountId& account_id = manager->GetWindowOwner(window); |
80 if (user_id.empty() || !window) | 80 if (!account_id.is_valid() || !window) |
81 return model.Pass(); | 81 return model.Pass(); |
82 chromeos::MultiUserContextMenuChromeos* menu = | 82 chromeos::MultiUserContextMenuChromeos* menu = |
83 new chromeos::MultiUserContextMenuChromeos(window); | 83 new chromeos::MultiUserContextMenuChromeos(window); |
84 model.reset(menu); | 84 model.reset(menu); |
85 for (int user_index = 1; user_index < logged_in_users; ++user_index) { | 85 for (int user_index = 1; user_index < logged_in_users; ++user_index) { |
86 const user_manager::UserInfo* user_info = | 86 const user_manager::UserInfo* user_info = |
87 delegate->GetUserInfo(user_index); | 87 delegate->GetUserInfo(user_index); |
88 menu->AddItem(user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 | 88 menu->AddItem(user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 |
89 : IDC_VISIT_DESKTOP_OF_LRU_USER_3, | 89 : IDC_VISIT_DESKTOP_OF_LRU_USER_3, |
90 l10n_util::GetStringFUTF16( | 90 l10n_util::GetStringFUTF16( |
91 IDS_VISIT_DESKTOP_OF_LRU_USER, | 91 IDS_VISIT_DESKTOP_OF_LRU_USER, |
92 user_info->GetDisplayName(), | 92 user_info->GetDisplayName(), |
93 base::ASCIIToUTF16(user_info->GetEmail()))); | 93 base::ASCIIToUTF16(user_info->GetEmail()))); |
94 } | 94 } |
95 } | 95 } |
96 return model.Pass(); | 96 return model.Pass(); |
97 } | 97 } |
98 | 98 |
99 void OnAcceptTeleportWarning(const AccountId& account_id, | 99 void OnAcceptTeleportWarning(const AccountId& account_id, |
100 aura::Window* window_, | 100 aura::Window* window_, |
101 bool no_show_again) { | 101 bool no_show_again) { |
102 PrefService* pref = ProfileManager::GetActiveUserProfile()->GetPrefs(); | 102 PrefService* pref = ProfileManager::GetActiveUserProfile()->GetPrefs(); |
103 pref->SetBoolean(prefs::kMultiProfileWarningShowDismissed, no_show_again); | 103 pref->SetBoolean(prefs::kMultiProfileWarningShowDismissed, no_show_again); |
104 | 104 |
105 ash::MultiProfileUMA::RecordTeleportAction( | 105 ash::MultiProfileUMA::RecordTeleportAction( |
106 ash::MultiProfileUMA::TELEPORT_WINDOW_CAPTION_MENU); | 106 ash::MultiProfileUMA::TELEPORT_WINDOW_CAPTION_MENU); |
107 | 107 |
108 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( | 108 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(window_, |
109 window_, account_id.GetUserEmail()); | 109 account_id); |
110 } | 110 } |
111 | 111 |
112 void ExecuteVisitDesktopCommand(int command_id, aura::Window* window) { | 112 void ExecuteVisitDesktopCommand(int command_id, aura::Window* window) { |
113 switch (command_id) { | 113 switch (command_id) { |
114 case IDC_VISIT_DESKTOP_OF_LRU_USER_2: | 114 case IDC_VISIT_DESKTOP_OF_LRU_USER_2: |
115 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: { | 115 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: { |
116 // When running the multi user mode on Chrome OS, windows can "visit" | 116 // When running the multi user mode on Chrome OS, windows can "visit" |
117 // another user's desktop. | 117 // another user's desktop. |
118 const AccountId account_id = | 118 const AccountId account_id = |
119 ash::Shell::GetInstance() | 119 ash::Shell::GetInstance() |
120 ->session_state_delegate() | 120 ->session_state_delegate() |
121 ->GetUserInfo(IDC_VISIT_DESKTOP_OF_LRU_USER_2 == command_id ? 1 | 121 ->GetUserInfo(IDC_VISIT_DESKTOP_OF_LRU_USER_2 == command_id ? 1 |
122 : 2) | 122 : 2) |
123 ->GetAccountId(); | 123 ->GetAccountId(); |
124 base::Callback<void(bool)> on_accept = | 124 base::Callback<void(bool)> on_accept = |
125 base::Bind(&OnAcceptTeleportWarning, account_id, window); | 125 base::Bind(&OnAcceptTeleportWarning, account_id, window); |
126 | 126 |
127 // Don't show warning dialog if any logged in user in multi-profiles | 127 // Don't show warning dialog if any logged in user in multi-profiles |
128 // session dismissed it. | 128 // session dismissed it. |
129 const user_manager::UserList logged_in_users = | 129 const user_manager::UserList logged_in_users = |
130 user_manager::UserManager::Get()->GetLoggedInUsers(); | 130 user_manager::UserManager::Get()->GetLoggedInUsers(); |
131 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); | 131 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); |
132 it != logged_in_users.end(); | 132 it != logged_in_users.end(); |
133 ++it) { | 133 ++it) { |
134 if (multi_user_util::GetProfileFromUserID( | 134 if (multi_user_util::GetProfileFromAccountId((*it)->GetAccountId()) |
135 multi_user_util::GetUserIDFromEmail((*it)->email()))->GetPrefs()-> | 135 ->GetPrefs() |
136 GetBoolean(prefs::kMultiProfileWarningShowDismissed)) { | 136 ->GetBoolean(prefs::kMultiProfileWarningShowDismissed)) { |
137 bool active_user_show_option = | 137 bool active_user_show_option = |
138 ProfileManager::GetActiveUserProfile()-> | 138 ProfileManager::GetActiveUserProfile()-> |
139 GetPrefs()->GetBoolean(prefs::kMultiProfileWarningShowDismissed); | 139 GetPrefs()->GetBoolean(prefs::kMultiProfileWarningShowDismissed); |
140 on_accept.Run(active_user_show_option); | 140 on_accept.Run(active_user_show_option); |
141 return; | 141 return; |
142 } | 142 } |
143 } | 143 } |
144 chromeos::ShowMultiprofilesWarningDialog(on_accept); | 144 chromeos::ShowMultiprofilesWarningDialog(on_accept); |
145 return; | 145 return; |
146 } | 146 } |
147 default: | 147 default: |
148 NOTREACHED(); | 148 NOTREACHED(); |
149 } | 149 } |
150 } | 150 } |
OLD | NEW |