Don't preload rarely seen large images
[chromium-blink-merge.git] / ash / display / resolution_notification_controller.h
blob23a1f698a65d40c33bab89a0d72d8e0e570f7557
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
3 // found in the LICENSE file.
5 #ifndef ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
6 #define ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "ash/display/display_controller.h"
10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/timer/timer.h"
13 #include "ui/gfx/display_observer.h"
14 #include "ui/gfx/geometry/size.h"
16 namespace chromeos {
17 FORWARD_DECLARE_TEST(DisplayPreferencesTest, PreventStore);
18 } // namespace chromeos
20 namespace views {
21 class Label;
22 class Widget;
23 } // namespace views
25 namespace ash {
27 struct DisplayMode;
29 // A class which manages the notification of display resolution change and
30 // also manages the timeout in case the new resolution is unusable.
31 class ASH_EXPORT ResolutionNotificationController
32 : public gfx::DisplayObserver,
33 public DisplayController::Observer {
34 public:
35 ResolutionNotificationController();
36 ~ResolutionNotificationController() override;
38 // Prepare a resolution change notification for |display_id| from
39 // |old_resolution| to |new_resolution|, which offers a button to revert the
40 // change in case something goes wrong. The notification times out if there's
41 // only one display connected and the user is trying to modify its resolution.
42 // In that case, the timeout has to be set since the user cannot make any
43 // changes if something goes wrong.
45 // This method does not create a notification itself. The notification will be
46 // created the next OnDisplayConfigurationChanged(), which will be called
47 // asynchronously after the resolution change is requested. So typically this
48 // method will be combined with resolution change methods like
49 // DisplayManager::SetDisplayMode().
50 void PrepareNotification(int64 display_id,
51 const DisplayMode& old_resolution,
52 const DisplayMode& new_resolution,
53 const base::Closure& accept_callback);
55 // Returns true if the notification is visible or scheduled to be visible and
56 // the notification times out.
57 bool DoesNotificationTimeout();
59 // Called by the notification delegate when the user accepts the display
60 // resolution change. Set |close_notification| to true when the notification
61 // should be removed.
62 void AcceptResolutionChange(bool close_notification);
64 // Called by the notification delegate when the user wants to revert the
65 // display resolution change.
66 void RevertResolutionChange();
68 private:
69 friend class ResolutionNotificationControllerTest;
70 FRIEND_TEST_ALL_PREFIXES(ResolutionNotificationControllerTest, Timeout);
71 FRIEND_TEST_ALL_PREFIXES(chromeos::DisplayPreferencesTest, PreventStore);
73 // A struct to bundle the data for a single resolution change.
74 struct ResolutionChangeInfo;
76 static const int kTimeoutInSec;
77 static const char kNotificationId[];
79 // Create a new notification, or update its content if it already exists.
80 // |enable_spoken_feedback| is set to false when the notification is updated
81 // during the countdown so the update isn't necessarily read by the spoken
82 // feedback.
83 void CreateOrUpdateNotification(bool enable_spoken_feedback);
85 // Called every second for timeout.
86 void OnTimerTick();
88 // gfx::DisplayObserver overrides:
89 void OnDisplayAdded(const gfx::Display& new_display) override;
90 void OnDisplayRemoved(const gfx::Display& old_display) override;
91 void OnDisplayMetricsChanged(const gfx::Display& display,
92 uint32_t metrics) override;
94 // DisplayController::Observer overrides:
95 void OnDisplayConfigurationChanged() override;
97 static void SuppressTimerForTest();
99 scoped_ptr<ResolutionChangeInfo> change_info_;
101 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationController);
104 } // namespace ash
106 #endif // ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_