Index: ash/wm/maximize_mode/maximize_mode_controller.h |
diff --git a/ash/wm/maximize_mode/maximize_mode_controller.h b/ash/wm/maximize_mode/maximize_mode_controller.h |
index 54db3f3a48539de4f53fb4781960be6b52876918..2beed0733a6d5511a6abec19a01381a336376b0e 100644 |
--- a/ash/wm/maximize_mode/maximize_mode_controller.h |
+++ b/ash/wm/maximize_mode/maximize_mode_controller.h |
@@ -13,7 +13,7 @@ |
#include "base/macros.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/observer_list.h" |
-#include "base/power_monitor/power_observer.h" |
+#include "chromeos/dbus/power_manager_client.h" |
#include "ui/gfx/display.h" |
namespace ui { |
@@ -31,7 +31,7 @@ class MaximizeModeWindowManagerTest; |
// enters and exits maximize mode when the lid is opened beyond the triggering |
// angle and rotates the display to match the device when in maximize mode. |
class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, |
- public base::PowerObserver, |
+ public chromeos::PowerManagerClient::Observer, |
public ShellObserver, |
public DisplayController::Observer { |
public: |
@@ -98,17 +98,51 @@ class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, |
virtual void OnMaximizeModeStarted() OVERRIDE; |
virtual void OnMaximizeModeEnded() OVERRIDE; |
- // base::PowerObserver: |
- virtual void OnSuspend() OVERRIDE; |
- virtual void OnResume() OVERRIDE; |
- |
// DisplayController::Observer: |
virtual void OnDisplayConfigurationChanged() OVERRIDE; |
+ // PowerManagerClient::Observer: |
+ virtual void LidEventReceived(bool open, |
+ const base::TimeTicks& time) OVERRIDE; |
+ virtual void SuspendImminent() OVERRIDE; |
+ virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; |
+ |
private: |
friend class MaximizeModeControllerTest; |
friend class MaximizeModeWindowManagerTest; |
+ // An abstraction of the current time in TimeTicks. |
+ // This is used so that tests can artificially control the current time. |
+ // This prevents test flakiness caused by dependencies on a true clock time. |
+ class TimeTickProvider { |
jonross
2014/07/24 14:22:00
I dislike the idea of changing the time provider.
|
+ public: |
+ TimeTickProvider() {} |
+ virtual ~TimeTickProvider() {} |
+ virtual base::TimeTicks Now() const = 0; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TimeTickProvider); |
+ }; |
+ |
+ // The default TimeTickProvider used by the MaximizeModeController. |
+ class TimeTickProviderImpl : public TimeTickProvider { |
jonross
2014/07/24 14:22:00
This class is not needed for testing, nor for any
|
+ public: |
+ TimeTickProviderImpl() : TimeTickProvider() {} |
+ virtual ~TimeTickProviderImpl() {} |
+ |
+ // TimeTickProvider: |
+ virtual base::TimeTicks Now() const OVERRIDE; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TimeTickProviderImpl); |
+ }; |
+ |
+ // Set the TimeTickProvider. |
+ // This is only to be used by tests that need to artificially and |
+ // deterministically control the current time. |
+ // Ownership of |provider| is assumed by this. |
+ void SetTimeTickProviderForTest(TimeTickProvider* provider); |
+ |
// Detect hinge rotation from |base| and |lid| accelerometers and |
// automatically start / stop maximize mode. |
void HandleHingeRotation(const gfx::Vector3dF& base, |
@@ -122,6 +156,9 @@ class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, |
void SetDisplayRotation(DisplayManager* display_manager, |
gfx::Display::Rotation rotation); |
+ // Returns true if the lid was recently opened. |
+ bool WasLidOpenedRecently() const; |
+ |
// Enables MaximizeModeWindowManager, and determines the current state of |
// rotation lock. |
void EnterMaximizeMode(); |
@@ -169,6 +206,19 @@ class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, |
base::TimeDelta total_touchview_time_; |
base::TimeDelta total_non_touchview_time_; |
+ // Tracks the last time we received a lid open event. |
+ // This is used to suppress erroneous acceleromter readings as the lid |
+ // is opened but the acceleromater reports readings that make |
+ // the lid to appear near fully open. |
+ base::TimeTicks last_lid_open_time_; |
+ |
+ // Source for the current time in base::TimeTicks. |
+ scoped_ptr<TimeTickProvider> time_tick_provider_; |
+ |
+ // Tracks when the lid is closed. |
+ // Used to prevent entering maximize mode. |
+ bool lid_is_closed_; |
+ |
DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); |
}; |