| 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 #include "ash/wm/video_detector.h" | 5 #include "ash/wm/video_detector.h" |
| 6 | 6 |
| 7 #include "ash/common/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // If the buffer is full, drop the first timestamp. | 38 // If the buffer is full, drop the first timestamp. |
| 39 if (buffer_size_ == static_cast<size_t>(kMinFramesPerSecond)) { | 39 if (buffer_size_ == static_cast<size_t>(kMinFramesPerSecond)) { |
| 40 buffer_start_ = (buffer_start_ + 1) % kMinFramesPerSecond; | 40 buffer_start_ = (buffer_start_ + 1) % kMinFramesPerSecond; |
| 41 buffer_size_--; | 41 buffer_size_--; |
| 42 } | 42 } |
| 43 | 43 |
| 44 update_times_[(buffer_start_ + buffer_size_) % kMinFramesPerSecond] = now; | 44 update_times_[(buffer_start_ + buffer_size_) % kMinFramesPerSecond] = now; |
| 45 buffer_size_++; | 45 buffer_size_++; |
| 46 | 46 |
| 47 return buffer_size_ == static_cast<size_t>(kMinFramesPerSecond) && | 47 return buffer_size_ == static_cast<size_t>(kMinFramesPerSecond) && |
| 48 (now - update_times_[buffer_start_]).InSecondsF() <= 1.0; | 48 (now - update_times_[buffer_start_]).InSecondsF() <= 1.0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 // Circular buffer containing update times of the last (up to | 52 // Circular buffer containing update times of the last (up to |
| 53 // |kMinFramesPerSecond|) video-sized updates to this window. | 53 // |kMinFramesPerSecond|) video-sized updates to this window. |
| 54 base::TimeTicks update_times_[kMinFramesPerSecond]; | 54 base::TimeTicks update_times_[kMinFramesPerSecond]; |
| 55 | 55 |
| 56 // Index into |update_times_| of the oldest update. | 56 // Index into |update_times_| of the oldest update. |
| 57 size_t buffer_start_; | 57 size_t buffer_start_; |
| 58 | 58 |
| 59 // Number of updates stored in |update_times_|. | 59 // Number of updates stored in |update_times_|. |
| 60 size_t buffer_size_; | 60 size_t buffer_size_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(WindowInfo); | 62 DISALLOW_COPY_AND_ASSIGN(WindowInfo); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 VideoDetector::VideoDetector() | 65 VideoDetector::VideoDetector() |
| 66 : observer_manager_(this), | 66 : observer_manager_(this), is_shutting_down_(false) { |
| 67 is_shutting_down_(false) { | |
| 68 aura::Env::GetInstance()->AddObserver(this); | 67 aura::Env::GetInstance()->AddObserver(this); |
| 69 WmShell::Get()->AddShellObserver(this); | 68 WmShell::Get()->AddShellObserver(this); |
| 70 } | 69 } |
| 71 | 70 |
| 72 VideoDetector::~VideoDetector() { | 71 VideoDetector::~VideoDetector() { |
| 73 WmShell::Get()->RemoveShellObserver(this); | 72 WmShell::Get()->RemoveShellObserver(this); |
| 74 aura::Env::GetInstance()->RemoveObserver(this); | 73 aura::Env::GetInstance()->RemoveObserver(this); |
| 75 } | 74 } |
| 76 | 75 |
| 77 void VideoDetector::AddObserver(VideoDetectorObserver* observer) { | 76 void VideoDetector::AddObserver(VideoDetectorObserver* observer) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 void VideoDetector::OnAppTerminating() { | 108 void VideoDetector::OnAppTerminating() { |
| 110 // Stop checking video activity once the shutdown | 109 // Stop checking video activity once the shutdown |
| 111 // process starts. crbug.com/231696. | 110 // process starts. crbug.com/231696. |
| 112 is_shutting_down_ = true; | 111 is_shutting_down_ = true; |
| 113 } | 112 } |
| 114 | 113 |
| 115 void VideoDetector::MaybeNotifyObservers(aura::Window* window, | 114 void VideoDetector::MaybeNotifyObservers(aura::Window* window, |
| 116 base::TimeTicks now) { | 115 base::TimeTicks now) { |
| 117 if (!last_observer_notification_time_.is_null() && | 116 if (!last_observer_notification_time_.is_null() && |
| 118 (now - last_observer_notification_time_).InSecondsF() < | 117 (now - last_observer_notification_time_).InSecondsF() < |
| 119 kNotifyIntervalSec) | 118 kNotifyIntervalSec) |
| 120 return; | 119 return; |
| 121 | 120 |
| 122 if (!window->IsVisible()) | 121 if (!window->IsVisible()) |
| 123 return; | 122 return; |
| 124 | 123 |
| 125 gfx::Rect root_bounds = window->GetRootWindow()->bounds(); | 124 gfx::Rect root_bounds = window->GetRootWindow()->bounds(); |
| 126 if (!window->GetBoundsInRootWindow().Intersects(root_bounds)) | 125 if (!window->GetBoundsInRootWindow().Intersects(root_bounds)) |
| 127 return; | 126 return; |
| 128 | 127 |
| 129 // As a relatively-cheap way to avoid flipping back and forth between | 128 // As a relatively-cheap way to avoid flipping back and forth between |
| 130 // fullscreen and non-fullscreen notifications when one video is playing in a | 129 // fullscreen and non-fullscreen notifications when one video is playing in a |
| 131 // fullscreen window and a second video is playing in a non-fullscreen window, | 130 // fullscreen window and a second video is playing in a non-fullscreen window, |
| 132 // report fullscreen video whenever a fullscreen window exists on any desktop | 131 // report fullscreen video whenever a fullscreen window exists on any desktop |
| 133 // regardless of whether the video is actually playing in that window: | 132 // regardless of whether the video is actually playing in that window: |
| 134 // http://crbug.com/340666 | 133 // http://crbug.com/340666 |
| 135 bool fullscreen_window_exists = false; | 134 bool fullscreen_window_exists = false; |
| 136 std::vector<aura::Window*> containers = | 135 std::vector<aura::Window*> containers = |
| 137 Shell::GetContainersFromAllRootWindows(kShellWindowId_DefaultContainer, | 136 Shell::GetContainersFromAllRootWindows(kShellWindowId_DefaultContainer, |
| 138 NULL); | 137 NULL); |
| 139 for (std::vector<aura::Window*>::const_iterator container = | 138 for (std::vector<aura::Window*>::const_iterator container = |
| 140 containers.begin(); container != containers.end(); ++container) { | 139 containers.begin(); |
| 140 container != containers.end(); ++container) { |
| 141 const aura::Window::Windows& windows = (*container)->children(); | 141 const aura::Window::Windows& windows = (*container)->children(); |
| 142 for (aura::Window::Windows::const_iterator window = windows.begin(); | 142 for (aura::Window::Windows::const_iterator window = windows.begin(); |
| 143 window != windows.end(); ++window) { | 143 window != windows.end(); ++window) { |
| 144 if (wm::GetWindowState(*window)->IsFullscreen()) { | 144 if (wm::GetWindowState(*window)->IsFullscreen()) { |
| 145 fullscreen_window_exists = true; | 145 fullscreen_window_exists = true; |
| 146 break; | 146 break; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 FOR_EACH_OBSERVER(VideoDetectorObserver, | 151 FOR_EACH_OBSERVER(VideoDetectorObserver, observers_, |
| 152 observers_, | |
| 153 OnVideoDetected(fullscreen_window_exists)); | 152 OnVideoDetected(fullscreen_window_exists)); |
| 154 last_observer_notification_time_ = now; | 153 last_observer_notification_time_ = now; |
| 155 } | 154 } |
| 156 | 155 |
| 157 } // namespace ash | 156 } // namespace ash |
| OLD | NEW |