control_v_histogram_recorder.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2021 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. #include "ash/clipboard/control_v_histogram_recorder.h"
  5. #include "ash/accelerators/accelerator_controller_impl.h"
  6. #include "ash/accelerators/accelerator_history_impl.h"
  7. #include "ash/shell.h"
  8. #include "base/metrics/histogram_functions.h"
  9. #include "ui/events/event.h"
  10. namespace ash {
  11. void ControlVHistogramRecorder::OnKeyEvent(ui::KeyEvent* event) {
  12. if (event->type() != ui::ET_KEY_PRESSED)
  13. return;
  14. switch (event->key_code()) {
  15. case ui::VKEY_CONTROL:
  16. ctrl_pressed_time_ = base::TimeTicks::Now();
  17. break;
  18. case ui::VKEY_V: {
  19. auto& currently_pressed_keys = Shell::Get()
  20. ->accelerator_controller()
  21. ->GetAcceleratorHistory()
  22. ->currently_pressed_keys();
  23. if (currently_pressed_keys.find(ui::VKEY_CONTROL) !=
  24. currently_pressed_keys.end() &&
  25. currently_pressed_keys.find(ui::VKEY_V) !=
  26. currently_pressed_keys.end() &&
  27. currently_pressed_keys.size() == 2 && !ctrl_pressed_time_.is_null()) {
  28. base::UmaHistogramTimes("Ash.ClipboardHistory.ControlToVDelay",
  29. base::TimeTicks::Now() - ctrl_pressed_time_);
  30. // Prevent a second V from recording a second metric.
  31. ctrl_pressed_time_ = base::TimeTicks();
  32. }
  33. } break;
  34. default:
  35. break;
  36. }
  37. }
  38. } // namespace ash