OLD | NEW |
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 | 9 |
10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 protected: | 36 protected: |
37 virtual ~VideoDetectorObserver() {} | 37 virtual ~VideoDetectorObserver() {} |
38 }; | 38 }; |
39 | 39 |
40 // Watches for updates to windows and tries to detect when a video is playing. | 40 // Watches for updates to windows and tries to detect when a video is playing. |
41 // We err on the side of false positives and can be fooled by things like | 41 // We err on the side of false positives and can be fooled by things like |
42 // continuous scrolling of a page. | 42 // continuous scrolling of a page. |
43 class ASH_EXPORT VideoDetector : public aura::EnvObserver, | 43 class ASH_EXPORT VideoDetector : public aura::EnvObserver, |
44 public aura::WindowObserver, | 44 public aura::WindowObserver, |
45 public ShellObserver { | 45 public ShellObserver { |
46 public: | 46 public: |
47 // Minimum dimensions in pixels that a window update must have to be | 47 // Minimum dimensions in pixels that a window update must have to be |
48 // considered a potential video frame. | 48 // considered a potential video frame. |
49 static const int kMinUpdateWidth; | 49 static const int kMinUpdateWidth; |
50 static const int kMinUpdateHeight; | 50 static const int kMinUpdateHeight; |
51 | 51 |
52 // Number of video-sized updates that we must see within a second in a window | 52 // Number of video-sized updates that we must see within a second in a window |
53 // before we assume that a video is playing. | 53 // before we assume that a video is playing. |
54 static const int kMinFramesPerSecond; | 54 static const int kMinFramesPerSecond; |
55 | 55 |
(...skipping 15 matching lines...) Expand all Loading... |
71 // WindowObserver overrides. | 71 // WindowObserver overrides. |
72 void OnDelegatedFrameDamage(aura::Window* window, | 72 void OnDelegatedFrameDamage(aura::Window* window, |
73 const gfx::Rect& region) override; | 73 const gfx::Rect& region) override; |
74 void OnWindowDestroyed(aura::Window* window) override; | 74 void OnWindowDestroyed(aura::Window* window) override; |
75 | 75 |
76 // ShellObserver overrides. | 76 // ShellObserver overrides. |
77 void OnAppTerminating() override; | 77 void OnAppTerminating() override; |
78 | 78 |
79 private: | 79 private: |
80 class WindowInfo; | 80 class WindowInfo; |
81 typedef std::map<aura::Window*, linked_ptr<WindowInfo> > WindowInfoMap; | 81 typedef std::map<aura::Window*, linked_ptr<WindowInfo>> WindowInfoMap; |
82 | 82 |
83 // Possibly notifies observers in response to detection of a video in | 83 // Possibly notifies observers in response to detection of a video in |
84 // |window|. Notifications are rate-limited and don't get sent if the window | 84 // |window|. Notifications are rate-limited and don't get sent if the window |
85 // is invisible or offscreen. | 85 // is invisible or offscreen. |
86 void MaybeNotifyObservers(aura::Window* window, base::TimeTicks now); | 86 void MaybeNotifyObservers(aura::Window* window, base::TimeTicks now); |
87 | 87 |
88 // Maps from a window that we're tracking to information about it. | 88 // Maps from a window that we're tracking to information about it. |
89 WindowInfoMap window_infos_; | 89 WindowInfoMap window_infos_; |
90 | 90 |
91 base::ObserverList<VideoDetectorObserver> observers_; | 91 base::ObserverList<VideoDetectorObserver> observers_; |
92 | 92 |
93 // Last time at which we notified observers that a video was playing. | 93 // Last time at which we notified observers that a video was playing. |
94 base::TimeTicks last_observer_notification_time_; | 94 base::TimeTicks last_observer_notification_time_; |
95 | 95 |
96 // If set, used when the current time is needed. This can be set by tests to | 96 // If set, used when the current time is needed. This can be set by tests to |
97 // simulate the passage of time. | 97 // simulate the passage of time. |
98 base::TimeTicks now_for_test_; | 98 base::TimeTicks now_for_test_; |
99 | 99 |
100 ScopedObserver<aura::Window, aura::WindowObserver> observer_manager_; | 100 ScopedObserver<aura::Window, aura::WindowObserver> observer_manager_; |
101 | 101 |
102 bool is_shutting_down_; | 102 bool is_shutting_down_; |
103 | 103 |
104 DISALLOW_COPY_AND_ASSIGN(VideoDetector); | 104 DISALLOW_COPY_AND_ASSIGN(VideoDetector); |
105 }; | 105 }; |
106 | 106 |
107 } // namespace ash | 107 } // namespace ash |
108 | 108 |
109 #endif // ASH_WM_VIDEO_DETECTOR_H_ | 109 #endif // ASH_WM_VIDEO_DETECTOR_H_ |
OLD | NEW |