Home | History | Annotate | Download | only in metrics
      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/metrics/user_metrics_recorder.h"
      6 
      7 #include "ash/shelf/shelf_layout_manager.h"
      8 #include "ash/shelf/shelf_view.h"
      9 #include "ash/shelf/shelf_widget.h"
     10 #include "ash/shell.h"
     11 #include "ash/wm/window_state.h"
     12 #include "base/metrics/histogram.h"
     13 #include "content/public/browser/user_metrics.h"
     14 
     15 namespace ash {
     16 
     17 // Time in seconds between calls to "RecordPeriodicMetrics".
     18 const int kAshPeriodicMetricsTimeInSeconds = 30 * 60;
     19 
     20 UserMetricsRecorder::UserMetricsRecorder() {
     21   timer_.Start(FROM_HERE,
     22                base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds),
     23                this,
     24                &UserMetricsRecorder::RecordPeriodicMetrics);
     25 }
     26 
     27 UserMetricsRecorder::~UserMetricsRecorder() {
     28   timer_.Stop();
     29 }
     30 
     31 void UserMetricsRecorder::RecordUserMetricsAction(UserMetricsAction action) {
     32   switch (action) {
     33     case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6:
     34       content::RecordAction(
     35           content::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
     36       break;
     37     case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7:
     38       content::RecordAction(
     39           content::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
     40       break;
     41     case ash::UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON:
     42       content::RecordAction(
     43           content::UserMetricsAction("Accel_LockScreen_LockButton"));
     44       break;
     45     case ash::UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON:
     46       content::RecordAction(
     47           content::UserMetricsAction("Accel_LockScreen_PowerButton"));
     48       break;
     49     case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4:
     50       content::RecordAction(
     51           content::UserMetricsAction("Accel_Maximize_Restore_F4"));
     52       break;
     53     case ash::UMA_ACCEL_PREVWINDOW_F5:
     54       content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_F5"));
     55       break;
     56     case ash::UMA_ACCEL_EXIT_FIRST_Q:
     57       content::RecordAction(content::UserMetricsAction("Accel_Exit_First_Q"));
     58       break;
     59     case ash::UMA_ACCEL_EXIT_SECOND_Q:
     60       content::RecordAction(content::UserMetricsAction("Accel_Exit_Second_Q"));
     61       break;
     62     case ash::UMA_ACCEL_SHUT_DOWN_POWER_BUTTON:
     63       content::RecordAction(
     64           content::UserMetricsAction("Accel_ShutDown_PowerButton"));
     65       break;
     66     case ash::UMA_CLOSE_THROUGH_CONTEXT_MENU:
     67       content::RecordAction(content::UserMetricsAction("CloseFromContextMenu"));
     68       break;
     69     case ash::UMA_GESTURE_OVERVIEW:
     70       content::RecordAction(content::UserMetricsAction("Gesture_Overview"));
     71       break;
     72     case ash::UMA_LAUNCHER_CLICK_ON_APP:
     73       content::RecordAction(content::UserMetricsAction("Launcher_ClickOnApp"));
     74       break;
     75     case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON:
     76       content::RecordAction(
     77           content::UserMetricsAction("Launcher_ClickOnApplistButton"));
     78       break;
     79     case ash::UMA_MOUSE_DOWN:
     80       content::RecordAction(content::UserMetricsAction("Mouse_Down"));
     81       break;
     82     case ash::UMA_SHELF_ALIGNMENT_SET_BOTTOM:
     83       content::RecordAction(
     84           content::UserMetricsAction("Shelf_AlignmentSetBottom"));
     85       break;
     86     case ash::UMA_SHELF_ALIGNMENT_SET_LEFT:
     87       content::RecordAction(
     88           content::UserMetricsAction("Shelf_AlignmentSetLeft"));
     89       break;
     90     case ash::UMA_SHELF_ALIGNMENT_SET_RIGHT:
     91       content::RecordAction(
     92           content::UserMetricsAction("Shelf_AlignmentSetRight"));
     93     case ash::UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE:
     94       content::RecordAction(
     95           content::UserMetricsAction("StatusArea_Audio_CurrentInputDevice"));
     96       break;
     97     case ash::UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE:
     98       content::RecordAction(
     99           content::UserMetricsAction("StatusArea_Audio_CurrentOutputDevice"));
    100       break;
    101     case ash::UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE:
    102       content::RecordAction(
    103           content::UserMetricsAction("StatusArea_Audio_SwitchInputDevice"));
    104       break;
    105     case ash::UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE:
    106       content::RecordAction(
    107           content::UserMetricsAction("StatusArea_Audio_SwitchOutputDevice"));
    108       break;
    109     case ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED:
    110       content::RecordAction(
    111           content::UserMetricsAction("StatusArea_BrightnessChanged"));
    112       break;
    113     case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE:
    114       content::RecordAction(
    115           content::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
    116       break;
    117     case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE:
    118       content::RecordAction(
    119           content::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown"));
    120       break;
    121     case ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED:
    122       content::RecordAction(
    123           content::UserMetricsAction("StatusArea_Bluetooth_Disabled"));
    124       break;
    125     case ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED:
    126       content::RecordAction(
    127           content::UserMetricsAction("StatusArea_Bluetooth_Enabled"));
    128       break;
    129     case ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED:
    130       content::RecordAction(
    131           content::UserMetricsAction("StatusArea_CapsLock_Detailed"));
    132       break;
    133     case ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK:
    134       content::RecordAction(
    135           content::UserMetricsAction("StatusArea_CapsLock_DisabledByClick"));
    136       break;
    137     case ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK:
    138       content::RecordAction(
    139           content::UserMetricsAction("StatusArea_CapsLock_EnabledByClick"));
    140       break;
    141     case ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP:
    142       content::RecordAction(
    143           content::UserMetricsAction("StatusArea_CapsLock_Popup"));
    144       break;
    145     case ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK:
    146       content::RecordAction(
    147           content::UserMetricsAction("StatusArea_Network_ConnectConfigured"));
    148       break;
    149     case ash::UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK:
    150       content::RecordAction(
    151           content::UserMetricsAction("StatusArea_Network_ConnectUnconfigured"));
    152       break;
    153     case ash::UMA_STATUS_AREA_CONNECT_TO_VPN:
    154       content::RecordAction(
    155           content::UserMetricsAction("StatusArea_VPN_ConnectToNetwork"));
    156       break;
    157     case ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU:
    158       content::RecordAction(
    159           content::UserMetricsAction("StatusArea_Volume_ChangedMenu"));
    160       break;
    161     case ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP:
    162       content::RecordAction(
    163           content::UserMetricsAction("StatusArea_Volume_ChangedPopup"));
    164       break;
    165     case ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY:
    166       content::RecordAction(
    167           content::UserMetricsAction("StatusArea_Accessability_DetailedView"));
    168       break;
    169     case ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW:
    170       content::RecordAction(
    171           content::UserMetricsAction("StatusArea_Audio_Detailed"));
    172       break;
    173     case ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW:
    174       content::RecordAction(
    175           content::UserMetricsAction("StatusArea_Bluetooth_Detailed"));
    176       break;
    177     case ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW:
    178       content::RecordAction(
    179           content::UserMetricsAction("StatusArea_Brightness_Detailed"));
    180       break;
    181     case ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW:
    182       content::RecordAction(
    183           content::UserMetricsAction("StatusArea_Drive_Detailed"));
    184       break;
    185     case ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW:
    186       content::RecordAction(
    187           content::UserMetricsAction("StatusArea_Network_Detailed"));
    188       break;
    189     case ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW:
    190       content::RecordAction(
    191           content::UserMetricsAction("StatusArea_VPN_Detailed"));
    192       break;
    193     case ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK:
    194       content::RecordAction(
    195           content::UserMetricsAction("StatusArea_AutoClickDisabled"));
    196       break;
    197     case ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST:
    198       content::RecordAction(
    199           content::UserMetricsAction("StatusArea_HighContrastDisabled"));
    200       break;
    201     case ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR:
    202       content::RecordAction(
    203           content::UserMetricsAction("StatusArea_LargeCursorDisabled"));
    204       break;
    205     case ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER:
    206       content::RecordAction(
    207           content::UserMetricsAction("StatusArea_MagnifierDisabled"));
    208       break;
    209     case ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK:
    210       content::RecordAction(
    211           content::UserMetricsAction("StatusArea_SpokenFeedbackDisabled"));
    212       break;
    213     case ash::UMA_STATUS_AREA_DISABLE_WIFI:
    214       content::RecordAction(
    215           content::UserMetricsAction("StatusArea_Network_WifiDisabled"));
    216       break;
    217     case ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION:
    218       content::RecordAction(
    219           content::UserMetricsAction("StatusArea_Drive_CancelOperation"));
    220       break;
    221     case ash::UMA_STATUS_AREA_DRIVE_SETTINGS:
    222       content::RecordAction(
    223           content::UserMetricsAction("StatusArea_Drive_Settings"));
    224       break;
    225     case ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK:
    226       content::RecordAction(
    227           content::UserMetricsAction("StatusArea_AutoClickEnabled"));
    228       break;
    229     case ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST:
    230       content::RecordAction(
    231           content::UserMetricsAction("StatusArea_HighContrastEnabled"));
    232       break;
    233     case ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR:
    234       content::RecordAction(
    235           content::UserMetricsAction("StatusArea_LargeCursorEnabled"));
    236       break;
    237     case ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER:
    238       content::RecordAction(
    239           content::UserMetricsAction("StatusArea_MagnifierEnabled"));
    240       break;
    241     case ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK:
    242       content::RecordAction(
    243           content::UserMetricsAction("StatusArea_SpokenFeedbackEnabled"));
    244       break;
    245     case ash::UMA_STATUS_AREA_ENABLE_WIFI:
    246       content::RecordAction(
    247           content::UserMetricsAction("StatusArea_Network_WifiEnabled"));
    248       break;
    249     case ash::UMA_STATUS_AREA_IME_SHOW_DETAILED:
    250       content::RecordAction(
    251           content::UserMetricsAction("StatusArea_IME_Detailed"));
    252       break;
    253     case ash::UMA_STATUS_AREA_IME_SWITCH_MODE:
    254       content::RecordAction(
    255           content::UserMetricsAction("StatusArea_IME_SwitchMode"));
    256       break;
    257     case ash::UMA_STATUS_AREA_MENU_OPENED:
    258       content::RecordAction(
    259           content::UserMetricsAction("StatusArea_MenuOpened"));
    260       break;
    261     case ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED:
    262       content::RecordAction(
    263           content::UserMetricsAction("StatusArea_Network_JoinOther"));
    264       break;
    265     case ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED:
    266       content::RecordAction(
    267           content::UserMetricsAction("StatusArea_Network_Settings"));
    268       break;
    269     case ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS:
    270       content::RecordAction(
    271           content::UserMetricsAction("StatusArea_Network_ConnectionDetails"));
    272       break;
    273     case ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS:
    274       content::RecordAction(
    275           content::UserMetricsAction("StatusArea_VPN_ConnectionDetails"));
    276       break;
    277     case ash::UMA_STATUS_AREA_SIGN_OUT:
    278       content::RecordAction(
    279           content::UserMetricsAction("StatusArea_SignOut"));
    280       break;
    281     case ash::UMA_STATUS_AREA_VPN_JOIN_OTHER_CLICKED:
    282       content::RecordAction(
    283           content::UserMetricsAction("StatusArea_VPN_JoinOther"));
    284       break;
    285     case ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED:
    286       content::RecordAction(
    287           content::UserMetricsAction("StatusArea_VPN_Settings"));
    288       break;
    289     case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK:
    290       content::RecordAction(
    291           content::UserMetricsAction("Caption_ClickTogglesMaximize"));
    292       break;
    293     case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE:
    294       content::RecordAction(
    295           content::UserMetricsAction("Caption_GestureTogglesMaximize"));
    296       break;
    297     case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW:
    298       content::RecordAction(
    299           content::UserMetricsAction("Touchpad_Gesture_Overview"));
    300       break;
    301     case ash::UMA_TOUCHSCREEN_TAP_DOWN:
    302       content::RecordAction(content::UserMetricsAction("Touchscreen_Down"));
    303       break;
    304     case ash::UMA_TRAY_HELP:
    305       content::RecordAction(content::UserMetricsAction("Tray_Help"));
    306       break;
    307     case ash::UMA_TRAY_LOCK_SCREEN:
    308       content::RecordAction(content::UserMetricsAction("Tray_LockScreen"));
    309       break;
    310     case ash::UMA_TRAY_SHUT_DOWN:
    311       content::RecordAction(content::UserMetricsAction("Tray_ShutDown"));
    312       break;
    313     case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK:
    314       content::RecordAction(content::UserMetricsAction("AppCloseButton_Clk"));
    315       break;
    316     case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK:
    317       content::RecordAction(content::UserMetricsAction("CloseButton_Clk"));
    318       break;
    319     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN:
    320       content::RecordAction(content::UserMetricsAction("MaxButton_Clk_ExitFS"));
    321       break;
    322     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE:
    323       content::RecordAction(
    324           content::UserMetricsAction("MaxButton_Clk_Restore"));
    325       break;
    326     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE:
    327       content::RecordAction(
    328           content::UserMetricsAction("MaxButton_Clk_Maximize"));
    329       break;
    330     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE:
    331       content::RecordAction(content::UserMetricsAction("MinButton_Clk"));
    332       break;
    333     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE:
    334       content::RecordAction(content::UserMetricsAction("MaxButton_Maximize"));
    335       break;
    336     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT:
    337       content::RecordAction(content::UserMetricsAction("MaxButton_MaxLeft"));
    338       break;
    339     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT:
    340       content::RecordAction(content::UserMetricsAction("MaxButton_MaxRight"));
    341       break;
    342     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE:
    343       content::RecordAction(content::UserMetricsAction("MaxButton_Minimize"));
    344       break;
    345     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE:
    346       content::RecordAction(content::UserMetricsAction("MaxButton_Restore"));
    347       break;
    348     case ash::UMA_WINDOW_MAXIMIZE_BUTTON_SHOW_BUBBLE:
    349       content::RecordAction(content::UserMetricsAction("MaxButton_ShowBubble"));
    350       break;
    351     case ash::UMA_WINDOW_OVERVIEW:
    352       content::RecordAction(
    353           content::UserMetricsAction("WindowSelector_Overview"));
    354       break;
    355     case ash::UMA_WINDOW_SELECTION:
    356       content::RecordAction(
    357           content::UserMetricsAction("WindowSelector_Selection"));
    358       break;
    359   }
    360 }
    361 
    362 void UserMetricsRecorder::RecordPeriodicMetrics() {
    363   internal::ShelfLayoutManager* manager =
    364       internal::ShelfLayoutManager::ForLauncher(Shell::GetPrimaryRootWindow());
    365   if (manager) {
    366     UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentOverTime",
    367         manager->SelectValueForShelfAlignment(
    368             internal::SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
    369             internal::SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
    370             internal::SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT,
    371             -1),
    372         internal::SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT);
    373   }
    374 
    375   enum ActiveWindowShowType {
    376     ACTIVE_WINDOW_SHOW_TYPE_NO_ACTIVE_WINDOW,
    377     ACTIVE_WINDOW_SHOW_TYPE_OTHER,
    378     ACTIVE_WINDOW_SHOW_TYPE_MAXIMIZED,
    379     ACTIVE_WINDOW_SHOW_TYPE_FULLSCREEN,
    380     ACTIVE_WINDOW_SHOW_TYPE_SNAPPED,
    381     ACTIVE_WINDOW_SHOW_TYPE_COUNT
    382   };
    383 
    384   ActiveWindowShowType active_window_show_type =
    385       ACTIVE_WINDOW_SHOW_TYPE_NO_ACTIVE_WINDOW;
    386   wm::WindowState* active_window_state = ash::wm::GetActiveWindowState();
    387   if (active_window_state) {
    388     switch(active_window_state->window_show_type()) {
    389       case wm::SHOW_TYPE_MAXIMIZED:
    390         active_window_show_type = ACTIVE_WINDOW_SHOW_TYPE_MAXIMIZED;
    391         break;
    392       case wm::SHOW_TYPE_FULLSCREEN:
    393         active_window_show_type = ACTIVE_WINDOW_SHOW_TYPE_FULLSCREEN;
    394         break;
    395       case wm::SHOW_TYPE_LEFT_SNAPPED:
    396       case wm::SHOW_TYPE_RIGHT_SNAPPED:
    397         active_window_show_type = ACTIVE_WINDOW_SHOW_TYPE_SNAPPED;
    398         break;
    399       case wm::SHOW_TYPE_DEFAULT:
    400       case wm::SHOW_TYPE_NORMAL:
    401       case wm::SHOW_TYPE_MINIMIZED:
    402       case wm::SHOW_TYPE_INACTIVE:
    403       case wm::SHOW_TYPE_DETACHED:
    404       case wm::SHOW_TYPE_END:
    405       case wm::SHOW_TYPE_AUTO_POSITIONED:
    406         active_window_show_type = ACTIVE_WINDOW_SHOW_TYPE_OTHER;
    407         break;
    408     }
    409   }
    410   UMA_HISTOGRAM_ENUMERATION("Ash.ActiveWindowShowTypeOverTime",
    411                             active_window_show_type,
    412                             ACTIVE_WINDOW_SHOW_TYPE_COUNT);
    413 }
    414 
    415 }  // namespace ash
    416