Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / multi_user / multi_user_context_menu_chromeos.cc
blob595f02e2c43531a8470d00741ffdaaf33e0a635d
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"
9 #include "ash/shell.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"
18 namespace {
20 class MultiUserContextMenuChromeos : public ui::SimpleMenuModel,
21 public ui::SimpleMenuModel::Delegate {
22 public:
23 explicit MultiUserContextMenuChromeos(aura::Window* window);
24 virtual ~MultiUserContextMenuChromeos() {}
26 // SimpleMenuModel::Delegate:
27 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE {
28 return false;
30 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE {
31 return true;
33 virtual bool GetAcceleratorForCommandId(
34 int command_id,
35 ui::Accelerator* accelerator) OVERRIDE {
36 return false;
38 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
40 private:
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),
49 window_(window) {
52 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id,
53 int event_flags) {
54 switch (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(
65 window_,
66 user_id);
67 return;
69 default:
70 NOTREACHED();
74 } // namespace
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())
89 return model.Pass();
90 MultiUserContextMenuChromeos* menu =
91 new MultiUserContextMenuChromeos(window);
92 model.reset(menu);
93 for (int user_index = 1; user_index < logged_in_users; ++user_index) {
94 menu->AddItem(
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(
99 user_index)));
102 return model.Pass();