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

Side by Side Diff: chrome/browser/ui/ash/multi_user/multi_user_context_menu_chromeos.cc

Issue 148093008: Create a dialog that warns about possible UI-oddities of the multi-profiles window teleport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments fix Created 6 years, 10 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
OLDNEW
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_state_delegate.h" 8 #include "ash/session_state_delegate.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/chromeos/login/user.h"
16 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 19 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
20 #include "chrome/browser/ui/ash/multi_user/multi_user_warning_dialog.h"
13 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 21 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
22 #include "chrome/common/pref_names.h"
14 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
15 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
16 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/models/simple_menu_model.h" 26 #include "ui/base/models/simple_menu_model.h"
18 27
28 namespace chromeos {
29
19 namespace { 30 namespace {
20 31
21 class MultiUserContextMenuChromeos : public ui::SimpleMenuModel, 32 class MultiUserContextMenuChromeos : public ui::SimpleMenuModel,
22 public ui::SimpleMenuModel::Delegate { 33 public ui::SimpleMenuModel::Delegate {
23 public: 34 public:
24 explicit MultiUserContextMenuChromeos(aura::Window* window); 35 explicit MultiUserContextMenuChromeos(aura::Window* window);
25 virtual ~MultiUserContextMenuChromeos() {} 36 virtual ~MultiUserContextMenuChromeos() {}
26 37
27 // SimpleMenuModel::Delegate: 38 // SimpleMenuModel::Delegate:
28 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { 39 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE {
(...skipping 16 matching lines...) Expand all
45 DISALLOW_COPY_AND_ASSIGN(MultiUserContextMenuChromeos); 56 DISALLOW_COPY_AND_ASSIGN(MultiUserContextMenuChromeos);
46 }; 57 };
47 58
48 MultiUserContextMenuChromeos::MultiUserContextMenuChromeos(aura::Window* window) 59 MultiUserContextMenuChromeos::MultiUserContextMenuChromeos(aura::Window* window)
49 : ui::SimpleMenuModel(this), 60 : ui::SimpleMenuModel(this),
50 window_(window) { 61 window_(window) {
51 } 62 }
52 63
53 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id, 64 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id,
54 int event_flags) { 65 int event_flags) {
55 switch (command_id) { 66 ExecuteVisitDesktopCommand(command_id, window_);
56 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
57 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: {
58 ash::MultiProfileUMA::RecordTeleportAction(
59 ash::MultiProfileUMA::TELEPORT_WINDOW_CAPTION_MENU);
60 // When running the multi user mode on Chrome OS, windows can "visit"
61 // another user's desktop.
62 const std::string& user_id =
63 ash::Shell::GetInstance()->session_state_delegate()->GetUserID(
64 IDC_VISIT_DESKTOP_OF_LRU_USER_2 == command_id ? 1 : 2);
65 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
66 window_,
67 user_id);
68 return;
69 }
70 default:
71 NOTREACHED();
72 }
73 } 67 }
68 } // namespace
69 } // namespace chromeos
74 70
75 } // namespace 71 scoped_ptr<ui::MenuModel> CreateMultiUserContextMenu(aura::Window* window) {
76
77 scoped_ptr<ui::MenuModel> CreateMultiUserContextMenu(
78 aura::Window* window) {
79 scoped_ptr<ui::MenuModel> model; 72 scoped_ptr<ui::MenuModel> model;
80 ash::SessionStateDelegate* delegate = 73 ash::SessionStateDelegate* delegate =
81 ash::Shell::GetInstance()->session_state_delegate(); 74 ash::Shell::GetInstance()->session_state_delegate();
82 int logged_in_users = delegate->NumberOfLoggedInUsers(); 75 int logged_in_users = delegate->NumberOfLoggedInUsers();
83 if (delegate && logged_in_users > 1) { 76 if (delegate && logged_in_users > 1) {
84 // If this window is not owned, we don't show the menu addition. 77 // If this window is not owned, we don't show the menu addition.
85 chrome::MultiUserWindowManager* manager = 78 chrome::MultiUserWindowManager* manager =
86 chrome::MultiUserWindowManager::GetInstance(); 79 chrome::MultiUserWindowManager::GetInstance();
87 const std::string user_id = manager->GetWindowOwner(window); 80 const std::string user_id = manager->GetWindowOwner(window);
88 if (user_id.empty() || !window || 81 if (user_id.empty() || !window ||
89 manager->GetWindowOwner(window).empty()) 82 manager->GetWindowOwner(window).empty())
90 return model.Pass(); 83 return model.Pass();
91 MultiUserContextMenuChromeos* menu = 84 chromeos::MultiUserContextMenuChromeos* menu =
92 new MultiUserContextMenuChromeos(window); 85 new chromeos::MultiUserContextMenuChromeos(window);
93 model.reset(menu); 86 model.reset(menu);
94 for (int user_index = 1; user_index < logged_in_users; ++user_index) { 87 for (int user_index = 1; user_index < logged_in_users; ++user_index) {
95 menu->AddItem( 88 menu->AddItem(
96 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 : 89 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 :
97 IDC_VISIT_DESKTOP_OF_LRU_USER_3, 90 IDC_VISIT_DESKTOP_OF_LRU_USER_3,
98 l10n_util::GetStringFUTF16( 91 l10n_util::GetStringFUTF16(
99 IDS_VISIT_DESKTOP_OF_LRU_USER, 92 IDS_VISIT_DESKTOP_OF_LRU_USER,
100 delegate->GetUserDisplayName(user_index), 93 delegate->GetUserDisplayName(user_index),
101 base::ASCIIToUTF16(delegate->GetUserEmail(user_index)))); 94 base::ASCIIToUTF16(delegate->GetUserEmail(user_index))));
102 } 95 }
103 } 96 }
104 return model.Pass(); 97 return model.Pass();
105 } 98 }
99
100 void OnAcceptTeleportWarning(
101 const std::string user_id, aura::Window* window_, bool no_show_again) {
102 PrefService* pref = ProfileManager::GetActiveUserProfile()->GetPrefs();
103 pref->SetBoolean(prefs::kMultiProfileWarningShowDismissed, no_show_again);
104
105 ash::MultiProfileUMA::RecordTeleportAction(
106 ash::MultiProfileUMA::TELEPORT_WINDOW_CAPTION_MENU);
107
108 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(window_,
109 user_id);
110 }
111
112 void ExecuteVisitDesktopCommand(int command_id, aura::Window* window) {
113 switch (command_id) {
114 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
115 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: {
116 // When running the multi user mode on Chrome OS, windows can "visit"
117 // another user's desktop.
118 const std::string& user_id =
119 ash::Shell::GetInstance()->session_state_delegate()->GetUserID(
120 IDC_VISIT_DESKTOP_OF_LRU_USER_2 == command_id ? 1 : 2);
121 base::Callback<void(bool)> on_accept =
122 base::Bind(&OnAcceptTeleportWarning, user_id, window);
123
124 // Don't show warning dialog if any logged in user in multi-profiles
125 // session dismissed it.
126 const chromeos::UserList logged_in_users =
127 chromeos::UserManager::Get()->GetLoggedInUsers();
128 for (chromeos::UserList::const_iterator it = logged_in_users.begin();
129 it != logged_in_users.end(); ++it) {
130 if (multi_user_util::GetProfileFromUserID(
131 multi_user_util::GetUserIDFromEmail((*it)->email()))->GetPrefs()->
132 GetBoolean(prefs::kMultiProfileWarningShowDismissed)) {
133 bool active_user_show_option =
134 ProfileManager::GetActiveUserProfile()->
135 GetPrefs()->GetBoolean(prefs::kMultiProfileWarningShowDismissed);
136 on_accept.Run(active_user_show_option);
137 return;
138 }
139 }
140 chromeos::ShowMultiprofilesWarningDialog(on_accept);
141 return;
142 }
143 default:
144 NOTREACHED();
145 }
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698