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/session/session_state_delegate.h" | 7 #include "ash/common/session/session_state_delegate.h" |
8 #include "ash/common/shelf/shelf_delegate.h" | 8 #include "ash/common/shelf/shelf_delegate.h" |
9 #include "ash/common/shelf/shelf_item_types.h" | 9 #include "ash/common/shelf/shelf_item_types.h" |
10 #include "ash/common/shelf/shelf_model.h" | 10 #include "ash/common/shelf/shelf_model.h" |
11 #include "ash/common/shelf/shelf_view.h" | 11 #include "ash/common/shelf/shelf_view.h" |
12 #include "ash/common/shelf/wm_shelf.h" | 12 #include "ash/common/shelf/wm_shelf.h" |
13 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
14 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
15 #include "ash/common/wm/window_state.h" | 15 #include "ash/common/wm/window_state.h" |
16 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
17 #include "ash/common/wm_window.h" | 17 #include "ash/common/wm_window.h" |
18 #include "ash/metrics/desktop_task_switch_metric_recorder.h" | 18 #include "ash/metrics/desktop_task_switch_metric_recorder.h" |
19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
20 #include "ash/wm/window_state_aura.h" | 20 #include "ash/wm/window_state_aura.h" |
| 21 #include "base/memory/ptr_util.h" |
21 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
22 #include "base/metrics/user_metrics.h" | 23 #include "base/metrics/user_metrics.h" |
23 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
24 | 25 |
| 26 #if defined(OS_CHROMEOS) |
| 27 #include "ash/common/metrics/pointer_metrics_recorder.h" |
| 28 #endif |
| 29 |
25 namespace ash { | 30 namespace ash { |
26 | 31 |
27 namespace { | 32 namespace { |
28 | 33 |
29 // Time in seconds between calls to "RecordPeriodicMetrics". | 34 // Time in seconds between calls to "RecordPeriodicMetrics". |
30 const int kAshPeriodicMetricsTimeInSeconds = 30 * 60; | 35 const int kAshPeriodicMetricsTimeInSeconds = 30 * 60; |
31 | 36 |
32 enum ActiveWindowStateType { | 37 enum ActiveWindowStateType { |
33 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW, | 38 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW, |
34 ACTIVE_WINDOW_STATE_TYPE_OTHER, | 39 ACTIVE_WINDOW_STATE_TYPE_OTHER, |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 593 } |
589 } | 594 } |
590 | 595 |
591 void UserMetricsRecorder::OnShellInitialized() { | 596 void UserMetricsRecorder::OnShellInitialized() { |
592 // Lazy creation of the DesktopTaskSwitchMetricRecorder because it accesses | 597 // Lazy creation of the DesktopTaskSwitchMetricRecorder because it accesses |
593 // Shell::GetInstance() which is not available when |this| is instantiated. | 598 // Shell::GetInstance() which is not available when |this| is instantiated. |
594 if (!desktop_task_switch_metric_recorder_) { | 599 if (!desktop_task_switch_metric_recorder_) { |
595 desktop_task_switch_metric_recorder_.reset( | 600 desktop_task_switch_metric_recorder_.reset( |
596 new DesktopTaskSwitchMetricRecorder()); | 601 new DesktopTaskSwitchMetricRecorder()); |
597 } | 602 } |
| 603 #if defined(OS_CHROMEOS) |
| 604 pointer_metrics_recorder_ = base::MakeUnique<PointerMetricsRecorder>(); |
| 605 #endif |
598 } | 606 } |
599 | 607 |
600 void UserMetricsRecorder::OnShellShuttingDown() { | 608 void UserMetricsRecorder::OnShellShuttingDown() { |
601 desktop_task_switch_metric_recorder_.reset(); | 609 desktop_task_switch_metric_recorder_.reset(); |
| 610 |
| 611 #if defined(OS_CHROMEOS) |
| 612 // To clean up pointer_metrics_recorder_ properly, a valid shell instance is |
| 613 // required, so explicitly delete it before the shell instance becomes |
| 614 // invalid. |
| 615 pointer_metrics_recorder_.reset(); |
| 616 #endif |
602 } | 617 } |
603 | 618 |
604 void UserMetricsRecorder::RecordPeriodicMetrics() { | 619 void UserMetricsRecorder::RecordPeriodicMetrics() { |
605 WmShelf* shelf = WmShelf::ForWindow(WmShell::Get()->GetPrimaryRootWindow()); | 620 WmShelf* shelf = WmShelf::ForWindow(WmShell::Get()->GetPrimaryRootWindow()); |
606 // TODO(bruthig): Investigating whether the check for |manager| is necessary | 621 // TODO(bruthig): Investigating whether the check for |manager| is necessary |
607 // and add tests if it is. | 622 // and add tests if it is. |
608 if (shelf) { | 623 if (shelf) { |
609 // TODO(bruthig): Consider tracking the time spent in each alignment. | 624 // TODO(bruthig): Consider tracking the time spent in each alignment. |
610 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentOverTime", | 625 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentOverTime", |
611 shelf->SelectValueForShelfAlignment( | 626 shelf->SelectValueForShelfAlignment( |
(...skipping 22 matching lines...) Expand all Loading... |
634 return IsUserActive() && !IsKioskModeActive(); | 649 return IsUserActive() && !IsKioskModeActive(); |
635 } | 650 } |
636 | 651 |
637 void UserMetricsRecorder::StartTimer() { | 652 void UserMetricsRecorder::StartTimer() { |
638 timer_.Start(FROM_HERE, | 653 timer_.Start(FROM_HERE, |
639 base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds), | 654 base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds), |
640 this, &UserMetricsRecorder::RecordPeriodicMetrics); | 655 this, &UserMetricsRecorder::RecordPeriodicMetrics); |
641 } | 656 } |
642 | 657 |
643 } // namespace ash | 658 } // namespace ash |
OLD | NEW |