Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(931)

Side by Side Diff: ash/wm/video_detector.h

Issue 2699033002: Replace WmWindowObserver with aura::WindowObserver. (Closed)
Patch Set: Check for null images in ShelfWindowWatcher. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/screen_pinning_controller.cc ('k') | ash/wm/video_detector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef ASH_WM_VIDEO_DETECTOR_H_ 5 #ifndef ASH_WM_VIDEO_DETECTOR_H_
6 #define ASH_WM_VIDEO_DETECTOR_H_ 6 #define ASH_WM_VIDEO_DETECTOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 11
12 #include "ash/ash_export.h" 12 #include "ash/ash_export.h"
13 #include "ash/common/shell_observer.h" 13 #include "ash/common/shell_observer.h"
14 #include "ash/common/wm_window_observer.h"
15 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
16 #include "base/macros.h" 15 #include "base/macros.h"
17 #include "base/observer_list.h" 16 #include "base/observer_list.h"
18 #include "base/scoped_observer.h" 17 #include "base/scoped_observer.h"
19 #include "base/time/time.h" 18 #include "base/time/time.h"
20 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
21 #include "ui/aura/env_observer.h" 20 #include "ui/aura/env_observer.h"
22 #include "ui/aura/window_observer.h" 21 #include "ui/aura/window_observer.h"
23 22
24 namespace aura { 23 namespace aura {
25 class Window; 24 class Window;
26 } 25 }
27 26
28 namespace gfx { 27 namespace gfx {
29 class Rect; 28 class Rect;
30 } 29 }
31 30
32 namespace ash { 31 namespace ash {
33 32
34 // Watches for updates to windows and tries to detect when a video is playing. 33 // Watches for updates to windows and tries to detect when a video is playing.
35 // We err on the side of false positives and can be fooled by things like 34 // We err on the side of false positives and can be fooled by things like
36 // continuous scrolling of a page. 35 // continuous scrolling of a page.
37 class ASH_EXPORT VideoDetector : public aura::EnvObserver, 36 class ASH_EXPORT VideoDetector : public aura::EnvObserver,
38 public aura::WindowObserver, 37 public aura::WindowObserver,
39 public ShellObserver, 38 public ShellObserver {
40 public WmWindowObserver {
41 public: 39 public:
42 // State of detected video activity. 40 // State of detected video activity.
43 enum class State { 41 enum class State {
44 // Video activity has been detected recently and there are no fullscreen 42 // Video activity has been detected recently and there are no fullscreen
45 // windows. 43 // windows.
46 PLAYING_WINDOWED, 44 PLAYING_WINDOWED,
47 // Video activity has been detected recently and there is at least one 45 // Video activity has been detected recently and there is at least one
48 // fullscreen window. 46 // fullscreen window.
49 PLAYING_FULLSCREEN, 47 PLAYING_FULLSCREEN,
50 // Video activity has not been detected recently. 48 // Video activity has not been detected recently.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 void AddObserver(Observer* observer); 84 void AddObserver(Observer* observer);
87 void RemoveObserver(Observer* observer); 85 void RemoveObserver(Observer* observer);
88 86
89 // Runs HandleVideoInactive() and returns true, or returns false if 87 // Runs HandleVideoInactive() and returns true, or returns false if
90 // |video_inactive_timer_| wasn't running. 88 // |video_inactive_timer_| wasn't running.
91 bool TriggerTimeoutForTest() WARN_UNUSED_RESULT; 89 bool TriggerTimeoutForTest() WARN_UNUSED_RESULT;
92 90
93 // EnvObserver overrides. 91 // EnvObserver overrides.
94 void OnWindowInitialized(aura::Window* window) override; 92 void OnWindowInitialized(aura::Window* window) override;
95 93
96 // WindowObserver overrides. 94 // aura::WindowObserver overrides.
97 void OnDelegatedFrameDamage(aura::Window* window, 95 void OnDelegatedFrameDamage(aura::Window* window,
98 const gfx::Rect& region) override; 96 const gfx::Rect& region) override;
99 void OnWindowDestroyed(aura::Window* window) override; 97 void OnWindowDestroyed(aura::Window* window) override;
100 void OnWindowDestroying(aura::Window* window) override {} 98 void OnWindowDestroying(aura::Window* window) override;
101 99
102 // ShellObserver overrides. 100 // ShellObserver overrides.
103 void OnAppTerminating() override; 101 void OnAppTerminating() override;
104 void OnFullscreenStateChanged(bool is_fullscreen, 102 void OnFullscreenStateChanged(bool is_fullscreen,
105 WmWindow* root_window) override; 103 WmWindow* root_window) override;
106 104
107 // WmWindowObserver overrides.
108 void OnWindowDestroyed(WmWindow* window) override {}
109 void OnWindowDestroying(WmWindow* window) override;
110
111 private: 105 private:
112 // Called when video activity is observed in |window|. 106 // Called when video activity is observed in |window|.
113 void HandleVideoActivity(aura::Window* window, base::TimeTicks now); 107 void HandleVideoActivity(aura::Window* window, base::TimeTicks now);
114 108
115 // Called by |inactive_timer_| |kVideoTimeoutMs| after the last-observed video 109 // Called by |inactive_timer_| |kVideoTimeoutMs| after the last-observed video
116 // activity. 110 // activity.
117 void HandleVideoInactive(); 111 void HandleVideoInactive();
118 112
119 // Updates |state_| and notifies |observers_| if it changed. 113 // Updates |state_| and notifies |observers_| if it changed.
120 void UpdateState(); 114 void UpdateState();
121 115
122 // Current playback state. 116 // Current playback state.
123 State state_; 117 State state_;
124 118
125 // True if video has been observed in the last |kVideoTimeoutMs|. 119 // True if video has been observed in the last |kVideoTimeoutMs|.
126 bool video_is_playing_; 120 bool video_is_playing_;
127 121
128 // Currently-fullscreen root windows. 122 // Currently-fullscreen root windows.
129 std::set<WmWindow*> fullscreen_root_windows_; 123 std::set<aura::Window*> fullscreen_root_windows_;
130 124
131 // Maps from a window that we're tracking to information about it. 125 // Maps from a window that we're tracking to information about it.
132 class WindowInfo; 126 class WindowInfo;
133 using WindowInfoMap = std::map<aura::Window*, std::unique_ptr<WindowInfo>>; 127 using WindowInfoMap = std::map<aura::Window*, std::unique_ptr<WindowInfo>>;
134 WindowInfoMap window_infos_; 128 WindowInfoMap window_infos_;
135 129
136 base::ObserverList<Observer> observers_; 130 base::ObserverList<Observer> observers_;
137 131
138 // Calls HandleVideoInactive(). 132 // Calls HandleVideoInactive().
139 base::OneShotTimer video_inactive_timer_; 133 base::OneShotTimer video_inactive_timer_;
140 134
141 // If set, used when the current time is needed. This can be set by tests to 135 // If set, used when the current time is needed. This can be set by tests to
142 // simulate the passage of time. 136 // simulate the passage of time.
143 base::TimeTicks now_for_test_; 137 base::TimeTicks now_for_test_;
144 138
145 ScopedObserver<aura::Window, aura::WindowObserver> window_observer_manager_; 139 ScopedObserver<aura::Window, aura::WindowObserver> window_observer_manager_;
146 ScopedObserver<WmWindow, WmWindowObserver> wm_window_observer_manager_;
147 140
148 bool is_shutting_down_; 141 bool is_shutting_down_;
149 142
150 DISALLOW_COPY_AND_ASSIGN(VideoDetector); 143 DISALLOW_COPY_AND_ASSIGN(VideoDetector);
151 }; 144 };
152 145
153 } // namespace ash 146 } // namespace ash
154 147
155 #endif // ASH_WM_VIDEO_DETECTOR_H_ 148 #endif // ASH_WM_VIDEO_DETECTOR_H_
OLDNEW
« no previous file with comments | « ash/wm/screen_pinning_controller.cc ('k') | ash/wm/video_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698