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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
7 #include "ash/multi_profile_uma.h"
8 #include "ash/session_state_delegate.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
13 #include "grit/generated_resources.h"
14 #include "ui/aura/window.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/models/simple_menu_model.h"
20 class MultiUserContextMenuChromeos
: public ui::SimpleMenuModel
,
21 public ui::SimpleMenuModel::Delegate
{
23 explicit MultiUserContextMenuChromeos(aura::Window
* window
);
24 virtual ~MultiUserContextMenuChromeos() {}
26 // SimpleMenuModel::Delegate:
27 virtual bool IsCommandIdChecked(int command_id
) const OVERRIDE
{
30 virtual bool IsCommandIdEnabled(int command_id
) const OVERRIDE
{
33 virtual bool GetAcceleratorForCommandId(
35 ui::Accelerator
* accelerator
) OVERRIDE
{
38 virtual void ExecuteCommand(int command_id
, int event_flags
) OVERRIDE
;
41 // The window for which this menu is.
42 aura::Window
* window_
;
44 DISALLOW_COPY_AND_ASSIGN(MultiUserContextMenuChromeos
);
47 MultiUserContextMenuChromeos::MultiUserContextMenuChromeos(aura::Window
* window
)
48 : ui::SimpleMenuModel(this),
52 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id
,
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(
76 scoped_ptr
<ui::MenuModel
> CreateMultiUserContextMenu(
77 aura::Window
* window
) {
78 scoped_ptr
<ui::MenuModel
> model
;
79 ash::SessionStateDelegate
* delegate
=
80 ash::Shell::GetInstance()->session_state_delegate();
81 int logged_in_users
= delegate
->NumberOfLoggedInUsers();
82 if (delegate
&& logged_in_users
> 1) {
83 // If this window is not owned, we don't show the menu addition.
84 chrome::MultiUserWindowManager
* manager
=
85 chrome::MultiUserWindowManager::GetInstance();
86 const std::string user_id
= manager
->GetWindowOwner(window
);
87 if (user_id
.empty() || !window
||
88 manager
->GetWindowOwner(window
).empty())
90 MultiUserContextMenuChromeos
* menu
=
91 new MultiUserContextMenuChromeos(window
);
93 for (int user_index
= 1; user_index
< logged_in_users
; ++user_index
) {
95 user_index
== 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2
:
96 IDC_VISIT_DESKTOP_OF_LRU_USER_3
,
97 l10n_util::GetStringFUTF16(IDS_VISIT_DESKTOP_OF_LRU_USER
,
98 delegate
->GetUserDisplayName(