OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wm/maximize_mode/maximize_mode_controller.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/accelerators/accelerator_controller.h" | 9 #include "ash/accelerators/accelerator_controller.h" |
10 #include "ash/accelerators/accelerator_table.h" | 10 #include "ash/accelerators/accelerator_table.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // The angle between chromeos::AccelerometerReadings are considered stable if | 85 // The angle between chromeos::AccelerometerReadings are considered stable if |
86 // their magnitudes do not differ greatly. This returns false if the deviation | 86 // their magnitudes do not differ greatly. This returns false if the deviation |
87 // between the screen and keyboard accelerometers is too high. | 87 // between the screen and keyboard accelerometers is too high. |
88 bool IsAngleBetweenAccelerometerReadingsStable( | 88 bool IsAngleBetweenAccelerometerReadingsStable( |
89 const chromeos::AccelerometerUpdate& update) { | 89 const chromeos::AccelerometerUpdate& update) { |
90 return std::abs( | 90 return std::abs( |
91 ui::ConvertAccelerometerReadingToVector3dF( | 91 ui::ConvertAccelerometerReadingToVector3dF( |
92 update.get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) | 92 update.get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) |
93 .Length() - | 93 .Length() - |
94 ui::ConvertAccelerometerReadingToVector3dF( | 94 ui::ConvertAccelerometerReadingToVector3dF( |
95 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)).Length()) <= | 95 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)) |
96 kNoisyMagnitudeDeviation; | 96 .Length()) <= kNoisyMagnitudeDeviation; |
97 } | 97 } |
98 #endif // OS_CHROMEOS | 98 #endif // OS_CHROMEOS |
99 | 99 |
100 } // namespace | 100 } // namespace |
101 | 101 |
102 MaximizeModeController::MaximizeModeController() | 102 MaximizeModeController::MaximizeModeController() |
103 : have_seen_accelerometer_data_(false), | 103 : have_seen_accelerometer_data_(false), |
104 touchview_usage_interval_start_time_(base::Time::Now()), | 104 touchview_usage_interval_start_time_(base::Time::Now()), |
105 tick_clock_(new base::DefaultTickClock()), | 105 tick_clock_(new base::DefaultTickClock()), |
106 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
107 tablet_mode_switch_is_on_(false), | 107 tablet_mode_switch_is_on_(false), |
108 #endif | 108 #endif |
109 lid_is_closed_(false) { | 109 lid_is_closed_(false) { |
110 WmShell::Get()->AddShellObserver(this); | 110 WmShell::Get()->AddShellObserver(this); |
111 WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); | 111 WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); |
112 | 112 |
113 #if defined(OS_CHROMEOS) | 113 #if defined(OS_CHROMEOS) |
114 // TODO(jonross): Do not create MaximizeModeController if the flag is | 114 // TODO(jonross): Do not create MaximizeModeController if the flag is |
115 // unavailable. This will require refactoring | 115 // unavailable. This will require refactoring |
116 // IsMaximizeModeWindowManagerEnabled to check for the existance of the | 116 // IsMaximizeModeWindowManagerEnabled to check for the existance of the |
117 // controller. | 117 // controller. |
118 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 118 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
119 switches::kAshEnableTouchView)) { | 119 switches::kAshEnableTouchView)) { |
120 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 120 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
121 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 121 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
122 } | 122 } |
123 chromeos::DBusThreadManager::Get()-> | 123 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
124 GetPowerManagerClient()->AddObserver(this); | 124 this); |
125 #endif // OS_CHROMEOS | 125 #endif // OS_CHROMEOS |
126 } | 126 } |
127 | 127 |
128 MaximizeModeController::~MaximizeModeController() { | 128 MaximizeModeController::~MaximizeModeController() { |
129 WmShell::Get()->RemoveShellObserver(this); | 129 WmShell::Get()->RemoveShellObserver(this); |
130 #if defined(OS_CHROMEOS) | 130 #if defined(OS_CHROMEOS) |
131 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 131 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
132 switches::kAshEnableTouchView)) { | 132 switches::kAshEnableTouchView)) { |
133 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 133 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
134 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 134 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
135 } | 135 } |
136 chromeos::DBusThreadManager::Get()-> | 136 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
137 GetPowerManagerClient()->RemoveObserver(this); | 137 this); |
138 #endif // OS_CHROMEOS | 138 #endif // OS_CHROMEOS |
139 } | 139 } |
140 | 140 |
141 bool MaximizeModeController::CanEnterMaximizeMode() { | 141 bool MaximizeModeController::CanEnterMaximizeMode() { |
142 // If we have ever seen accelerometer data, then HandleHingeRotation may | 142 // If we have ever seen accelerometer data, then HandleHingeRotation may |
143 // trigger maximize mode at some point in the future. | 143 // trigger maximize mode at some point in the future. |
144 // The --enable-touch-view-testing switch can also mean that we may enter | 144 // The --enable-touch-view-testing switch can also mean that we may enter |
145 // maximize mode. | 145 // maximize mode. |
146 // TODO(mgiuca): This can result in false positives, as it returns true for | 146 // TODO(mgiuca): This can result in false positives, as it returns true for |
147 // any device with an accelerometer. Have TouchView-enabled devices explicitly | 147 // any device with an accelerometer. Have TouchView-enabled devices explicitly |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 return TOUCH_VIEW_INTERVAL_INACTIVE; | 400 return TOUCH_VIEW_INTERVAL_INACTIVE; |
401 } | 401 } |
402 | 402 |
403 void MaximizeModeController::OnAppTerminating() { | 403 void MaximizeModeController::OnAppTerminating() { |
404 // The system is about to shut down, so record TouchView usage interval | 404 // The system is about to shut down, so record TouchView usage interval |
405 // metrics based on whether TouchView mode is currently active. | 405 // metrics based on whether TouchView mode is currently active. |
406 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); | 406 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); |
407 | 407 |
408 if (CanEnterMaximizeMode()) { | 408 if (CanEnterMaximizeMode()) { |
409 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal", | 409 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal", |
410 total_touchview_time_.InMinutes(), | 410 total_touchview_time_.InMinutes(), 1, |
411 1, base::TimeDelta::FromDays(7).InMinutes(), 50); | 411 base::TimeDelta::FromDays(7).InMinutes(), 50); |
412 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal", | 412 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal", |
413 total_non_touchview_time_.InMinutes(), | 413 total_non_touchview_time_.InMinutes(), 1, |
414 1, base::TimeDelta::FromDays(7).InMinutes(), 50); | 414 base::TimeDelta::FromDays(7).InMinutes(), 50); |
415 base::TimeDelta total_runtime = total_touchview_time_ + | 415 base::TimeDelta total_runtime = |
416 total_non_touchview_time_; | 416 total_touchview_time_ + total_non_touchview_time_; |
417 if (total_runtime.InSeconds() > 0) { | 417 if (total_runtime.InSeconds() > 0) { |
418 UMA_HISTOGRAM_PERCENTAGE("Ash.TouchView.TouchViewActivePercentage", | 418 UMA_HISTOGRAM_PERCENTAGE( |
| 419 "Ash.TouchView.TouchViewActivePercentage", |
419 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); | 420 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); |
420 } | 421 } |
421 } | 422 } |
422 } | 423 } |
423 | 424 |
424 bool MaximizeModeController::WasLidOpenedRecently() const { | 425 bool MaximizeModeController::WasLidOpenedRecently() const { |
425 if (last_lid_open_time_.is_null()) | 426 if (last_lid_open_time_.is_null()) |
426 return false; | 427 return false; |
427 | 428 |
428 base::TimeTicks now = tick_clock_->NowTicks(); | 429 base::TimeTicks now = tick_clock_->NowTicks(); |
429 DCHECK(now >= last_lid_open_time_); | 430 DCHECK(now >= last_lid_open_time_); |
430 base::TimeDelta elapsed_time = now - last_lid_open_time_; | 431 base::TimeDelta elapsed_time = now - last_lid_open_time_; |
431 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; | 432 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; |
432 } | 433 } |
433 | 434 |
434 void MaximizeModeController::SetTickClockForTest( | 435 void MaximizeModeController::SetTickClockForTest( |
435 std::unique_ptr<base::TickClock> tick_clock) { | 436 std::unique_ptr<base::TickClock> tick_clock) { |
436 DCHECK(tick_clock_); | 437 DCHECK(tick_clock_); |
437 tick_clock_ = std::move(tick_clock); | 438 tick_clock_ = std::move(tick_clock); |
438 } | 439 } |
439 | 440 |
440 } // namespace ash | 441 } // namespace ash |
OLD | NEW |