| 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 "ash/metrics/user_metrics_recorder.h" | 5 #include "ash/metrics/user_metrics_recorder.h" |
| 6 | 6 |
| 7 #include "ash/common/metrics/pointer_metrics_recorder.h" | 7 #include "ash/common/metrics/pointer_metrics_recorder.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/shelf/shelf_model.h" | 10 #include "ash/common/shelf/shelf_model.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // Time in seconds between calls to "RecordPeriodicMetrics". | 31 // Time in seconds between calls to "RecordPeriodicMetrics". |
| 32 const int kAshPeriodicMetricsTimeInSeconds = 30 * 60; | 32 const int kAshPeriodicMetricsTimeInSeconds = 30 * 60; |
| 33 | 33 |
| 34 enum ActiveWindowStateType { | 34 enum ActiveWindowStateType { |
| 35 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW, | 35 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW, |
| 36 ACTIVE_WINDOW_STATE_TYPE_OTHER, | 36 ACTIVE_WINDOW_STATE_TYPE_OTHER, |
| 37 ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED, | 37 ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED, |
| 38 ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN, | 38 ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN, |
| 39 ACTIVE_WINDOW_STATE_TYPE_SNAPPED, | 39 ACTIVE_WINDOW_STATE_TYPE_SNAPPED, |
| 40 ACTIVE_WINDOW_STATE_TYPE_DOCKED, | |
| 41 ACTIVE_WINDOW_STATE_TYPE_PINNED, | 40 ACTIVE_WINDOW_STATE_TYPE_PINNED, |
| 42 ACTIVE_WINDOW_STATE_TYPE_TRUSTED_PINNED, | 41 ACTIVE_WINDOW_STATE_TYPE_TRUSTED_PINNED, |
| 43 ACTIVE_WINDOW_STATE_TYPE_COUNT, | 42 ACTIVE_WINDOW_STATE_TYPE_COUNT, |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 ActiveWindowStateType GetActiveWindowState() { | 45 ActiveWindowStateType GetActiveWindowState() { |
| 47 ActiveWindowStateType active_window_state_type = | 46 ActiveWindowStateType active_window_state_type = |
| 48 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW; | 47 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW; |
| 49 wm::WindowState* active_window_state = ash::wm::GetActiveWindowState(); | 48 wm::WindowState* active_window_state = ash::wm::GetActiveWindowState(); |
| 50 if (active_window_state) { | 49 if (active_window_state) { |
| 51 switch (active_window_state->GetStateType()) { | 50 switch (active_window_state->GetStateType()) { |
| 52 case wm::WINDOW_STATE_TYPE_MAXIMIZED: | 51 case wm::WINDOW_STATE_TYPE_MAXIMIZED: |
| 53 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED; | 52 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED; |
| 54 break; | 53 break; |
| 55 case wm::WINDOW_STATE_TYPE_FULLSCREEN: | 54 case wm::WINDOW_STATE_TYPE_FULLSCREEN: |
| 56 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN; | 55 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN; |
| 57 break; | 56 break; |
| 58 case wm::WINDOW_STATE_TYPE_LEFT_SNAPPED: | 57 case wm::WINDOW_STATE_TYPE_LEFT_SNAPPED: |
| 59 case wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED: | 58 case wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED: |
| 60 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_SNAPPED; | 59 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_SNAPPED; |
| 61 break; | 60 break; |
| 62 case wm::WINDOW_STATE_TYPE_DOCKED: | |
| 63 case wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED: | |
| 64 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_DOCKED; | |
| 65 break; | |
| 66 case wm::WINDOW_STATE_TYPE_PINNED: | 61 case wm::WINDOW_STATE_TYPE_PINNED: |
| 67 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_PINNED; | 62 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_PINNED; |
| 68 break; | 63 break; |
| 69 case wm::WINDOW_STATE_TYPE_TRUSTED_PINNED: | 64 case wm::WINDOW_STATE_TYPE_TRUSTED_PINNED: |
| 70 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_TRUSTED_PINNED; | 65 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_TRUSTED_PINNED; |
| 71 break; | 66 break; |
| 72 case wm::WINDOW_STATE_TYPE_DEFAULT: | 67 case wm::WINDOW_STATE_TYPE_DEFAULT: |
| 73 case wm::WINDOW_STATE_TYPE_NORMAL: | 68 case wm::WINDOW_STATE_TYPE_NORMAL: |
| 74 case wm::WINDOW_STATE_TYPE_MINIMIZED: | 69 case wm::WINDOW_STATE_TYPE_MINIMIZED: |
| 75 case wm::WINDOW_STATE_TYPE_INACTIVE: | 70 case wm::WINDOW_STATE_TYPE_INACTIVE: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 108 } |
| 114 NOTREACHED(); | 109 NOTREACHED(); |
| 115 return false; | 110 return false; |
| 116 } | 111 } |
| 117 | 112 |
| 118 // Array of window container ids that contain visible windows to be counted for | 113 // Array of window container ids that contain visible windows to be counted for |
| 119 // UMA statistics. Note the containers are ordered from top most visible | 114 // UMA statistics. Note the containers are ordered from top most visible |
| 120 // container to the lowest to allow the |GetNumVisibleWindows| method to short | 115 // container to the lowest to allow the |GetNumVisibleWindows| method to short |
| 121 // circuit when processing a maximized or fullscreen window. | 116 // circuit when processing a maximized or fullscreen window. |
| 122 int kVisibleWindowContainerIds[] = { | 117 int kVisibleWindowContainerIds[] = { |
| 123 kShellWindowId_PanelContainer, kShellWindowId_DockedContainer, | 118 kShellWindowId_PanelContainer, |
| 124 kShellWindowId_AlwaysOnTopContainer, kShellWindowId_DefaultContainer}; | 119 kShellWindowId_AlwaysOnTopContainer, |
| 120 kShellWindowId_DefaultContainer |
| 121 }; |
| 125 | 122 |
| 126 // Returns an approximate count of how many windows are currently visible in the | 123 // Returns an approximate count of how many windows are currently visible in the |
| 127 // primary root window. | 124 // primary root window. |
| 128 int GetNumVisibleWindowsInPrimaryDisplay() { | 125 int GetNumVisibleWindowsInPrimaryDisplay() { |
| 129 int visible_window_count = 0; | 126 int visible_window_count = 0; |
| 130 bool maximized_or_fullscreen_window_present = false; | 127 bool maximized_or_fullscreen_window_present = false; |
| 131 | 128 |
| 132 for (const int& current_container_id : kVisibleWindowContainerIds) { | 129 for (const int& current_container_id : kVisibleWindowContainerIds) { |
| 133 if (maximized_or_fullscreen_window_present) | 130 if (maximized_or_fullscreen_window_present) |
| 134 break; | 131 break; |
| 135 | 132 |
| 136 const aura::Window::Windows& children = | 133 const aura::Window::Windows& children = |
| 137 Shell::GetContainer(Shell::GetInstance()->GetPrimaryRootWindow(), | 134 Shell::GetContainer(Shell::GetInstance()->GetPrimaryRootWindow(), |
| 138 current_container_id) | 135 current_container_id) |
| 139 ->children(); | 136 ->children(); |
| 140 // Reverse iterate over the child windows so that they are processed in | 137 // Reverse iterate over the child windows so that they are processed in |
| 141 // visible stacking order. | 138 // visible stacking order. |
| 142 for (aura::Window::Windows::const_reverse_iterator it = children.rbegin(), | 139 for (aura::Window::Windows::const_reverse_iterator it = children.rbegin(), |
| 143 rend = children.rend(); | 140 rend = children.rend(); |
| 144 it != rend; ++it) { | 141 it != rend; ++it) { |
| 145 const aura::Window* child_window = *it; | 142 const aura::Window* child_window = *it; |
| 146 const wm::WindowState* child_window_state = | 143 const wm::WindowState* child_window_state = |
| 147 wm::GetWindowState(child_window); | 144 wm::GetWindowState(child_window); |
| 148 | 145 |
| 149 if (!child_window->IsVisible() || child_window_state->IsMinimized()) | 146 if (!child_window->IsVisible() || child_window_state->IsMinimized()) |
| 150 continue; | 147 continue; |
| 151 | 148 |
| 152 // Only count activatable windows for 2 reasons: | 149 // Only count activatable windows for 1 reason: |
| 153 // 1. Ensures that a browser window and its transient, modal child will | 150 // - Ensures that a browser window and its transient, modal child will |
| 154 // only count as 1 visible window. | 151 // only count as 1 visible window. |
| 155 // 2. Prevents counting some windows in the | |
| 156 // kShellWindowId_DockedContainer that were not opened by the user. | |
| 157 if (child_window_state->CanActivate()) | 152 if (child_window_state->CanActivate()) |
| 158 ++visible_window_count; | 153 ++visible_window_count; |
| 159 | 154 |
| 160 // Stop counting windows that will be hidden by maximized or fullscreen | 155 // Stop counting windows that will be hidden by maximized or fullscreen |
| 161 // windows. Only windows in the kShellWindowId_DefaultContainer and | 156 // windows. Only windows in the kShellWindowId_DefaultContainer and |
| 162 // kShellWindowId_AlwaysOnTopContainer can be maximized or fullscreened | 157 // kShellWindowId_AlwaysOnTopContainer can be maximized or fullscreened |
| 163 // and completely obscure windows beneath them. | 158 // and completely obscure windows beneath them. |
| 164 if ((kShellWindowId_DefaultContainer == current_container_id || | 159 if ((kShellWindowId_DefaultContainer == current_container_id || |
| 165 kShellWindowId_AlwaysOnTopContainer == current_container_id) && | 160 kShellWindowId_AlwaysOnTopContainer == current_container_id) && |
| 166 child_window_state->IsMaximizedOrFullscreenOrPinned()) { | 161 child_window_state->IsMaximizedOrFullscreenOrPinned()) { |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 return IsUserActive() && !IsKioskModeActive() && !IsArcKioskModeActive(); | 641 return IsUserActive() && !IsKioskModeActive() && !IsArcKioskModeActive(); |
| 647 } | 642 } |
| 648 | 643 |
| 649 void UserMetricsRecorder::StartTimer() { | 644 void UserMetricsRecorder::StartTimer() { |
| 650 timer_.Start(FROM_HERE, | 645 timer_.Start(FROM_HERE, |
| 651 base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds), | 646 base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds), |
| 652 this, &UserMetricsRecorder::RecordPeriodicMetrics); | 647 this, &UserMetricsRecorder::RecordPeriodicMetrics); |
| 653 } | 648 } |
| 654 | 649 |
| 655 } // namespace ash | 650 } // namespace ash |
| OLD | NEW |