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. 4 5#include "ash/wm/overview/window_selector_controller.h" 6 7#include "ash/metrics/user_metrics_recorder.h" 8#include "ash/root_window_controller.h" 9#include "ash/session/session_state_delegate.h" 10#include "ash/shell.h" 11#include "ash/system/tray/system_tray_delegate.h" 12#include "ash/wm/mru_window_tracker.h" 13#include "ash/wm/overview/window_selector.h" 14#include "ash/wm/window_state.h" 15#include "ash/wm/window_util.h" 16#include "base/metrics/histogram.h" 17#include "ui/aura/window.h" 18 19namespace ash { 20 21WindowSelectorController::WindowSelectorController() { 22} 23 24WindowSelectorController::~WindowSelectorController() { 25} 26 27// static 28bool WindowSelectorController::CanSelect() { 29 // Don't allow a window overview if the screen is locked or a modal dialog is 30 // open or running in kiosk app session. 31 return Shell::GetInstance()->session_state_delegate()-> 32 IsActiveUserSessionStarted() && 33 !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && 34 !Shell::GetInstance()->IsSystemModalWindowOpen() && 35 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() != 36 user::LOGGED_IN_KIOSK_APP; 37} 38 39void WindowSelectorController::ToggleOverview() { 40 if (IsSelecting()) { 41 OnSelectionEnded(); 42 } else { 43 // Don't start overview if window selection is not allowed. 44 if (!CanSelect()) 45 return; 46 47 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> 48 mru_window_tracker()->BuildMruWindowList(); 49 // Don't enter overview mode with no windows. 50 if (windows.empty()) 51 return; 52 53 window_selector_.reset(new WindowSelector(windows, this)); 54 OnSelectionStarted(); 55 } 56} 57 58bool WindowSelectorController::IsSelecting() { 59 return window_selector_.get() != NULL; 60} 61 62// TODO(flackr): Make WindowSelectorController observe the activation of 63// windows, so we can remove WindowSelectorDelegate. 64void WindowSelectorController::OnSelectionEnded() { 65 window_selector_.reset(); 66 last_selection_time_ = base::Time::Now(); 67} 68 69void WindowSelectorController::OnSelectionStarted() { 70 if (!last_selection_time_.is_null()) { 71 UMA_HISTOGRAM_LONG_TIMES( 72 "Ash.WindowSelector.TimeBetweenUse", 73 base::Time::Now() - last_selection_time_); 74 } 75} 76 77} // namespace ash 78