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

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

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
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 #include "ash/wm/video_detector.h" 5 #include "ash/wm/video_detector.h"
6 6
7 #include "ash/common/wm/window_state.h" 7 #include "ash/common/wm/window_state.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "ash/common/wm_window.h" 9 #include "ash/common/wm_window.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // Number of updates stored in |update_times_|. 75 // Number of updates stored in |update_times_|.
76 size_t buffer_size_; 76 size_t buffer_size_;
77 77
78 DISALLOW_COPY_AND_ASSIGN(WindowInfo); 78 DISALLOW_COPY_AND_ASSIGN(WindowInfo);
79 }; 79 };
80 80
81 VideoDetector::VideoDetector() 81 VideoDetector::VideoDetector()
82 : state_(State::NOT_PLAYING), 82 : state_(State::NOT_PLAYING),
83 video_is_playing_(false), 83 video_is_playing_(false),
84 window_observer_manager_(this), 84 window_observer_manager_(this),
85 wm_window_observer_manager_(this),
86 is_shutting_down_(false) { 85 is_shutting_down_(false) {
87 aura::Env::GetInstance()->AddObserver(this); 86 aura::Env::GetInstance()->AddObserver(this);
88 WmShell::Get()->AddShellObserver(this); 87 WmShell::Get()->AddShellObserver(this);
89 } 88 }
90 89
91 VideoDetector::~VideoDetector() { 90 VideoDetector::~VideoDetector() {
92 WmShell::Get()->RemoveShellObserver(this); 91 WmShell::Get()->RemoveShellObserver(this);
93 aura::Env::GetInstance()->RemoveObserver(this); 92 aura::Env::GetInstance()->RemoveObserver(this);
94 } 93 }
95 94
(...skipping 26 matching lines...) Expand all
122 std::unique_ptr<WindowInfo>& info = window_infos_[window]; 121 std::unique_ptr<WindowInfo>& info = window_infos_[window];
123 if (!info.get()) 122 if (!info.get())
124 info.reset(new WindowInfo); 123 info.reset(new WindowInfo);
125 124
126 base::TimeTicks now = 125 base::TimeTicks now =
127 !now_for_test_.is_null() ? now_for_test_ : base::TimeTicks::Now(); 126 !now_for_test_.is_null() ? now_for_test_ : base::TimeTicks::Now();
128 if (info->RecordUpdateAndCheckForVideo(damage_rect_in_dip, now)) 127 if (info->RecordUpdateAndCheckForVideo(damage_rect_in_dip, now))
129 HandleVideoActivity(window, now); 128 HandleVideoActivity(window, now);
130 } 129 }
131 130
131 void VideoDetector::OnWindowDestroying(aura::Window* window) {
132 if (fullscreen_root_windows_.count(window)) {
133 window_observer_manager_.Remove(window);
134 fullscreen_root_windows_.erase(window);
135 UpdateState();
136 }
137 }
138
132 void VideoDetector::OnWindowDestroyed(aura::Window* window) { 139 void VideoDetector::OnWindowDestroyed(aura::Window* window) {
133 window_infos_.erase(window); 140 window_infos_.erase(window);
134 window_observer_manager_.Remove(window); 141 window_observer_manager_.Remove(window);
135 } 142 }
136 143
137 void VideoDetector::OnAppTerminating() { 144 void VideoDetector::OnAppTerminating() {
138 // Stop checking video activity once the shutdown 145 // Stop checking video activity once the shutdown
139 // process starts. crbug.com/231696. 146 // process starts. crbug.com/231696.
140 is_shutting_down_ = true; 147 is_shutting_down_ = true;
141 } 148 }
142 149
143 void VideoDetector::OnFullscreenStateChanged(bool is_fullscreen, 150 void VideoDetector::OnFullscreenStateChanged(bool is_fullscreen,
144 WmWindow* root_window) { 151 WmWindow* root_window) {
145 if (is_fullscreen && !fullscreen_root_windows_.count(root_window)) { 152 aura::Window* aura_window = root_window->aura_window();
146 fullscreen_root_windows_.insert(root_window); 153 if (is_fullscreen && !fullscreen_root_windows_.count(aura_window)) {
147 wm_window_observer_manager_.Add(root_window); 154 fullscreen_root_windows_.insert(aura_window);
155 if (!window_observer_manager_.IsObserving(aura_window))
156 window_observer_manager_.Add(aura_window);
148 UpdateState(); 157 UpdateState();
149 } else if (!is_fullscreen && fullscreen_root_windows_.count(root_window)) { 158 } else if (!is_fullscreen && fullscreen_root_windows_.count(aura_window)) {
150 fullscreen_root_windows_.erase(root_window); 159 fullscreen_root_windows_.erase(aura_window);
151 wm_window_observer_manager_.Remove(root_window); 160 window_observer_manager_.Remove(aura_window);
152 UpdateState(); 161 UpdateState();
153 } 162 }
154 } 163 }
155
156 void VideoDetector::OnWindowDestroying(WmWindow* window) {
157 if (fullscreen_root_windows_.count(window)) {
158 wm_window_observer_manager_.Remove(window);
159 fullscreen_root_windows_.erase(window);
160 UpdateState();
161 }
162 }
163 164
164 void VideoDetector::HandleVideoActivity(aura::Window* window, 165 void VideoDetector::HandleVideoActivity(aura::Window* window,
165 base::TimeTicks now) { 166 base::TimeTicks now) {
166 if (!window->IsVisible()) 167 if (!window->IsVisible())
167 return; 168 return;
168 169
169 gfx::Rect root_bounds = window->GetRootWindow()->bounds(); 170 gfx::Rect root_bounds = window->GetRootWindow()->bounds();
170 if (!window->GetBoundsInRootWindow().Intersects(root_bounds)) 171 if (!window->GetBoundsInRootWindow().Intersects(root_bounds))
171 return; 172 return;
172 173
(...skipping 17 matching lines...) Expand all
190 } 191 }
191 192
192 if (state_ != new_state) { 193 if (state_ != new_state) {
193 state_ = new_state; 194 state_ = new_state;
194 for (auto& observer : observers_) 195 for (auto& observer : observers_)
195 observer.OnVideoStateChanged(state_); 196 observer.OnVideoStateChanged(state_);
196 } 197 }
197 } 198 }
198 199
199 } // namespace ash 200 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/video_detector.h ('k') | chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698