/
ambient_ui_model.h
147 lines (107 loc) · 5.17 KB
/
ambient_ui_model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_
#define ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/time/time.h"
namespace ash {
// Enumeration of UI visibility states.
enum class AmbientUiVisibility {
kShown, // Screen saver is shown.
kPreview, // Same as kShown, but do not lock screen or acquire wake lock.
// kPreview state is used to show a preview of the screen saver.
// Users should be able to exit from the preview mode directly.
// Hence, no need to lock the screen or acquire wake lock.
kHidden, // Screen saver is closed; start inactivity timer to restart it.
kClosed, // Screen saver is closed; all observers and timers are cancelled.
};
// Enumeration of ambient UI modes. This is used for metrics reporting and
// values should not be re-ordered or removed.
enum class AmbientUiMode {
kLockScreenUi = 0,
kInSessionUi = 1,
kMaxValue = kInSessionUi,
};
// The default time before starting Ambient mode on lock screen.
constexpr base::TimeDelta kLockScreenInactivityTimeout = base::Seconds(7);
// The default time to lock screen in the background after Ambient mode begins.
constexpr base::TimeDelta kLockScreenBackgroundTimeout = base::Seconds(5);
// The default interval to refresh photos.
constexpr base::TimeDelta kPhotoRefreshInterval = base::Seconds(60);
// The default animation playback speed. Not used in slideshow mode.
constexpr float kAnimationPlaybackSpeed = 1.f;
// The default time before starting the managed screensaver. Must match with the
// default value declared in the DeviceScreensaverLoginScreenIdleTimeoutSeconds
// and ScreensaverLockScreenIdleTimeoutSeconds policies.
constexpr base::TimeDelta kManagedScreensaverInactivityTimeout =
base::Seconds(7);
// The default interval to refresh images in the managed screensaver. Must match
// with the default value declared in the
// DeviceScreensaverImageDisplayIntervalSeconds and
// ScreensaverImageDisplayIntervalSeconds policies.
constexpr base::TimeDelta kManagedScreensaverImageRefreshInterval =
base::Seconds(60);
// A checked observer which receives notification of changes to the Ambient Mode
// UI model.
class ASH_PUBLIC_EXPORT AmbientUiModelObserver : public base::CheckedObserver {
public:
// Invoked when the Ambient Mode UI visibility changed.
virtual void OnAmbientUiVisibilityChanged(AmbientUiVisibility visibility) {}
virtual void OnLockScreenInactivityTimeoutChanged(base::TimeDelta timeout) {}
virtual void OnBackgroundLockScreenTimeoutChanged(base::TimeDelta timeout) {}
};
// Models the Ambient Mode UI.
class ASH_PUBLIC_EXPORT AmbientUiModel {
public:
static AmbientUiModel* Get();
AmbientUiModel();
AmbientUiModel(const AmbientUiModel&) = delete;
AmbientUiModel& operator=(AmbientUiModel&) = delete;
~AmbientUiModel();
void AddObserver(AmbientUiModelObserver* observer);
void RemoveObserver(AmbientUiModelObserver* observer);
// Updates current UI visibility and notifies all subscribers.
void SetUiVisibility(AmbientUiVisibility visibility);
AmbientUiVisibility ui_visibility() const { return ui_visibility_; }
void SetLockScreenInactivityTimeout(base::TimeDelta timeout);
base::TimeDelta lock_screen_inactivity_timeout() const {
return lock_screen_inactivity_timeout_;
}
void SetBackgroundLockScreenTimeout(base::TimeDelta timeout);
base::TimeDelta background_lock_screen_timeout() const {
return background_lock_screen_timeout_;
}
void SetPhotoRefreshInterval(base::TimeDelta interval);
base::TimeDelta photo_refresh_interval() const {
return photo_refresh_interval_;
}
void set_animation_playback_speed(float animation_playback_speed) {
animation_playback_speed_ = animation_playback_speed;
}
float animation_playback_speed() const { return animation_playback_speed_; }
private:
void NotifyAmbientUiVisibilityChanged();
void NotifyLockScreenInactivityTimeoutChanged();
void NotifyBackgroundLockScreenTimeoutChanged();
AmbientUiVisibility ui_visibility_ = AmbientUiVisibility::kClosed;
// The delay to show ambient mode after lock screen is activated.
base::TimeDelta lock_screen_inactivity_timeout_ =
kLockScreenInactivityTimeout;
// The delay between ambient mode starts and enabling lock screen.
base::TimeDelta background_lock_screen_timeout_ =
kLockScreenBackgroundTimeout;
// The interval to refresh photos.
base::TimeDelta photo_refresh_interval_ = kPhotoRefreshInterval;
// Animation playback speed. Not used in slideshow mode.
float animation_playback_speed_ = kAnimationPlaybackSpeed;
base::ObserverList<AmbientUiModelObserver> observers_;
};
ASH_PUBLIC_EXPORT std::ostream& operator<<(std::ostream& out,
AmbientUiMode mode);
ASH_PUBLIC_EXPORT std::ostream& operator<<(std::ostream& out,
AmbientUiVisibility visibility);
} // namespace ash
#endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_