 Chromium Code Reviews
 Chromium Code Reviews 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
    
  
    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| 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_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 "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" | 
| 14 #include "chrome/browser/chromeos/login/user.h" | |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/browser/profiles/profile_manager.h" | |
| 11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 18 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 
| 19 #include "chrome/browser/ui/ash/multi_user/multi_user_warning_dialog.h" | |
| 12 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 20 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 
| 21 #include "chrome/common/pref_names.h" | |
| 13 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" | 
| 14 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" | 
| 15 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" | 
| 16 #include "ui/base/models/simple_menu_model.h" | 25 #include "ui/base/models/simple_menu_model.h" | 
| 17 | 26 | 
| 27 namespace chromeos { | |
| 28 | |
| 18 namespace { | 29 namespace { | 
| 19 | 30 | 
| 20 class MultiUserContextMenuChromeos : public ui::SimpleMenuModel, | 31 class MultiUserContextMenuChromeos : public ui::SimpleMenuModel, | 
| 21 public ui::SimpleMenuModel::Delegate { | 32 public ui::SimpleMenuModel::Delegate { | 
| 22 public: | 33 public: | 
| 23 explicit MultiUserContextMenuChromeos(aura::Window* window); | 34 explicit MultiUserContextMenuChromeos(aura::Window* window); | 
| 24 virtual ~MultiUserContextMenuChromeos() {} | 35 virtual ~MultiUserContextMenuChromeos() {} | 
| 25 | 36 | 
| 26 // SimpleMenuModel::Delegate: | 37 // SimpleMenuModel::Delegate: | 
| 27 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { | 38 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 44 DISALLOW_COPY_AND_ASSIGN(MultiUserContextMenuChromeos); | 55 DISALLOW_COPY_AND_ASSIGN(MultiUserContextMenuChromeos); | 
| 45 }; | 56 }; | 
| 46 | 57 | 
| 47 MultiUserContextMenuChromeos::MultiUserContextMenuChromeos(aura::Window* window) | 58 MultiUserContextMenuChromeos::MultiUserContextMenuChromeos(aura::Window* window) | 
| 48 : ui::SimpleMenuModel(this), | 59 : ui::SimpleMenuModel(this), | 
| 49 window_(window) { | 60 window_(window) { | 
| 50 } | 61 } | 
| 51 | 62 | 
| 52 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id, | 63 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id, | 
| 53 int event_flags) { | 64 int event_flags) { | 
| 54 switch (command_id) { | 65 ExecuteVisitDesktopCommand(command_id, window_); | 
| 55 case IDC_VISIT_DESKTOP_OF_LRU_USER_2: | |
| 56 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: { | |
| 57 ash::MultiProfileUMA::RecordTeleportAction( | |
| 58 ash::MultiProfileUMA::TELEPORT_WINDOW_CAPTION_MENU); | |
| 59 // When running the multi user mode on Chrome OS, windows can "visit" | |
| 60 // another user's desktop. | |
| 61 const std::string& user_id = | |
| 62 ash::Shell::GetInstance()->session_state_delegate()->GetUserID( | |
| 63 IDC_VISIT_DESKTOP_OF_LRU_USER_2 == command_id ? 1 : 2); | |
| 64 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( | |
| 65 window_, | |
| 66 user_id); | |
| 67 return; | |
| 68 } | |
| 69 default: | |
| 70 NOTREACHED(); | |
| 71 } | |
| 72 } | 66 } | 
| 73 | 67 | 
| 74 } // namespace | 68 } // namespace | 
| 69 } // namespace chromeos | |
| 75 | 70 | 
| 76 scoped_ptr<ui::MenuModel> CreateMultiUserContextMenu( | 71 scoped_ptr<ui::MenuModel> CreateMultiUserContextMenu( | 
| 77 aura::Window* window) { | 72 aura::Window* window) { | 
| 78 scoped_ptr<ui::MenuModel> model; | 73 scoped_ptr<ui::MenuModel> model; | 
| 79 ash::SessionStateDelegate* delegate = | 74 ash::SessionStateDelegate* delegate = | 
| 80 ash::Shell::GetInstance()->session_state_delegate(); | 75 ash::Shell::GetInstance()->session_state_delegate(); | 
| 81 int logged_in_users = delegate->NumberOfLoggedInUsers(); | 76 int logged_in_users = delegate->NumberOfLoggedInUsers(); | 
| 82 if (delegate && logged_in_users > 1) { | 77 if (delegate && logged_in_users > 1) { | 
| 83 // If this window is not owned, we don't show the menu addition. | 78 // If this window is not owned, we don't show the menu addition. | 
| 84 chrome::MultiUserWindowManager* manager = | 79 chrome::MultiUserWindowManager* manager = | 
| 85 chrome::MultiUserWindowManager::GetInstance(); | 80 chrome::MultiUserWindowManager::GetInstance(); | 
| 86 const std::string user_id = manager->GetWindowOwner(window); | 81 const std::string user_id = manager->GetWindowOwner(window); | 
| 87 if (user_id.empty() || !window || | 82 if (user_id.empty() || !window || | 
| 88 manager->GetWindowOwner(window).empty()) | 83 manager->GetWindowOwner(window).empty()) | 
| 89 return model.Pass(); | 84 return model.Pass(); | 
| 90 MultiUserContextMenuChromeos* menu = | 85 chromeos::MultiUserContextMenuChromeos* menu = | 
| 91 new MultiUserContextMenuChromeos(window); | 86 new chromeos::MultiUserContextMenuChromeos(window); | 
| 92 model.reset(menu); | 87 model.reset(menu); | 
| 93 for (int user_index = 1; user_index < logged_in_users; ++user_index) { | 88 for (int user_index = 1; user_index < logged_in_users; ++user_index) { | 
| 94 menu->AddItem( | 89 menu->AddItem( | 
| 95 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 : | 90 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 : | 
| 96 IDC_VISIT_DESKTOP_OF_LRU_USER_3, | 91 IDC_VISIT_DESKTOP_OF_LRU_USER_3, | 
| 97 l10n_util::GetStringFUTF16(IDS_VISIT_DESKTOP_OF_LRU_USER, | 92 l10n_util::GetStringFUTF16(IDS_VISIT_DESKTOP_OF_LRU_USER, | 
| 98 delegate->GetUserDisplayName( | 93 delegate->GetUserDisplayName( | 
| 99 user_index))); | 94 user_index))); | 
| 100 } | 95 } | 
| 101 } | 96 } | 
| 102 return model.Pass(); | 97 return model.Pass(); | 
| 103 } | 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 bool show_warning = true; | |
| 127 const chromeos::UserList logged_in_users = | |
| 128 chromeos::UserManager::Get()->GetLoggedInUsers(); | |
| 129 for (chromeos::UserList::const_iterator it = logged_in_users.begin(); | |
| 130 it != logged_in_users.end(); ++it) { | |
| 
Mr4D (OOO till 08-26)
2014/01/28 17:33:02
optional nit:
Why not doing "it != logged_in_users
 
merkulova
2014/01/29 09:11:19
Done.
 | |
| 131 show_warning &= !multi_user_util::GetProfileFromUserID( | |
| 132 multi_user_util::GetUserIDFromEmail((*it)->email()))->GetPrefs()-> | |
| 133 GetBoolean(prefs::kMultiProfileWarningShowDismissed); | |
| 134 if (!show_warning) | |
| 135 break; | |
| 136 } | |
| 137 if (show_warning) { | |
| 138 chromeos::ShowMultiprofilesWarningDialog(on_accept); | |
| 139 } else { | |
| 140 bool active_user_show_option = ProfileManager::GetActiveUserProfile()-> | |
| 141 GetPrefs()->GetBoolean(prefs::kMultiProfileWarningShowDismissed); | |
| 142 on_accept.Run(active_user_show_option); | |
| 143 } | |
| 144 return; | |
| 145 } | |
| 146 default: | |
| 147 NOTREACHED(); | |
| 148 } | |
| 149 } | |
| OLD | NEW |