1 // Copyright 2013 The ChromiumOS Authors 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 <gtest/gtest.h> // for FRIEND_TEST 6 #include <map> 7 8 #include "include/filter_interpreter.h" 9 #include "include/finger_metrics.h" 10 #include "include/gestures.h" 11 #include "include/prop_registry.h" 12 #include "include/tracer.h" 13 #include "include/util.h" 14 15 #ifndef GESTURES_METRICS_FILTER_INTERPRETER_H_ 16 #define GESTURES_METRICS_FILTER_INTERPRETER_H_ 17 18 namespace gestures { 19 20 // This interpreter catches scenarios which we want to collect UMA stats for 21 // and generate GestureMetrics gestures for them. Those gestures would picked 22 // up in Chrome to log the desired UMA stats. We chose not to call out to the 23 // metrics lib here because it might introduce the deadlock problem. 24 25 class MetricsFilterInterpreter : public FilterInterpreter { 26 FRIEND_TEST(MetricsFilterInterpreterTest, SimpleTestMultitouchMouse); 27 FRIEND_TEST(MetricsFilterInterpreterTest, SimpleTestPointingStick); 28 FRIEND_TEST(MetricsFilterInterpreterTest, SimpleTestTouchpad); 29 30 public: 31 // Takes ownership of |next|: 32 MetricsFilterInterpreter(PropRegistry* prop_reg, 33 Interpreter* next, 34 Tracer* tracer, 35 GestureInterpreterDeviceClass devclass); ~MetricsFilterInterpreter()36 virtual ~MetricsFilterInterpreter() {} 37 38 protected: 39 virtual void SyncInterpretImpl(HardwareState* hwstate, stime_t* timeout); 40 41 private: 42 template <class DataType, size_t kHistorySize> 43 struct State { StateState44 State() {} StateState45 State(const DataType& fs, const HardwareState& hwstate) 46 : timestamp(hwstate.timestamp), data(fs) {} 47 MaxHistorySizeState48 static size_t MaxHistorySize() { return kHistorySize; } 49 50 stime_t timestamp; 51 DataType data; 52 }; 53 54 // struct for one finger's data of one frame. 55 typedef State<FingerState, 3> MState; 56 typedef List<MState> FingerHistory; 57 58 // Push the new data into the buffer. 59 void AddNewStateToBuffer(FingerHistory& history, 60 const FingerState& data, 61 const HardwareState& hwstate); 62 63 // Update the class with new finger data, check if there is any interesting 64 // pattern 65 void UpdateFingerState(const HardwareState& hwstate); 66 67 // Detect the noisy ground pattern and send GestureMetrics 68 bool DetectNoisyGround(FingerHistory& history); 69 70 // Update the class with new mouse movement data. 71 void UpdateMouseMovementState(const HardwareState& hwstate); 72 73 // Compute interested statistics for the mouse history, send GestureMetrics. 74 void ReportMouseStatistics(); 75 76 // A map to store each finger's past data 77 typedef std::map<short, FingerHistory> FingerHistoryMap; 78 FingerHistoryMap histories_; 79 80 // Device class (e.g. touchpad, mouse). 81 GestureInterpreterDeviceClass devclass_; 82 83 // The total number of mouse movement sessions from the startup. 84 int mouse_movement_session_index_; 85 86 // The number of events in the current mouse movement session. 87 int mouse_movement_current_session_length; 88 89 // The start/last update time of the current mouse movement session. 90 stime_t mouse_movement_current_session_start; 91 stime_t mouse_movement_current_session_last; 92 93 // The total distance that mouse traveled in the current mouse movement 94 // session. 95 double mouse_movement_current_session_distance; 96 97 // Threshold values for detecting movements caused by the noisy ground 98 DoubleProperty noisy_ground_distance_threshold_; 99 DoubleProperty noisy_ground_time_threshold_; 100 101 // Threshold values for determining a moving mouse. We consider the mouse 102 // stationary if it doesn't report movements in the last threshold amount 103 // of time. 104 DoubleProperty mouse_moving_time_threshold_; 105 106 // Number of mouse movement sessions that we skip at startup. We do this 107 // because it takes time for the user to "get used to" the mouse speed when 108 // they first start using the mouse. We only want to capture the user metrics 109 // after the user has been familiar with their mouse. 110 IntProperty mouse_control_warmup_sessions_; 111 }; 112 113 } // namespace gestures 114 115 #endif // GESTURES_METRICS_FILTER_INTERPRETER_H_ 116